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

1.0.1 • Public • Published

🦖 Torex

Typed Object Reflection: Infer TypeScript interface from JSON

Get started

Install

npm i torex

Examples

import { getType } from "torex";

getType({
  myKey: "myValue",
})
/*
interface IRoot {
  myKey: string;
}
*/

getType({ myKey: "myValue" }, { rootName: "MyObject" });
/*
interface IMyObject {
  myKey: string;
}
*/

getType([{ name: "a" }, { name: "b", size: 42 }]);
/*
type Root = IRootItem[];

interface IRootItem {
  name: string;
  size?: number;
}
*/

getType([{ name: "a" }, { name: "b", size: 42 }], { scope: "root-item" });
/*
type Root = IRootItem[];

interface IRootItem {
  name: string;
  size?: number;
}
*/

getType([{ name: "a" }, { name: "b", size: 42 }], { rootName: "MyObject", scope: "root-item" }));
/*
interface IMyObject {
  name: string;
  size?: number;
}
*/

Readme

Keywords

none

Package Sidebar

Install

npm i torex

Weekly Downloads

10

Version

1.0.1

License

MIT

Unpacked Size

20.1 kB

Total Files

18

Last publish

Collaborators

  • chuanqisun