1.3.2 • Published 1 year ago

typesgenerator v1.3.2

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Typesgenerator

Typesgenerator helps in creating typescript types/interfaces from JSON or JavaScript-object.

Installation and Usage

  • As Package: To use a function for printing type:

npm i -D typesgenerator

Below is usage example for printing the type from the javascript/json object:

import { printType } from 'typesgenerator';

const object = {
  name: 'john doe',
  hobbies: [
    { name: 'coding', outdoor: false },
    { name: 'cycling', outdoor: true },
  ],
  age: 35,
  score: [0, 'A', ['1st']],
};

printType(object, 'Person');

//console output:
/*
export type PersonHobbie = {
  name: string;
  outdoor: boolean;
};

export type Person = {
  name: string;
  hobbies: PersonHobbie[];
  age: number;
  score: (number | string | string[])[];
};
*/
  • As CLI: To create a typescript file from JSON:

npm i -g typesgenerator

Below is the usage example that will create a new file containing types:

tg -n <Type name> -s <path-to-json> -t <path-to-target-directory>

Below are the suppored arguments:

  • -n or -N or --type-name : Name to be given to type
  • -s or -S or --source-path : path to the json
  • (optional )-t or -T or --target-path : path to the type-file to be generated

GitHub: https://github.com/emreSlim/typescript-types-generator

Issues: https://github.com/emreSlim/typescript-types-generator/issues

1.2.4

2 years ago

1.3.2

1 year ago

1.2.3

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.0

2 years ago

1.0.2

2 years ago

1.1.1

2 years ago

1.0.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1-beta

2 years ago

0.0.1

2 years ago