1.0.1 • Published 3 years ago

@web-dev-memo/type-system v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

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[]
}
NameRequiredDefinition
nametrueName of type
istrueFunction for checking type
subForfalseArray 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.