1.2.0 • Published 3 years ago

@factor-sef/cs-to-ts v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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

paramtypedefaultdescription
propertiesToCamelCasebooleantruetransform properties names to camelCase
trimPostfixesstring \| string[][]Removes specified postfixes from property names, types & class names.
recursiveTrimPostfixesbooleantrueWhether 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)
ignoreInitializerbooleantrueWhen true to initializers will be ignored
removeMethodBodiesbooleanfalseIf true then method bodies will be removed, else preserve the method body as-is
removeConstructorsbooleantrueWhen 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.
byteArrayToStringbooleantruetrue to convert C# byte array type to Typescript string
dateTypesstring \| string[]'Date \| string'Convert C# types DateTime and DateTimeOffset to selected types
removeWithModifierstring[][]Remove fields or properties with the given modifiers (Ex. if you want to remove private and internal members set to ['private', 'internal'])
removeNameRegexstringnullIf setted, any property or field that its name matches the given regex will be removed
classToInterfacebooleantrueWhen true to classes will be converted to interfaces
preserveModifiersbooleanfalsetrue to preserve fields and property modifiers
maxBodyDepthnumber8Maximum body depth
maxExpressionDepthnumber4Maximum expression depth
1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago