Mobydack / type-system

Generate custom type system

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Type system

Install

npm i --save @web-dev-memo/type-system

Usage

import TypeSystem from "@web-dev-memo/type-sytem";

const typeSystem = new TypeSystem(
    {
        name: "String",
        is: (value: unknown) => typeof value === "string"
    },
    {
        name: "Marcus",
        is: (value: string) => value.toLowerCase() === "marcus",
        subFor: ["String"]
    }
);

console.log(typeSystem.typeof("some test")); // "String"
console.log(typeSystem.typeof("some test")); // "Marcus"

Type definition

Type has next interface

export interface IType {
    name: string;
    is: (value: unknown, path?: string[]) => boolean;
    subFor?: string[]
}
Name Required Definition
name true Name of type
is true Function for checking type
subFor false Array of parent type name

subFor

This property is required to determine the relationship to the parent type. Thus this type will be checked only if the parent type passes the check.

About

Generate custom type system


Languages

Language:TypeScript 73.2%Language:JavaScript 24.6%Language:Shell 2.1%