1.0.1 • Published 2 years ago

sb-cs2ts v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

C# models to TypeScript

This is a tool that consumes your C# domain models and types and creates TypeScript declaration files from them. There's other tools that does this but what makes this one different is that it internally uses Roslyn (the .NET compiler platform) to parse the source files, which removes the need to create and maintain our own parser.

NPM version

Dependencies

Forked from

Install

$ npm install --save --dev sb-cs2ts

How to use

  1. Add a config file to your project that contains for example...
{
    "include": [
        "./models/**/*.cs",
        "./enums/**/*.cs"
    ],
    "exclude": [
        "./models/foo/bar.cs"
    ],
    "namespace": "Api",
    "output": "./api.d.ts",
    "camelCase": false,
    "camelCaseEnums": false,
    "camelCaseOptions": {
        "pascalCase": false,
        "preserveConsecutiveUppercase": false,
        "locale": "en-US"
    },
    "numericEnums": false,
    "stringLiteralTypesInsteadOfEnums": false,
    "customTypeTranslations": {
        "ProductName": "string",
        "ProductNumber": "string"
    }
}
  1. Add a npm script to your package.json that references your config file...
"scripts": {
    "generate-ts": "cs2ts --config=your-config-file.json"
},
  1. Run the npm script generate-ts and the output file specified in your config should be created and populated with your models.

License

MIT © Jonathan Svenheden