UNPKG

dtsgeneratorws

Version:

TypeScript d.ts file generator for JSON Schema file

24 lines (20 loc) 689 B
import dtsGenerator, { DefaultTypeNameConvertor, SchemaId } from 'dtsgenerator'; import * as fs from 'fs'; const filePath = '../../test/snapshots/json-schema-draft-04/schema/schema.json'; function typeNameConvertor(id: SchemaId): string[] { const names = DefaultTypeNameConvertor(id); if (names.length > 0) { const lastIndex = names.length - 1; names[lastIndex] = 'I' + names[lastIndex]; } return names; } async function main(): Promise<void> { const content = JSON.parse( fs.readFileSync(filePath, 'utf-8') ); const result = await dtsGenerator({ contents: [content], typeNameConvertor, }); console.log(result); } main();