π€ Empower your type handling with uniqueness and customization. Effortlessly create and manage tailored types for a robust and flexible codebase. π
# nyxi
nyxi add typiqus
# pnpm
pnpm add typiqus
# npm
npm i typiqus
# yarn
yarn add typiqus
First we have to define a reference object that describes types, defaults, and a $resolve
method (normalizer).
const defaultPlanet = {
name: 'earth',
specs: {
gravity: {
$resolve: val => parseFloat(val),
$default: '9.8'
},
moons: {
$resolve: (val = ['moon']) => [].concat(val),
$schema: {
title: 'planet moons'
}
}
}
}
import { resolveSchema } from 'typiqus'
const schema = await resolveSchema(defaultPlanet)
π Output:
{
"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"
}
import { resolveSchema, generateTypes } from 'typiqus'
const types = generateTypes(await resolveSchema(defaultPlanet))
π Output:
interface Typiqus {
/** @default "earth" */
name: string,
specs: {
/** @default 9.8 */
gravity: number,
/**
* planet moons
* @default ["moon"]
*/
moons: string[],
},
}
import { resolveSchema, generateMarkdown } from 'typiqus'
const markdown = generateMarkdown(await resolveSchema(defaultPlanet))
π Output:
# `name`
- **Type**: `string`
- **Default**: `"earth"`
# `specs`
## `gravity`
- **Type**: `number`
- **Default**: `9.8`
## `moons`
- **Type**: `array`
- **Default**: `["moon"]`
- π Clone this repository
- π§ Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - π¦ Install dependencies using
nyxi
- π Run interactive tests using
nyxr dev
- π Run
nyxr web
to start playground website - π Run
pnpm test
before push to ensure all tests and lint checks passing
MIT - Made with π