typeof-sjsonc
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

typeof-sjsoncnpm version

在线体验地址

将 similar jsonc 转换为 TypeScript 的 interface

{
    // 123
    "a": 123,
    /** true */
    b: true,
    c: [{d: 'test'}]
}
export interface Root {
    /** 123 */
    a: number;
    /** true */
    b: boolean;
    c: Array<{
        d: string;
    }>;
}

Usage

npm

npm i typeof-sjsonc --save

yarn

yarn add typeof-sjsonc --save

use

import { typeofSjsonc } from 'typeof-sjsonc';

typeofSjsonc(
    '//123\n{a: {//111\naa/**22*/: 123, /**eee*/ b: true,/**bbb*/ // aaa \n}, b: [123,true, {//111\naa/**22*/: 123, /**eee*/ b: true,/**bbb*/ // aaa \n}]} \n/**12*/{c: 123}',
    'aaa'
);

Result

/** 123 */
export interface Aaa {
    a: {
        /**
         * 111
         * 22
         * eee
         */
        aa: number;
        /**
         * bbb
         * aaa
         */
        b: boolean;
    };
    b: Array<
        | number
        | boolean
        | {
              /**
               * 111
               * 22
               * eee
               */
              aa: number;
              /**
               * bbb
               * aaa
               */
              b: boolean;
          }
    >;
}

/** 12 */
export interface Aaa1 {
    c: number;
}

API

typeofSjsonc(jsonc: string, name?: string, options?: {disallowComments?: boolean})

  • jsonc: 待抓换的字符串
  • name: interface 的名字,默认为 root
  • options: 配置项
    • disallowComments: 不产出注释,默认为 false
    • separate: 是否将子结构分割出单独的 interface,默认值 false
    • prifix: 是否添加前缀,例如添加 I

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i typeof-sjsonc

Weekly Downloads

16

Version

1.0.6

License

MIT

Unpacked Size

317 kB

Total Files

7

Last publish

Collaborators

  • wulunyi