Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/unjs/untyped
Generate types and markdown from a config object.
https://github.com/unjs/untyped
config generator markdown typescript
Last synced: about 2 months ago
JSON representation
Generate types and markdown from a config object.
- Host: GitHub
- URL: https://github.com/unjs/untyped
- Owner: unjs
- License: mit
- Created: 2021-03-20T14:10:37.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-05-17T22:03:10.000Z (7 months ago)
- Last Synced: 2024-05-17T23:21:02.887Z (7 months ago)
- Topics: config, generator, markdown, typescript
- Language: TypeScript
- Homepage: https://untyped.unjs.io/
- Size: 1.48 MB
- Stars: 374
- Watchers: 6
- Forks: 19
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# untyped
[![npm version](https://img.shields.io/npm/v/untyped)](https://npmjs.com/package/untyped)
[![npm downloads](https://img.shields.io/npm/dm/untyped)](https://npm.chart.dev/untyped)
[![bundle size](https://img.shields.io/bundlejs/size/untyped)](https://bundlejs.com/?q=untyped)**▶️ Check [online playground](https://untyped.unjs.io)**
## Install
```sh
# ✨ Auto-detect
npx nypm install untyped# npm
npm install untyped# yarn
yarn add untyped# pnpm
pnpm install untyped# bun
bun install untyped# deno
deno install untyped
```## Usage
First we have to define a reference object that describes types, defaults, and a `$resolve` method (normalizer).
```js
const defaultPlanet = {
name: "earth",
specs: {
gravity: {
$resolve: (val) => Number.parseFloat(val),
$default: "9.8",
},
moons: {
$resolve: (val = ["moon"]) => [val].flat(),
$schema: {
title: "planet moons",
},
},
},
};
```## API
### `resolveSchema`
```js
import { resolveSchema } from "untyped";const schema = await resolveSchema(defaultPlanet);
```Output:
```json
{
"properties": {
"name": {
"type": "string",
"default": "earth"
},
"specs": {
"properties": {
"gravity": {
"default": 9.8,
"type": "number"
},
"moons": {
"title": "planet moons",
"default": ["moon"],
"type": "array",
"items": [
{
"type": "string"
}
]
}
},
"type": "object"
}
},
"type": "object"
}
```### `generateTypes`
```js
import { resolveSchema, generateTypes } from "untyped";const types = generateTypes(await resolveSchema(defaultPlanet));
```Output:
```ts
interface Untyped {
/** @default "earth" */
name: string;specs: {
/** @default 9.8 */
gravity: number;/**
* planet moons
* @default ["moon"]
*/
moons: string[];
};
}
```### `generateMarkdown`
```js
import { resolveSchema, generateMarkdown } from "untyped";const markdown = generateMarkdown(await resolveSchema(defaultPlanet));
```Output:
```markdown
# `name`- **Type**: `string`
- **Default**: `"earth"`# `specs`
## `gravity`
- **Type**: `number`
- **Default**: `9.8`## `moons`
- **Type**: `array`
- **Default**: `["moon"]`
```## 💻 Development
- Clone this repository
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`
- Use `pnpm web` to start playground website
- Use `pnpm test` before push to ensure all tests and lint checks passing## License
[MIT](./LICENSE)
Thanks to [@dominikschreiber](https://github.com/dominikschreiber) for donating package name.
[npm-version-src]: https://img.shields.io/npm/v/untyped?style=flat-square
[npm-version-href]: https://npmjs.com/package/untyped
[npm-downloads-src]: https://img.shields.io/npm/dm/untyped?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/untyped
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/untyped/ci.yml?branch-main&style=flat-square
[github-actions-href]: https://github.com/unjs/untyped/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/untyped/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/untyped
[bundle-src]: https://img.shields.io/bundlephobia/minzip/untyped?style=flat-square
[bundle-href]: https://bundlephobia.com/result?p=untyped