https://github.com/chuanqisun/torex
Typed Object Reflection: Infer TypeScript interface from JSON
https://github.com/chuanqisun/torex
Last synced: 8 months ago
JSON representation
Typed Object Reflection: Infer TypeScript interface from JSON
- Host: GitHub
- URL: https://github.com/chuanqisun/torex
- Owner: chuanqisun
- License: mit
- Created: 2023-07-31T01:02:23.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-12T21:38:33.000Z (about 1 year ago)
- Last Synced: 2025-02-18T21:19:52.555Z (8 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/torex
- Size: 153 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 🦖 Torex
**Typed Object Reflection**: Infer TypeScript interface from JSON
## Get started
Install
```bash
npm i torex
```Examples
```typescript
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;
}
*/
```