typeof-jsonc
typeof-jsonc
is a library for Convert json or jsonc string to typescript type (interface)
Support
- Basic types
- Array types (support auto merge)
- Same struct auto merge
- Comments
- JsDocComments
- Custom naming
- Json
- Jsonc
- Not standard jsonc or json
Usage
install
npm install typeof-jsonc -S
or
yarn add typeof-jsonc -S
Demo
Jsonc string
{ "barr": [ // aaa "aaa", "bbb" ], "name": "lanfeng", // this is name // this is demo "demo": { "hello": "world" }, /** this is arr */ "arr": [ { "age": 1 }, 2 ], "a": "hello", "b": ["a", "b"]}
Convert script
;; ; ; console.log typeofJsonctext, 'Response', ,;
Output
/** this is arr */
API
- typeofJsonc(jsonc: string, name: string, options?: Options)
option | type | default | desc |
---|---|---|---|
prefix | string | "" | type name prefix |
onName | (name: string) => string | (name: string) => ${prefix}${name} |
Custom naming If this option set prefix will not work |
addExport | boolean | false | Add export keywords, when set true rootFlags set will not work |
rootFlags | number | 0 | Identifiers are e.g. legal variable names. They may not be reserved words None = 0 Module = 1 InAmbientNamespace = 2 |
disallowComments | boolean | true | Whether to prohibit the generation of comments |
singleLineJsDocComments | boolean | false | Single-line display when single-line comment |
Version
1.1.9
- Implementation refactor
- Same struct auto merge
1.1.8
- Fix addExport bug
- Pack umd and es lib
1.1.6
- Support singleLineJsDocComments options
1.1.5
- Support convert not standard jsonc or json
Standard jsonc or json demo
{ "name": "test", "age": 13, "loves": ["A", "B"]}
Not standard jsonc or json demo
{
name: '',
age: 13,
loves: ['A', 'B']
}
License
MIT