https://github.com/stackql/generate-types
Deno module to generate a TypeScript types module file from JSON data (or a parsed JSON string).
https://github.com/stackql/generate-types
Last synced: 7 months ago
JSON representation
Deno module to generate a TypeScript types module file from JSON data (or a parsed JSON string).
- Host: GitHub
- URL: https://github.com/stackql/generate-types
- Owner: stackql
- Created: 2022-10-06T05:49:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-07T03:51:01.000Z (over 3 years ago)
- Last Synced: 2024-05-01T11:44:46.527Z (over 1 year ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 🦕 generate-types
[](https://deno.land/x/dts)

Deno module to generate a TypeScript types module file from JSON data (or a
parsed JSON string).
## Usage
```typescript
import { generateTypes } from "https://deno.land/x/dts/mod.ts";
async function main() {
const jsonString = `{
"external_urls": {
"spotify": "https://open.spotify.com/artist/4Z8W4fKeB5YxbusRsdQVPb"
},
"followers": {
"href": null,
"total": 7405000
},
"genres": [
"alternative rock",
"art rock",
"melancholia",
"oxford indie",
"permanent wave",
"rock"
],
"href": "https://api.spotify.com/v1/artists/4Z8W4fKeB5YxbusRsdQVPb",
"id": "4Z8W4fKeB5YxbusRsdQVPb",
"name": "Radiohead",
"popularity": 79,
"type": "artist",
"uri": "spotify:artist:4Z8W4fKeB5YxbusRsdQVPb"
}`;
const inputObject = JSON.parse(jsonString);
const result = await generateTypes(inputObject);
console.log(result);
}
main();
```
outputs...
```
declare module namespace {
export interface IRootObject {
IExternal_urls: object
IFollowers: object
genres: string[]
href: string
id: string
name: string
popularity: number
type: string
uri: string
}
export interface IExternal_urls {
spotify: string
}
export interface IFollowers {
href: any
total: number
}
}
```
## Test
```bash
deno test
```