Skip to content

πŸ”€ Empower your type handling with uniqueness and customization. Effortlessly create and manage tailored types for a robust and flexible codebase. πŸš€

License

Notifications You must be signed in to change notification settings

nyxblabs/typiqus

Repository files navigation

cover npm version npm downloads bundle License

🧬 Typiqus

πŸ”€ Empower your type handling with uniqueness and customization. Effortlessly create and manage tailored types for a robust and flexible codebase. πŸš€

▢️ Check online playground

πŸ’Ύ Install

# nyxi
nyxi add typiqus

# pnpm
pnpm add typiqus

# npm
npm i typiqus

# yarn
yarn add typiqus

πŸ“š Usage

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'
      }
    }
  }
}

🌐 API

🧩 resolveSchema

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"
}

🏭 generateTypes

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[],
  },
}

πŸ“„ generateMarkdown

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"]`

🌱 Development

  • πŸ™ Clone this repository
  • πŸ”§ Enable Corepack using corepack enable (use npm 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

πŸ“œ License

MIT - Made with πŸ’ž

About

πŸ”€ Empower your type handling with uniqueness and customization. Effortlessly create and manage tailored types for a robust and flexible codebase. πŸš€

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project