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

0.0.2 • 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;
}
*/

Limitations

Only support TypeScript bundlers (e.g. vite, esbuild). Vanilla js is not distributed in the package

Readme

Keywords

none

Package Sidebar

Install

npm i torex

Weekly Downloads

45

Version

0.0.2

License

MIT

Unpacked Size

29.7 kB

Total Files

16

Last publish

Collaborators

  • chuanqisun