joi2types
Convert @hapi/joi schema into TypeScript
Last updated 3 years ago by xiaohuoni .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install joi2types 
SYNC missed versions from official npm registry.

joi2types

codecov NPM version NPM downloads CircleCI Install size

a converter transforms @hapi/joi schema into TypeScript types.

Online demo

Quick start

Install

$ npm i joi2types @hapi/joi -S

use in your project

const Joi = require("@hapi/joi");
const joi2Types = require("joi2types").default;

// example for react-router-config
const schema = Joi.array().items(
  Joi.object({
    path: Joi.string().description("Any valid URL path"),
    component: Joi.string().description(
      "A React component to render only when the location matches."
    ),
    redirect: Joi.string().description("navigate to a new location"),
    exact: Joi.boolean().description(
      "When true, the active class/style will only be applied if the location is matched exactly."
    )
  }).unknown()
);

(async () => {
  const types = await joi2Types(schema, {
    bannerComment: "/** comment for test */",
    interfaceName: "IRoute"
  });
  console.log('types', types)
})();

It will convert into types as follows:

/** comment for test */

export type IRoute = {
  /**
   * Any valid URL path
   */
  path?: string;
  /**
   * A React component to render only when the location matches.
   */
  component?: string;
  /**
   * navigate to a new location
   */
  redirect?: string;
  /**
   * When true, the active class/style will only be applied if the location is matched exactly.
   */
  exact?: boolean;
  [k: string]: any;
}[];

TODO

  • [ ] support custom type definitions using tsType

Current Tags

  • 1.1.1                                ...           latest (3 years ago)

21 Versions

  • 1.1.1                                ...           3 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.8                                ...           5 years ago
  • 1.0.7                                ...           6 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 1.0.0-beta.10                                ...           6 years ago
  • 1.0.0-beta.9                                ...           6 years ago
  • 1.0.0-beta.8                                ...           6 years ago
  • 1.0.0-beta.7                                ...           6 years ago
  • 1.0.0-beta.6                                ...           6 years ago
  • 1.0.0-beta.5                                ...           6 years ago
  • 1.0.0-beta.4                                ...           6 years ago
  • 1.0.0-beta.3                                ...           6 years ago
  • 1.0.0-beta.2                                ...           6 years ago
  • 1.0.0-beta.1                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 4
Last Day 0
Last Week 19
Last Month 17
Dependencies (1)
Dev Dependencies (11)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |