@hacxy/json2ts
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

Json2Ts

Overview

Json2Ts is a code generation tool that transforms Json Data into Typescript types.

Targets Browsers and Node.js .

Install

npm install @hacxy/json2ts --save

Example

import json2ts from '@hacxy/json2ts';

json2ts(`{"id": 1, "name": "hacxy"}`, 'Root').then((code) => {
  console.log(code);
});
/**
  export interface Root {
    id: number;
    name: string;
  }
 */

function: json2ts()

json2ts(json, name): Promise<string>

Params

name types default description
json string undefined json data
name string 'Root' define type name
options Json2TsOptions { indentation: 2 } Generate options

Json2TsOptions

interface Json2TsOptions {
  /**
   * indentation of the generated code, default is 2 spaces
   */
  indentation?: number;
}

Returns

Promise<string>

Related

License

MIT

Dependencies (1)

Dev Dependencies (14)

Package Sidebar

Install

npm i @hacxy/json2ts

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

4.33 kB

Total Files

5

Last publish

Collaborators

  • hacxy