Negotiate Pushing Milestone

    @factor-sef/cs-to-ts
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.0 • Public • Published

    cs-to-ts

    License: MIT CI status Package ver.

    It is a simple package for converting a C# class to typescript, where the user can flexibly customize the library to get the desired result.

    this package was inspired by @YuvrajSagarRana/csharp-to-typescript solution.

    Installation

    npm i @factor-sef/cs-to-ts

    Usage

    1. After installation, you must import this package:
    import Parser from '@factor-sef/cs-to-ts';
    // or
    const Parser = require('@factor-sef/cs-to-ts');
    1. Next, you must create a new parser class:
    const parser = new Parser(config)

    You can view this config options here

    1. In the end, you can pass any C # class in string format to the conversion method:
    const codeForParse = `public class Address {
        public int Id { get; set; }
        public string Street { get; set; }
        public string City { get; set; }
    }`
    
    const output = parser.parse(codeForParse);

    Output:

    export class Address
    {
        Id: number;
        Street: string;
        City: string;
    }

    Configuration

    param type default description
    propertiesToCamelCase boolean true transform properties names to camelCase
    trimPostfixes string | string[] [] Removes specified postfixes from property names, types & class names.
    recursiveTrimPostfixes boolean true Whether or not trim postfixes recursive. (e.g. with postfixes 'A' & 'B' PersonAAB will become PersonAA when it's false and Person when it's true)
    ignoreInitializer boolean true When true to initializers will be ignored
    removeMethodBodies boolean false If true then method bodies will be removed, else preserve the method body as-is
    removeConstructors boolean true When true to removing class constructor
    methodStyle 'signature' | 'lambda' | 'controller' 'signature' 'signature' to emit a method signature. 'lambda' to emit a lambda function. 'controller' to emit a lambda to call an async controller.
    byteArrayToString boolean true true to convert C# byte array type to Typescript string
    dateTypes string | string[] 'Date | string' Convert C# types DateTime and DateTimeOffset to selected types
    removeWithModifier string[] [] Remove fields or properties with the given modifiers (Ex. if you want to remove private and internal members set to ['private', 'internal'])
    removeNameRegex string null If setted, any property or field that its name matches the given regex will be removed
    classToInterface boolean true When true to classes will be converted to interfaces
    preserveModifiers boolean false true to preserve fields and property modifiers
    maxBodyDepth number 8 Maximum body depth
    maxExpressionDepth number 4 Maximum expression depth

    Install

    npm i @factor-sef/cs-to-ts

    DownloadsWeekly Downloads

    6

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    84.2 kB

    Total Files

    88

    Last publish

    Collaborators

    • factor-sef