Gathering detailed insights and metrics for ts-interface-keys-transformer-plugin
Gathering detailed insights and metrics for ts-interface-keys-transformer-plugin
Gathering detailed insights and metrics for ts-interface-keys-transformer-plugin
Gathering detailed insights and metrics for ts-interface-keys-transformer-plugin
It parses the interface information during the compilation phase of TypeScript.
npm install ts-interface-keys-transformer-plugin
Typescript
Module System
Node Version
NPM Version
TypeScript (99.85%)
JavaScript (0.15%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Commits
1 Watchers
1 Branches
2 Contributors
Updated on Oct 20, 2021
Latest Version
1.0.2
Package Id
ts-interface-keys-transformer-plugin@1.0.2
Unpacked Size
44.69 kB
Size
7.72 kB
File Count
9
NPM Version
7.6.3
Node Version
14.16.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
6
ts-interface-keys-transformer-plugin
is developed again on the basis of ts-interface-keys-transformer
.
It parses the interface information during the compilation phase of TypeScript.
About feature:
1 2export interface PropertyType { 3 /** 4 * Possible values are: 5 * 6 * unknown、array、string、number、boolean、Function、Array、Set、Map、symbol、any、null、object、 7 * parenthesized、undefined、bigint、symbol、reference other interfaces 8 */ 9 type: string; 10 /** 11 * If it is one of the types set, map, array, array and parenthesized, 12 * it will contain other types referenced by itself. 13 * If there are multiple reference types, they are stored in the order they appear. 14 * @example 15 * 16 * { field: Map<Symbol, number> } => Symbol, number 17 * { field: Set<B> } => B 18 * { field: Cat[] } => Cat 19 * { field: Array<{ a: number }> } => object 20 */ 21 elementType?: PropertyType[]; 22 isParenthesizedType?: boolean; 23 isEnumType?: boolean; 24} 25 26/** 27 * field information contained in interface 28 */ 29export interface Property { 30 name: string; 31 modifiers: string[]; 32 optional: boolean; 33 type: PropertyType[]; 34 /** 35 * If the type of value contains a reference type, its information will also be resolved. 36 * @example 37 * interface Cat { 38 * name: string; 39 * } 40 * interface Foo { 41 * cat: Cat 42 * } 43 * console.log(keys<Foo>()); // Cat information will be stored in the valueInterface field 44 */ 45 valueInterface?: InterfaceInfo[]; 46 docComment: string; 47 jsDocTags: ts.JSDocTagInfo[]; 48 /** 49 * When the field value is an enumeration member type, it is used to store the corresponding enumeration value. 50 * @example 51 * enum AnimalType { 52 * Cat = 2 53 * } 54 * enumTypeValue = `2` 55 */ 56 enumTypeValue?: string; 57} 58 59export interface InterfaceInfo { 60 /** interface name */ 61 name: string; 62 /** original name,eg:type A = B, name is A,originalName is B */ 63 originalName: string; 64 properties: Property[]; 65 docComment: string; 66 jsDocTags: ts.JSDocTagInfo[]; 67} 68
1$ npm i -D typescript ttypescript ts-interface-keys-transformer-plugin
and then add following to "compilerOptions" field in tsconfig.json:
1"plugins": [ 2 { "transform": "ts-interface-keys-transformer-plugin/transformer" } 3 ]
Use following command to run (assume index.js is the compiled file of index.ts):
1$ ttsc -p tsconfig.json && node index.js
1import { keys } from 'ts-interface-keys-transformer-plugin'; 2 3interface Foo { 4 [key: string]: string | number; 5}; 6 7// { 8// name: `Foo`, 9// properties: [ 10// { 11// name: `__index`, 12// modifiers: [], 13// optional: true, 14// type: [{ type: `string` }, { type: `number` }], 15// docComment: ``, 16// jsDocTags: [] 17// } 18// ], 19// originalName: `Foo`, 20// docComment: ``, 21// jsDocTags: [] 22// } 23console.log(keys<Foo>());
1import { keys } from 'ts-interface-keys-transformer-plugin'; 2 3interface Foo { 4 /** 5 * any field 6 * @min 10 7 */ 8 [key: string]: { a: string, b?: SSnake; }[]; 9}; 10 11// { 12// name: `Foo`, 13// properties: [ 14// { 15// name: `__index`, 16// modifiers: [], 17// optional: true, 18// type: [{ type: `array`, elementType: [{ type: `object` }] }], 19// docComment: `any field`, 20// jsDocTags: [{ name: `min`, text: '10' }], 21// valueInterface: [ 22// { 23// name: `__type`, 24// originalName: `__type`, 25// properties: [ 26// { 27// name: `a`, 28// modifiers: [], 29// optional: false, 30// type: [{ type: `string` }], 31// docComment: ``, 32// jsDocTags: [] 33// }, 34// { 35// name: `b`, 36// modifiers: [], 37// optional: true, 38// type: [{ type: `SSnake`, isEnumType: false }], 39// docComment: ``, 40// jsDocTags: [], 41// valueInterface: [ 42// { 43// name: `SSnake`, 44// originalName: `Snake`, 45// properties: [{ 46// name: `s`, 47// modifiers: [], 48// optional: false, 49// type: [{ type: `number` }], 50// docComment: ``, 51// jsDocTags: [] 52// }], 53// docComment: ``, 54// jsDocTags: [] 55// } 56// ] 57// } 58// ], 59// docComment: ``, 60// jsDocTags: [] 61// } 62// ] 63// } 64// ], 65// originalName: `Foo`, 66// docComment: ``, 67// jsDocTags: [] 68// } 69console.log(keys<Foo>());
See more test cases in Tests
1npm run build
1npm test
No vulnerabilities found.
No security vulnerabilities found.