| import { Type } from "./type"; | ||
| export declare class EnumType<E = any> extends Type { | ||
| private typeName; | ||
| private acceptableValues; | ||
| constructor(acceptableValues: E[], typeName?: string, isOptional?: boolean); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } |
| import { ObjectType } from "./object-type"; | ||
| export declare class IntersectionType extends ObjectType { | ||
| protected typeName: string; | ||
| constructor(types: ObjectType[], isOptional?: boolean); | ||
| } |
| export {}; |
| export declare const TEST_VALUES: any; |
| import { Type } from "./type"; | ||
| export declare class UnionType<E = any> extends Type<E> { | ||
| protected typeName: string; | ||
| protected acceptableTypes: Type[]; | ||
| constructor(types: Type[], isOptional?: boolean); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } |
+185
| // For a detailed explanation regarding each configuration property, visit: | ||
| // https://jestjs.io/docs/en/configuration.html | ||
| module.exports = { | ||
| // All imported modules in your tests should be mocked automatically | ||
| // automock: false, | ||
| // Stop running tests after `n` failures | ||
| // bail: 0, | ||
| // Respect "browser" field in package.json when resolving modules | ||
| // browser: false, | ||
| // The directory where Jest should store its cached dependency information | ||
| // cacheDirectory: "/tmp/jest_rs", | ||
| // Automatically clear mock calls and instances between every test | ||
| clearMocks: true, | ||
| // Indicates whether the coverage information should be collected while executing the test | ||
| collectCoverage: true, | ||
| // An array of glob patterns indicating a set of files for which coverage information should be collected | ||
| // collectCoverageFrom: null, | ||
| // The directory where Jest should output its coverage files | ||
| coverageDirectory: "ts/test/coverage", | ||
| // An array of regexp pattern strings used to skip coverage collection | ||
| // coveragePathIgnorePatterns: [ | ||
| // "/node_modules/" | ||
| // ], | ||
| // A list of reporter names that Jest uses when writing coverage reports | ||
| // coverageReporters: [ | ||
| // "json", | ||
| // "text", | ||
| // "lcov", | ||
| // "clover" | ||
| // ], | ||
| // An object that configures minimum threshold enforcement for coverage results | ||
| // coverageThreshold: null, | ||
| // A path to a custom dependency extractor | ||
| // dependencyExtractor: null, | ||
| // Make calling deprecated APIs throw helpful error messages | ||
| // errorOnDeprecated: false, | ||
| // Force coverage collection from ignored files using an array of glob patterns | ||
| // forceCoverageMatch: [], | ||
| // A path to a module which exports an async function that is triggered once before all test suites | ||
| // globalSetup: null, | ||
| // A path to a module which exports an async function that is triggered once after all test suites | ||
| // globalTeardown: null, | ||
| // A set of global variables that need to be available in all test environments | ||
| // globals: {}, | ||
| // An array of directory names to be searched recursively up from the requiring module's location | ||
| // moduleDirectories: [ | ||
| // "node_modules" | ||
| // ], | ||
| // An array of file extensions your modules use | ||
| // moduleFileExtensions: [ | ||
| // "js", | ||
| // "json", | ||
| // "jsx", | ||
| // "ts", | ||
| // "tsx", | ||
| // "node" | ||
| // ], | ||
| // A map from regular expressions to module names that allow to stub out resources with a single module | ||
| // moduleNameMapper: {}, | ||
| // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader | ||
| // modulePathIgnorePatterns: [], | ||
| // Activates notifications for test results | ||
| // notify: false, | ||
| // An enum that specifies notification mode. Requires { notify: true } | ||
| // notifyMode: "failure-change", | ||
| // A preset that is used as a base for Jest's configuration | ||
| // preset: null, | ||
| // Run tests from one or more projects | ||
| // projects: null, | ||
| // Use this configuration option to add custom reporters to Jest | ||
| // reporters: undefined, | ||
| // Automatically reset mock state between every test | ||
| // resetMocks: false, | ||
| // Reset the module registry before running each individual test | ||
| // resetModules: false, | ||
| // A path to a custom resolver | ||
| // resolver: null, | ||
| // Automatically restore mock state between every test | ||
| // restoreMocks: false, | ||
| // The root directory that Jest should scan for tests and modules within | ||
| // rootDir: null, | ||
| // A list of paths to directories that Jest should use to search for files in | ||
| roots: [ | ||
| "<rootDir>/js/test" | ||
| ], | ||
| // Allows you to use a custom runner instead of Jest's default test runner | ||
| // runner: "jest-runner", | ||
| // The paths to modules that run some code to configure or set up the testing environment before each test | ||
| // setupFiles: [], | ||
| // A list of paths to modules that run some code to configure or set up the testing framework before each test | ||
| // setupFilesAfterEnv: [], | ||
| // A list of paths to snapshot serializer modules Jest should use for snapshot testing | ||
| // snapshotSerializers: [], | ||
| // The test environment that will be used for testing | ||
| testEnvironment: "node", | ||
| // Options that will be passed to the testEnvironment | ||
| // testEnvironmentOptions: {}, | ||
| // Adds a location field to test results | ||
| // testLocationInResults: false, | ||
| // The glob patterns Jest uses to detect test files | ||
| // testMatch: [ | ||
| // "**/__tests__/**/*.[jt]s?(x)", | ||
| // "**/?(*.)+(spec|test).[tj]s?(x)" | ||
| // ], | ||
| // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped | ||
| // testPathIgnorePatterns: [ | ||
| // "/node_modules/" | ||
| // ], | ||
| // The regexp pattern or array of patterns that Jest uses to detect test files | ||
| // testRegex: [], | ||
| // This option allows the use of a custom results processor | ||
| // testResultsProcessor: null, | ||
| // This option allows use of a custom test runner | ||
| // testRunner: "jasmine2", | ||
| // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href | ||
| // testURL: "http://localhost", | ||
| // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout" | ||
| // timers: "real", | ||
| // A map from regular expressions to paths to transformers | ||
| // transform: null, | ||
| // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation | ||
| // transformIgnorePatterns: [ | ||
| // "/node_modules/" | ||
| // ], | ||
| // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them | ||
| // unmockedModulePathPatterns: undefined, | ||
| // Indicates whether each individual test should be reported during the run | ||
| // verbose: null, | ||
| // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode | ||
| // watchPathIgnorePatterns: [], | ||
| // Whether to use watchman for file crawling | ||
| // watchman: true, | ||
| }; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = require("./type"); | ||
| class EnumType extends type_1.Type { | ||
| constructor(acceptableValues, typeName, isOptional = false) { | ||
| super(isOptional); | ||
| this.acceptableValues = acceptableValues; | ||
| if (typeName !== undefined) | ||
| this.typeName = typeName; | ||
| else { | ||
| this.typeName = "enum"; | ||
| } | ||
| } | ||
| getTypeName() { | ||
| return this.typeName; | ||
| } | ||
| checkConformity(input) { | ||
| return this.acceptableValues.some((value) => (value === input)); | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| let once = false; | ||
| for (let value of this.acceptableValues) { | ||
| if (value === input) { | ||
| if (once) | ||
| return false; | ||
| else | ||
| once = true; | ||
| } | ||
| } | ||
| return once; | ||
| } | ||
| } | ||
| exports.EnumType = EnumType; | ||
| //# sourceMappingURL=enum-type.js.map |
| {"version":3,"file":"enum-type.js","sourceRoot":"","sources":["../ts/enum-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAS9B,MAAa,QAAkB,SAAQ,WAAI;IAM1C,YAAmB,gBAAqB,EAAE,QAAiB,EAAE,aAAsB,KAAK;QAEvF,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAEzC,IAAI,QAAQ,KAAK,SAAS;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;aAChD;YAEJ,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;SAIvB;IAEF,CAAC;IAEM,WAAW;QAEjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IAEtB,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,KAAQ,EAAW,EAAE,CAAC,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC;IAE7E,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,IAAI,IAAI,GAAY,KAAK,CAAC;QAE1B,KAAK,IAAI,KAAK,IAAI,IAAI,CAAC,gBAAgB,EAAE;YAExC,IAAI,KAAK,KAAK,KAAK,EAAE;gBAEpB,IAAI,IAAI;oBAAE,OAAO,KAAK,CAAC;;oBAClB,IAAI,GAAG,IAAI,CAAC;aAEjB;SAED;QAED,OAAO,IAAI,CAAC;IAEb,CAAC;CAED;AAtDD,4BAsDC"} |
| "use strict"; | ||
| var __importStar = (this && this.__importStar) || function (mod) { | ||
| if (mod && mod.__esModule) return mod; | ||
| var result = {}; | ||
| if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
| result["default"] = mod; | ||
| return result; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const object_type_1 = require("./object-type"); | ||
| const Merj = __importStar(require("merj")); | ||
| class IntersectionType extends object_type_1.ObjectType { | ||
| constructor(types, isOptional = false) { | ||
| super(Merj.merge(types.map((type) => type.getObjectTypeDefinition())), "", isOptional); | ||
| this.typeName = ""; | ||
| for (let type of types) { | ||
| if (this.typeName !== "") | ||
| this.typeName += " & "; | ||
| this.typeName += type.getTypeName(); | ||
| } | ||
| } | ||
| } | ||
| exports.IntersectionType = IntersectionType; | ||
| //# sourceMappingURL=intersection-type.js.map |
| {"version":3,"file":"intersection-type.js","sourceRoot":"","sources":["../ts/intersection-type.ts"],"names":[],"mappings":";;;;;;;;;AAMA,+CAA2C;AAC3C,2CAA6B;AA6B7B,MAAa,gBAAiB,SAAQ,wBAAU;IAI/C,YAAmB,KAAmB,EAAE,aAAsB,KAAK;QAElE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAgB,EAAE,EAAE,CAAC,IAAI,CAAC,uBAAuB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,CAAC;QAEnG,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;YAEvB,IAAI,IAAI,CAAC,QAAQ,KAAK,EAAE;gBAAE,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC;YACjD,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;SAEpC;IAEF,CAAC;CAED;AAnBD,4CAmBC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const standard_type_1 = require("../standard-type"); | ||
| const test_values_1 = require("./test-values"); | ||
| describe("Number Type", () => { | ||
| test("Number", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.BASIC)).toBeTruthy(); | ||
| }); | ||
| test("Boolean", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("String", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.STRING.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Undefined", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.SPECIAL.UNDEFINED)).toBeFalsy(); | ||
| }); | ||
| test("Null", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.SPECIAL.NULL)).toBeFalsy(); | ||
| }); | ||
| describe("Special Numeric Values", () => { | ||
| test("Zero", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.ZERO)).toBeTruthy(); | ||
| }); | ||
| test("Positive Infinity", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.POSITIVE_INFINITY)).toBeTruthy(); | ||
| }); | ||
| test("Negative Infinity", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.NEGATIVE_INFINITY)).toBeTruthy(); | ||
| }); | ||
| test("Max Safe Integer", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MAX_SAFE_INTEGER)).toBeTruthy(); | ||
| }); | ||
| test("Min Safe Integer", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MIN_SAFE_INTEGER)).toBeTruthy(); | ||
| }); | ||
| test("Max Value", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MAX_VALUE)).toBeTruthy(); | ||
| }); | ||
| test("Min Value", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MIN_VALUE)).toBeTruthy(); | ||
| }); | ||
| test("NaN", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.NUMBERS.NAN)).toBeTruthy(); | ||
| }); | ||
| }); | ||
| describe("Special Boolean Values", () => { | ||
| test("True", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.TRUE)).toBeFalsy(); | ||
| }); | ||
| test("False", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.FALSE)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special String Values", () => { | ||
| test("Empty String", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.STRING.EMPTY)).toBeFalsy(); | ||
| }); | ||
| test("Numeric String", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.STRING.NUMERIC)).toBeFalsy(); | ||
| }); | ||
| test("Symbol String", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.STRING.SYMBOLS)).toBeFalsy(); | ||
| }); | ||
| test("Long String", () => { | ||
| expect(standard_type_1.StandardType.NUMBER.checkConformity(test_values_1.TEST_VALUES.STRING.LONG)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("Boolean Type", () => { | ||
| test("Number", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Boolean", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.BASIC)).toBeTruthy(); | ||
| }); | ||
| test("String", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.STRING.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Undefined", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.SPECIAL.UNDEFINED)).toBeFalsy(); | ||
| }); | ||
| test("Null", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.SPECIAL.NULL)).toBeFalsy(); | ||
| }); | ||
| describe("Special Numeric Values", () => { | ||
| test("Zero", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.ZERO)).toBeFalsy(); | ||
| }); | ||
| test("Positive Infinity", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.POSITIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Negative Infinity", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.NEGATIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Max Safe Integer", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MAX_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Min Safe Integer", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MIN_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Max Value", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MAX_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("Min Value", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MIN_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("NaN", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.NUMBERS.NAN)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special Boolean Values", () => { | ||
| test("True", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.TRUE)).toBeTruthy(); | ||
| }); | ||
| test("False", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.FALSE)).toBeTruthy(); | ||
| }); | ||
| }); | ||
| describe("Special String Values", () => { | ||
| test("Empty String", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.STRING.EMPTY)).toBeFalsy(); | ||
| }); | ||
| test("Numeric String", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.STRING.NUMERIC)).toBeFalsy(); | ||
| }); | ||
| test("Symbol String", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.STRING.SYMBOLS)).toBeFalsy(); | ||
| }); | ||
| test("Long String", () => { | ||
| expect(standard_type_1.StandardType.BOOLEAN.checkConformity(test_values_1.TEST_VALUES.STRING.LONG)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("String Type", () => { | ||
| test("Number", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Boolean", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("String", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.STRING.BASIC)).toBeTruthy(); | ||
| }); | ||
| test("Undefined", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.SPECIAL.UNDEFINED)).toBeFalsy(); | ||
| }); | ||
| test("Null", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.SPECIAL.NULL)).toBeFalsy(); | ||
| }); | ||
| describe("Special Numeric Values", () => { | ||
| test("Zero", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.ZERO)).toBeFalsy(); | ||
| }); | ||
| test("Positive Infinity", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.POSITIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Negative Infinity", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.NEGATIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Max Safe Integer", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MAX_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Min Safe Integer", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MIN_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Max Value", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MAX_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("Min Value", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.MIN_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("NaN", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.NUMBERS.NAN)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special Boolean Values", () => { | ||
| test("True", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.TRUE)).toBeFalsy(); | ||
| }); | ||
| test("False", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.BOOLEAN.FALSE)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special String Values", () => { | ||
| test("Empty String", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.STRING.EMPTY)).toBeTruthy(); | ||
| }); | ||
| test("Numeric String", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.STRING.NUMERIC)).toBeTruthy(); | ||
| }); | ||
| test("Symbol String", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.STRING.SYMBOLS)).toBeTruthy(); | ||
| }); | ||
| test("Long String", () => { | ||
| expect(standard_type_1.StandardType.STRING.checkConformity(test_values_1.TEST_VALUES.STRING.LONG)).toBeTruthy(); | ||
| }); | ||
| }); | ||
| }); | ||
| test.todo("Optional Number Type"); | ||
| test.todo("Optional Boolean Type"); | ||
| test.todo("Optional String Type"); | ||
| //# sourceMappingURL=standard-type.test.js.map |
| {"version":3,"file":"standard-type.test.js","sourceRoot":"","sources":["../../ts/test/standard-type.test.ts"],"names":[],"mappings":";;AAMA,oDAAgD;AAChD,+CAA4C;AAU5C,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IAE5B,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;QAEnB,MAAM,CAAC,4BAAY,CAAC,MAAM,CAAC,eAAe,CAAC,yBAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;IAErF,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;QAEpB,MAAM,CAAC,4BAAY,CAAC,MAAM,CAAC,eAAe,CAAC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AE;YAE1B,MAAM,CAAC,4BAAY,CAAC,MAAM,CAAC,eAAe,CAAC,yBAAW,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QAEtF,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,aAAa,EAAE,GAAG,EAAE;YAExB,MAAM,CAAC,4BAAY,CAAC,MAAM,CAAC,eAAe,CAAC,yBAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;QAEnF,CAAC,CAAC,CAAC;IAEJ,CAAC,CAAC,CAAC;AAEJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;AAElC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AAEnC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.TEST_VALUES = { | ||
| NUMBERS: { | ||
| BASIC: 5, | ||
| ZERO: 0, | ||
| POSITIVE_INFINITY: Number.POSITIVE_INFINITY, | ||
| NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY, | ||
| MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER, | ||
| MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER, | ||
| MAX_VALUE: Number.MAX_VALUE, | ||
| MIN_VALUE: Number.MIN_VALUE, | ||
| NAN: Number.NaN | ||
| }, | ||
| BOOLEAN: { | ||
| BASIC: true, | ||
| TRUE: true, | ||
| FALSE: false | ||
| }, | ||
| STRING: { | ||
| BASIC: "string", | ||
| NUMERIC: "1234567890", | ||
| SYMBOLS: "`~!@#$%^&*()_+=-{}|[]\\:\";'<>?,./", | ||
| EMPTY: "", | ||
| LONG: "linasdfiuhnapsdgoim[oinpiubasodifnpasiudbpgoasdnfoimpoipiausdhfoaisdmf[oim[oinpunasfdinapsdoifn[opiasdf[iop98j=09148n3tg-9n-[08jsd[onfpioH" | ||
| }, | ||
| SPECIAL: { | ||
| UNDEFINED: undefined, | ||
| NULL: null | ||
| } | ||
| }; | ||
| //# sourceMappingURL=test-values.js.map |
| {"version":3,"file":"test-values.js","sourceRoot":"","sources":["../../ts/test/test-values.ts"],"names":[],"mappings":";;AAAa,QAAA,WAAW,GAAQ;IAE/B,OAAO,EAAE;QAER,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;QACP,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAC3C,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;QACzC,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,GAAG,EAAE,MAAM,CAAC,GAAG;KAEf;IAED,OAAO,EAAE;QAER,KAAK,EAAE,IAAI;QACX,IAAI,EAAE,IAAI;QACV,KAAK,EAAE,KAAK;KAEZ;IAED,MAAM,EAAE;QAEP,KAAK,EAAE,QAAQ;QACf,OAAO,EAAE,YAAY;QACrB,OAAO,EAAE,oCAAoC;QAC7C,KAAK,EAAE,EAAE;QACT,IAAI,EAAE,4IAA4I;KAElJ;IAED,OAAO,EAAE;QAER,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,IAAI;KAEV;CAED,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = require("./type"); | ||
| class UnionType extends type_1.Type { | ||
| constructor(types, isOptional = false) { | ||
| super(isOptional); | ||
| this.acceptableTypes = types; | ||
| this.typeName = ""; | ||
| for (let type of types) { | ||
| if (this.typeName !== "") | ||
| this.typeName += " | "; | ||
| this.typeName += type.getTypeName(); | ||
| } | ||
| } | ||
| getTypeName() { | ||
| return this.typeName; | ||
| } | ||
| checkConformity(input) { | ||
| return this.acceptableTypes.some((type) => type.checkConformity(input)); | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| let once = false; | ||
| for (let type of this.acceptableTypes) { | ||
| if (type.checkConformity(input)) { | ||
| if (once) | ||
| return false; | ||
| else | ||
| once = true; | ||
| } | ||
| } | ||
| return once; | ||
| } | ||
| } | ||
| exports.UnionType = UnionType; | ||
| //# sourceMappingURL=union-type.js.map |
| {"version":3,"file":"union-type.js","sourceRoot":"","sources":["../ts/union-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAS9B,MAAa,SAAmB,SAAQ,WAAO;IAM9C,YAAmB,KAAa,EAAE,aAAsB,KAAK;QAE5D,KAAK,CAAC,UAAU,CAAC,CAAC;QAElB,IAAI,CAAC,eAAe,GAAG,KAAK,CAAC;QAC7B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QAEnB,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE;YAEvB,IAAI,IAAI,CAAC,QAAQ,KAAK,EAAE;gBAAE,IAAI,CAAC,QAAQ,IAAI,KAAK,CAAC;YACjD,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;SAEpC;IAEF,CAAC;IAEM,WAAW;QAEjB,OAAO,IAAI,CAAC,QAAQ,CAAC;IAEtB,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,IAAU,EAAW,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC;IAExF,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,IAAI,IAAI,GAAY,KAAK,CAAC;QAE1B,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,eAAe,EAAE;YAEtC,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,EAAE;gBAEhC,IAAI,IAAI;oBAAE,OAAO,KAAK,CAAC;;oBAClB,IAAI,GAAG,IAAI,CAAC;aAEjB;SAED;QAED,OAAO,IAAI,CAAC;IAEb,CAAC;CAED;AArDD,8BAqDC"} |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 6:14 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class ArrayType<E = any> extends Type<E[]> { | ||
| private arrayType: Type; | ||
| public constructor(arrayType: Type<E>, isOptional: boolean = false) { | ||
| super(isOptional); | ||
| this.arrayType = arrayType; | ||
| } | ||
| public getTypeName(): string { | ||
| return "Array<" + this.arrayType.getTypeName() + ">"; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| if (!Array.isArray(input)) return false; | ||
| else { | ||
| let inputArray: any[] = input; | ||
| for (let element of inputArray) { | ||
| if (!this.arrayType.checkConformity(element)) return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return this.checkConformity(input); | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 2:41 PM -- June 14th, 2019. | ||
| * Website: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * A special kind of type that has a predefined/static set of acceptable values. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.1.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class EnumType<E = any> extends Type { | ||
| private typeName: string; | ||
| private acceptableValues: E[]; | ||
| public constructor(acceptableValues: E[], typeName?: string, isOptional: boolean = false) { | ||
| super(isOptional); | ||
| this.acceptableValues = acceptableValues; | ||
| if (typeName !== undefined) this.typeName = typeName; | ||
| else { | ||
| this.typeName = "enum"; | ||
| // TODO [6/14/19 @ 2:50 PM] - Attempt to derive acceptableValue type and iterate over getTypeName or raw value. | ||
| } | ||
| } | ||
| public getTypeName(): string { | ||
| return this.typeName; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return this.acceptableValues.some((value: E): boolean => (value === input)); | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| let once: boolean = false; | ||
| for (let value of this.acceptableValues) { | ||
| if (value === input) { | ||
| if (once) return false; | ||
| else once = true; | ||
| } | ||
| } | ||
| return once; | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 1:12 PM -- June 13th, 2019. | ||
| * Website: typit | ||
| */ | ||
| import { ObjectType } from "./object-type"; | ||
| import * as Merj from "merj"; | ||
| /** | ||
| * A type that combines multiple types into one. | ||
| * | ||
| * For example, an intersection type of the following objects: | ||
| * | ||
| * { "firstName": "John" } | ||
| * | ||
| * { | ||
| * "lastName": "Smith", | ||
| * "age": 26 | ||
| * } | ||
| * | ||
| * { "phone": "(123) 456 - 7890" } | ||
| * | ||
| * Would result in the following object: | ||
| * | ||
| * { | ||
| * "firstName": "John", | ||
| * "lastName": "Smith", | ||
| * "age": 26, | ||
| * "phone": "(123) 456 - 7890" | ||
| * } | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.1.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class IntersectionType extends ObjectType { | ||
| protected typeName: string; | ||
| public constructor(types: ObjectType[], isOptional: boolean = false) { | ||
| super(Merj.merge(types.map((type: ObjectType) => type.getObjectTypeDefinition())), "", isOptional); | ||
| this.typeName = ""; | ||
| for (let type of types) { | ||
| if (this.typeName !== "") this.typeName += " & "; | ||
| this.typeName += type.getTypeName(); | ||
| } | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 6:55 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export interface ObjectTypeDefinition { | ||
| readonly [property: string]: Type | ObjectTypeDefinition; | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 7:30 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { ObjectIterator } from "iter-over"; | ||
| import { Type } from "./type"; | ||
| import { ObjectTypeDefinition } from "./object-type-definition"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class ObjectType extends Type { | ||
| // TODO [5/27/19 @ 12:54 AM] - Need to take into account that some properties might be optional, nullable, or explicitly undefined. | ||
| protected typeName: string; | ||
| protected typeDefinition: ObjectTypeDefinition; | ||
| public constructor(typeDefinition: ObjectTypeDefinition, typeName: string = "", isOptional: boolean = false) { | ||
| super(isOptional); | ||
| this.typeDefinition = typeDefinition; | ||
| this.typeName = typeName; | ||
| } | ||
| public static typeDefinitionToReadableJSON(typeDefinition: ObjectTypeDefinition): any { | ||
| let iterator: ObjectIterator<Type | ObjectTypeDefinition> = new ObjectIterator<Type | ObjectTypeDefinition>(typeDefinition); | ||
| let result: any = {}; | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| if (element.value.getTypeName !== undefined) result[element.key] = (element.value as Type).getTypeName(); | ||
| else result[element.key] = ObjectType.typeDefinitionToReadableJSON(element.value as ObjectTypeDefinition); | ||
| } | ||
| return result; | ||
| } | ||
| public static typeDefinitionToString(typeDefinition: ObjectTypeDefinition): string { | ||
| let structureToStringArray: (struct: ObjectTypeDefinition) => string[] = (struct: ObjectTypeDefinition): string[] => { | ||
| let iterator: ObjectIterator<Type | ObjectTypeDefinition> = new ObjectIterator<Type | ObjectTypeDefinition>(struct); | ||
| let resultLines: string[] = []; | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| if (element.value.getTypeName !== undefined) { | ||
| let typeName: string = (element.value as Type).getTypeName(); | ||
| resultLines.push("| " + element.key + ": " + typeName); | ||
| } else { | ||
| resultLines.push("| " + element.key + ": object \u23ce"); | ||
| let nestedResultLines: string[] = structureToStringArray(element.value as ObjectTypeDefinition); | ||
| for (let line of nestedResultLines) resultLines.push("| " + line); | ||
| } | ||
| } | ||
| return resultLines; | ||
| }; | ||
| return structureToStringArray(typeDefinition).join("\n"); | ||
| } | ||
| public typeDefinitionToReadableJSON(): any { | ||
| return ObjectType.typeDefinitionToReadableJSON(this.typeDefinition); | ||
| } | ||
| public typeDefinitionToString(): string { | ||
| return ObjectType.typeDefinitionToString(this.typeDefinition); | ||
| } | ||
| public getTypeName(): string { | ||
| return "object" + (this.typeName !== "" ? " (" + this.typeName + ")" : ""); | ||
| } | ||
| public getObjectTypeDefinition(): ObjectTypeDefinition { | ||
| return this.typeDefinition; | ||
| } | ||
| public checkConformity(input: any, typeDefinition: ObjectTypeDefinition = this.typeDefinition): boolean { | ||
| if (!(typeof input === "object") || (input === null)) return false; | ||
| let iterator: ObjectIterator<Type | ObjectTypeDefinition> = new ObjectIterator<Type | ObjectTypeDefinition>(typeDefinition); | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| let propertyName: string = element.key; | ||
| let propertyValue: any = input[propertyName]; | ||
| if (propertyValue === undefined) return false; | ||
| if (element.value.getTypeName !== undefined) { | ||
| let type: Type = element.value as Type; | ||
| if (!type.checkConformity(propertyValue)) return false; | ||
| } else { | ||
| if (!this.checkConformity(propertyValue, element.value as ObjectTypeDefinition)) return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| public exhaustivelyCheckConformity(input: any, typeDefinition: ObjectTypeDefinition = this.typeDefinition): boolean { | ||
| if (!this.checkConformity(input, typeDefinition)) return false; | ||
| let clonedInput: any = JSON.parse(JSON.stringify(input)); | ||
| let iterator: ObjectIterator<any> = new ObjectIterator<any>(clonedInput); | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| let propertyName: string = element.key; | ||
| let propertyValue: any = input[propertyName]; | ||
| if (typeDefinition[propertyName] !== undefined) { | ||
| if (typeDefinition[propertyName].getTypeName !== undefined) { | ||
| let type: Type = typeDefinition[propertyName] as Type; | ||
| if (!type.checkConformity(propertyValue)) return false; | ||
| } else { | ||
| if (!this.exhaustivelyCheckConformity(propertyValue, typeDefinition[propertyName] as ObjectTypeDefinition)) return false; | ||
| } | ||
| } else return false; | ||
| } | ||
| return true; | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 12:08 AM -- May 27th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| type Validator = (input: any) => boolean; | ||
| /** | ||
| * An enumeration of certain special types found in JavaScript. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class SpecialType<E> extends Type<E> { | ||
| public static readonly ANY: SpecialType<any> = new SpecialType( | ||
| "any", | ||
| false, | ||
| (input: any): boolean => true | ||
| ); | ||
| public static readonly OPTIONAL_ANY: SpecialType<any> = new SpecialType( | ||
| "any", | ||
| true, | ||
| (input: any): boolean => true | ||
| ); | ||
| public static readonly VOID: SpecialType<void> = new SpecialType( | ||
| "void", | ||
| false, | ||
| (input: any): boolean => false | ||
| ); | ||
| public static readonly OPTIONAL_VOID: SpecialType<void> = new SpecialType( | ||
| "void", | ||
| true, | ||
| (input: any): boolean => false | ||
| ); | ||
| public static readonly UNDEFINED: SpecialType<undefined> = new SpecialType( | ||
| "undefined", | ||
| false, | ||
| (input: any): boolean => input === undefined | ||
| ); | ||
| public static readonly OPTIONAL_UNDEFINED: SpecialType<undefined> = new SpecialType( | ||
| "undefined", | ||
| true, | ||
| (input: any): boolean => input === undefined | ||
| ); | ||
| public static readonly NULL: SpecialType<null> = new SpecialType( | ||
| "null", | ||
| false, | ||
| (input: any): boolean => input === null | ||
| ); | ||
| public static readonly OPTIONAL_NULL: SpecialType<null> = new SpecialType( | ||
| "null", | ||
| true, | ||
| (input: any): boolean => input === null | ||
| ); | ||
| private name: string; | ||
| private validator: Validator; | ||
| protected constructor(name: string, isOptional: boolean, validator: Validator) { | ||
| super(isOptional); | ||
| this.name = name; | ||
| this.validator = validator; | ||
| } | ||
| public getTypeName(): string { | ||
| return this.name; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return this.validator(input); | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return this.checkConformity(input); | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 5:59 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| type Validator = (input: any) => boolean; | ||
| /** | ||
| * An enumeration of the standard types found in JavaScript. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class StandardType<E> extends Type<E> { | ||
| public static readonly NUMBER: StandardType<number> = new StandardType( | ||
| "number", | ||
| false, | ||
| (input: any): boolean => (typeof input === "number") | ||
| ); | ||
| public static readonly OPTIONAL_NUMBER: StandardType<number> = new StandardType( | ||
| "number", | ||
| true, | ||
| (input: any): boolean => (typeof input === "number") | ||
| ); | ||
| public static readonly BOOLEAN: StandardType<boolean> = new StandardType( | ||
| "boolean", | ||
| false, | ||
| (input: any): boolean => (typeof input === "boolean") | ||
| ); | ||
| public static readonly OPTIONAL_BOOLEAN: StandardType<boolean> = new StandardType( | ||
| "boolean", | ||
| true, | ||
| (input: any): boolean => (typeof input === "boolean") | ||
| ); | ||
| public static readonly STRING: StandardType<string> = new StandardType( | ||
| "string", | ||
| false, | ||
| (input: any): boolean => (typeof input === "string") | ||
| ); | ||
| public static readonly OPTIONAL_STRING: StandardType<string> = new StandardType( | ||
| "string", | ||
| true, | ||
| (input: any): boolean => (typeof input === "string") | ||
| ); | ||
| private name: string; | ||
| private validator: Validator; | ||
| protected constructor(name: string, isOptional: boolean, validator: Validator) { | ||
| super(isOptional); | ||
| this.name = name; | ||
| this.validator = validator; | ||
| } | ||
| public getTypeName(): string { | ||
| return this.name; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return this.validator(input); | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return this.checkConformity(input); | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 7:02 PM -- June 13th, 2019. | ||
| * Website: typit | ||
| */ | ||
| import { StandardType } from "../standard-type"; | ||
| import { TEST_VALUES } from "./test-values"; | ||
| /** | ||
| * Tests for the Typit standard types. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.1.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| describe("Number Type", () => { | ||
| test("Number", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.BASIC)).toBeTruthy(); | ||
| }); | ||
| test("Boolean", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.BOOLEAN.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("String", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.STRING.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Undefined", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.SPECIAL.UNDEFINED)).toBeFalsy(); | ||
| }); | ||
| test("Null", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.SPECIAL.NULL)).toBeFalsy(); | ||
| }); | ||
| describe("Special Numeric Values", () => { | ||
| test("Zero", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.ZERO)).toBeTruthy(); | ||
| }); | ||
| test("Positive Infinity", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.POSITIVE_INFINITY)).toBeTruthy(); | ||
| }); | ||
| test("Negative Infinity", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.NEGATIVE_INFINITY)).toBeTruthy(); | ||
| }); | ||
| test("Max Safe Integer", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.MAX_SAFE_INTEGER)).toBeTruthy(); | ||
| }); | ||
| test("Min Safe Integer", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.MIN_SAFE_INTEGER)).toBeTruthy(); | ||
| }); | ||
| test("Max Value", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.MAX_VALUE)).toBeTruthy(); | ||
| }); | ||
| test("Min Value", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.MIN_VALUE)).toBeTruthy(); | ||
| }); | ||
| test("NaN", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.NUMBERS.NAN)).toBeTruthy(); | ||
| }); | ||
| }); | ||
| describe("Special Boolean Values", () => { | ||
| test("True", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.BOOLEAN.TRUE)).toBeFalsy(); | ||
| }); | ||
| test("False", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.BOOLEAN.FALSE)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special String Values", () => { | ||
| test("Empty String", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.STRING.EMPTY)).toBeFalsy(); | ||
| }); | ||
| test("Numeric String", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.STRING.NUMERIC)).toBeFalsy(); | ||
| }); | ||
| test("Symbol String", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.STRING.SYMBOLS)).toBeFalsy(); | ||
| }); | ||
| test("Long String", () => { | ||
| expect(StandardType.NUMBER.checkConformity(TEST_VALUES.STRING.LONG)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("Boolean Type", () => { | ||
| test("Number", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Boolean", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.BOOLEAN.BASIC)).toBeTruthy(); | ||
| }); | ||
| test("String", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.STRING.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Undefined", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.SPECIAL.UNDEFINED)).toBeFalsy(); | ||
| }); | ||
| test("Null", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.SPECIAL.NULL)).toBeFalsy(); | ||
| }); | ||
| describe("Special Numeric Values", () => { | ||
| test("Zero", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.ZERO)).toBeFalsy(); | ||
| }); | ||
| test("Positive Infinity", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.POSITIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Negative Infinity", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.NEGATIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Max Safe Integer", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.MAX_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Min Safe Integer", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.MIN_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Max Value", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.MAX_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("Min Value", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.MIN_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("NaN", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.NUMBERS.NAN)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special Boolean Values", () => { | ||
| test("True", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.BOOLEAN.TRUE)).toBeTruthy(); | ||
| }); | ||
| test("False", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.BOOLEAN.FALSE)).toBeTruthy(); | ||
| }); | ||
| }); | ||
| describe("Special String Values", () => { | ||
| test("Empty String", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.STRING.EMPTY)).toBeFalsy(); | ||
| }); | ||
| test("Numeric String", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.STRING.NUMERIC)).toBeFalsy(); | ||
| }); | ||
| test("Symbol String", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.STRING.SYMBOLS)).toBeFalsy(); | ||
| }); | ||
| test("Long String", () => { | ||
| expect(StandardType.BOOLEAN.checkConformity(TEST_VALUES.STRING.LONG)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| }); | ||
| describe("String Type", () => { | ||
| test("Number", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("Boolean", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.BOOLEAN.BASIC)).toBeFalsy(); | ||
| }); | ||
| test("String", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.STRING.BASIC)).toBeTruthy(); | ||
| }); | ||
| test("Undefined", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.SPECIAL.UNDEFINED)).toBeFalsy(); | ||
| }); | ||
| test("Null", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.SPECIAL.NULL)).toBeFalsy(); | ||
| }); | ||
| describe("Special Numeric Values", () => { | ||
| test("Zero", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.ZERO)).toBeFalsy(); | ||
| }); | ||
| test("Positive Infinity", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.POSITIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Negative Infinity", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.NEGATIVE_INFINITY)).toBeFalsy(); | ||
| }); | ||
| test("Max Safe Integer", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.MAX_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Min Safe Integer", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.MIN_SAFE_INTEGER)).toBeFalsy(); | ||
| }); | ||
| test("Max Value", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.MAX_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("Min Value", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.MIN_VALUE)).toBeFalsy(); | ||
| }); | ||
| test("NaN", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.NUMBERS.NAN)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special Boolean Values", () => { | ||
| test("True", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.BOOLEAN.TRUE)).toBeFalsy(); | ||
| }); | ||
| test("False", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.BOOLEAN.FALSE)).toBeFalsy(); | ||
| }); | ||
| }); | ||
| describe("Special String Values", () => { | ||
| test("Empty String", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.STRING.EMPTY)).toBeTruthy(); | ||
| }); | ||
| test("Numeric String", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.STRING.NUMERIC)).toBeTruthy(); | ||
| }); | ||
| test("Symbol String", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.STRING.SYMBOLS)).toBeTruthy(); | ||
| }); | ||
| test("Long String", () => { | ||
| expect(StandardType.STRING.checkConformity(TEST_VALUES.STRING.LONG)).toBeTruthy(); | ||
| }); | ||
| }); | ||
| }); | ||
| test.todo("Optional Number Type"); | ||
| test.todo("Optional Boolean Type"); | ||
| test.todo("Optional String Type"); |
| export const TEST_VALUES: any = { | ||
| NUMBERS: { | ||
| BASIC: 5, | ||
| ZERO: 0, | ||
| POSITIVE_INFINITY: Number.POSITIVE_INFINITY, | ||
| NEGATIVE_INFINITY: Number.NEGATIVE_INFINITY, | ||
| MIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER, | ||
| MAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER, | ||
| MAX_VALUE: Number.MAX_VALUE, | ||
| MIN_VALUE: Number.MIN_VALUE, | ||
| NAN: Number.NaN | ||
| }, | ||
| BOOLEAN: { | ||
| BASIC: true, | ||
| TRUE: true, | ||
| FALSE: false | ||
| }, | ||
| STRING: { | ||
| BASIC: "string", | ||
| NUMERIC: "1234567890", | ||
| SYMBOLS: "`~!@#$%^&*()_+=-{}|[]\\:\";'<>?,./", | ||
| EMPTY: "", | ||
| LONG: "linasdfiuhnapsdgoim[oinpiubasodifnpasiudbpgoasdnfoimpoipiausdhfoaisdmf[oim[oinpunasfdinapsdoifn[opiasdf[iop98j=09148n3tg-9n-[08jsd[onfpioH" | ||
| }, | ||
| SPECIAL: { | ||
| UNDEFINED: undefined, | ||
| NULL: null | ||
| } | ||
| }; |
+48
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 5:59 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| /** | ||
| * An interface for classes that check for conformity to a given type at runtime. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export abstract class Type<E = any> { | ||
| protected readonly isOptional: boolean; | ||
| protected constructor(isOptional: boolean) { | ||
| this.isOptional = isOptional; | ||
| } | ||
| public getOptionality(): boolean { | ||
| return this.isOptional; | ||
| } | ||
| public abstract getTypeName(): string; | ||
| public abstract checkConformity(input: any): boolean; | ||
| public abstract exhaustivelyCheckConformity(input: any): boolean; | ||
| public sanitize(input: any): E { | ||
| if (this.checkConformity(input)) return input as E; | ||
| else { | ||
| throw new Error("ERR | Attempted to sanitize content that did not match the desired type signature. " + | ||
| "Type of " + input.toString() + "was not '" + this.getTypeName() + "'"); | ||
| } | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 1:15 PM -- June 14th, 2019. | ||
| * Website: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * A type that can be one of a set of types. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.1.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class UnionType<E = any> extends Type<E> { | ||
| protected typeName: string; | ||
| protected acceptableTypes: Type[]; | ||
| public constructor(types: Type[], isOptional: boolean = false) { | ||
| super(isOptional); | ||
| this.acceptableTypes = types; | ||
| this.typeName = ""; | ||
| for (let type of types) { | ||
| if (this.typeName !== "") this.typeName += " | "; | ||
| this.typeName += type.getTypeName(); | ||
| } | ||
| } | ||
| public getTypeName(): string { | ||
| return this.typeName; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return this.acceptableTypes.some((type: Type): boolean => type.checkConformity(input)); | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| let once: boolean = false; | ||
| for (let type of this.acceptableTypes) { | ||
| if (type.checkConformity(input)) { | ||
| if (once) return false; | ||
| else once = true; | ||
| } | ||
| } | ||
| return once; | ||
| } | ||
| } |
@@ -1,5 +0,5 @@ | ||
| import Type from "./type"; | ||
| declare class ArrayType<E = any> extends Type<E[]> { | ||
| import { Type } from "./type"; | ||
| export declare class ArrayType<E = any> extends Type<E[]> { | ||
| private arrayType; | ||
| constructor(arrayType: Type<E>); | ||
| constructor(arrayType: Type<E>, isOptional?: boolean); | ||
| getTypeName(): string; | ||
@@ -9,2 +9,1 @@ checkConformity(input: any): boolean; | ||
| } | ||
| export default ArrayType; |
+9
-7
@@ -1,7 +0,9 @@ | ||
| export { Type } from "./types/type"; | ||
| export { StandardType } from "./types/standard-type"; | ||
| export { SpecialType } from "./types/special-type"; | ||
| export { ArrayType } from "./types/array-type"; | ||
| export { ObjectType } from "./types/object-type"; | ||
| export { ObjectTypeDefinition } from "./types/object-type-definition"; | ||
| export { OptionalType } from "./types/optional-type"; | ||
| export { Type } from "./type"; | ||
| export { StandardType } from "./standard-type"; | ||
| export { SpecialType } from "./special-type"; | ||
| export { ArrayType } from "./array-type"; | ||
| export { ObjectType } from "./object-type"; | ||
| export { ObjectTypeDefinition } from "./object-type-definition"; | ||
| export { EnumType } from "./enum-type"; | ||
| export { IntersectionType, IntersectionType as MultiType, IntersectionType as AndType } from "./intersection-type"; | ||
| export { UnionType, UnionType as OrType } from "./union-type"; |
@@ -1,5 +0,4 @@ | ||
| import Type from "./type"; | ||
| interface ObjectTypeDefinition { | ||
| import { Type } from "./type"; | ||
| export interface ObjectTypeDefinition { | ||
| readonly [property: string]: Type | ObjectTypeDefinition; | ||
| } | ||
| export default ObjectTypeDefinition; |
@@ -1,7 +0,7 @@ | ||
| import Type from "./type"; | ||
| import ObjectTypeDefinition from "./object-type-definition"; | ||
| declare class ObjectType extends Type { | ||
| private readonly objectName; | ||
| private readonly typeDefinition; | ||
| constructor(typeDefinition: ObjectTypeDefinition, objectName?: string); | ||
| import { Type } from "./type"; | ||
| import { ObjectTypeDefinition } from "./object-type-definition"; | ||
| export declare class ObjectType extends Type { | ||
| protected typeName: string; | ||
| protected typeDefinition: ObjectTypeDefinition; | ||
| constructor(typeDefinition: ObjectTypeDefinition, typeName?: string, isOptional?: boolean); | ||
| static typeDefinitionToReadableJSON(typeDefinition: ObjectTypeDefinition): any; | ||
@@ -12,5 +12,5 @@ static typeDefinitionToString(typeDefinition: ObjectTypeDefinition): string; | ||
| getTypeName(): string; | ||
| getObjectTypeDefinition(): ObjectTypeDefinition; | ||
| checkConformity(input: any, typeDefinition?: ObjectTypeDefinition): boolean; | ||
| exhaustivelyCheckConformity(input: any, typeDefinition?: ObjectTypeDefinition): boolean; | ||
| } | ||
| export default ObjectType; |
@@ -1,11 +0,15 @@ | ||
| import Type from "./type"; | ||
| import { Type } from "./type"; | ||
| declare type Validator = (input: any) => boolean; | ||
| declare class SpecialType<E> extends Type<E> { | ||
| export declare class SpecialType<E> extends Type<E> { | ||
| static readonly ANY: SpecialType<any>; | ||
| static readonly OPTIONAL_ANY: SpecialType<any>; | ||
| static readonly VOID: SpecialType<void>; | ||
| static readonly OPTIONAL_VOID: SpecialType<void>; | ||
| static readonly UNDEFINED: SpecialType<undefined>; | ||
| static readonly OPTIONAL_UNDEFINED: SpecialType<undefined>; | ||
| static readonly NULL: SpecialType<null>; | ||
| static readonly OPTIONAL_NULL: SpecialType<null>; | ||
| private name; | ||
| private validator; | ||
| protected constructor(name: string, validator: Validator); | ||
| protected constructor(name: string, isOptional: boolean, validator: Validator); | ||
| getTypeName(): string; | ||
@@ -15,2 +19,2 @@ checkConformity(input: any): boolean; | ||
| } | ||
| export default SpecialType; | ||
| export {}; |
@@ -1,10 +0,13 @@ | ||
| import Type from "./type"; | ||
| import { Type } from "./type"; | ||
| declare type Validator = (input: any) => boolean; | ||
| declare class StandardType<E> extends Type<E> { | ||
| export declare class StandardType<E> extends Type<E> { | ||
| static readonly NUMBER: StandardType<number>; | ||
| static readonly OPTIONAL_NUMBER: StandardType<number>; | ||
| static readonly BOOLEAN: StandardType<boolean>; | ||
| static readonly OPTIONAL_BOOLEAN: StandardType<boolean>; | ||
| static readonly STRING: StandardType<string>; | ||
| static readonly OPTIONAL_STRING: StandardType<string>; | ||
| private name; | ||
| private validator; | ||
| protected constructor(name: string, validator: Validator); | ||
| protected constructor(name: string, isOptional: boolean, validator: Validator); | ||
| getTypeName(): string; | ||
@@ -14,2 +17,2 @@ checkConformity(input: any): boolean; | ||
| } | ||
| export default StandardType; | ||
| export {}; |
+4
-2
@@ -1,2 +0,5 @@ | ||
| declare abstract class Type<E = any> { | ||
| export declare abstract class Type<E = any> { | ||
| protected readonly isOptional: boolean; | ||
| protected constructor(isOptional: boolean); | ||
| getOptionality(): boolean; | ||
| abstract getTypeName(): string; | ||
@@ -7,2 +10,1 @@ abstract checkConformity(input: any): boolean; | ||
| } | ||
| export default Type; |
+5
-8
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = __importDefault(require("./type")); | ||
| class ArrayType extends type_1.default { | ||
| constructor(arrayType) { | ||
| super(); | ||
| const type_1 = require("./type"); | ||
| class ArrayType extends type_1.Type { | ||
| constructor(arrayType, isOptional = false) { | ||
| super(isOptional); | ||
| this.arrayType = arrayType; | ||
@@ -31,3 +28,3 @@ } | ||
| } | ||
| exports.default = ArrayType; | ||
| exports.ArrayType = ArrayType; | ||
| //# sourceMappingURL=array-type.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"array-type.js","sourceRoot":"","sources":["../ts/types/array-type.ts"],"names":[],"mappings":";;;;;AAMA,kDAA0B;AAS1B,MAAM,SAAmB,SAAQ,cAAS;IAIzC,YAAmB,SAAkB;QAEpC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAE5B,CAAC;IAEM,WAAW;QAEjB,OAAO,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC;IAEtD,CAAC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C,CAAC;CAED;AA3CD,8BA2CC"} |
+14
-7
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| var type_1 = require("./types/type"); | ||
| var type_1 = require("./type"); | ||
| exports.Type = type_1.Type; | ||
| var standard_type_1 = require("./types/standard-type"); | ||
| var standard_type_1 = require("./standard-type"); | ||
| exports.StandardType = standard_type_1.StandardType; | ||
| var special_type_1 = require("./types/special-type"); | ||
| var special_type_1 = require("./special-type"); | ||
| exports.SpecialType = special_type_1.SpecialType; | ||
| var array_type_1 = require("./types/array-type"); | ||
| var array_type_1 = require("./array-type"); | ||
| exports.ArrayType = array_type_1.ArrayType; | ||
| var object_type_1 = require("./types/object-type"); | ||
| var object_type_1 = require("./object-type"); | ||
| exports.ObjectType = object_type_1.ObjectType; | ||
| var optional_type_1 = require("./types/optional-type"); | ||
| exports.OptionalType = optional_type_1.OptionalType; | ||
| var enum_type_1 = require("./enum-type"); | ||
| exports.EnumType = enum_type_1.EnumType; | ||
| var intersection_type_1 = require("./intersection-type"); | ||
| exports.IntersectionType = intersection_type_1.IntersectionType; | ||
| exports.MultiType = intersection_type_1.IntersectionType; | ||
| exports.AndType = intersection_type_1.IntersectionType; | ||
| var union_type_1 = require("./union-type"); | ||
| exports.UnionType = union_type_1.UnionType; | ||
| exports.OrType = union_type_1.UnionType; | ||
| //# sourceMappingURL=main.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../ts/main.ts"],"names":[],"mappings":";;AAcA,qCAAwC;AAA/B,sBAAA,IAAI,CAAA;AACb,uDAAuD;AAA9C,uCAAA,YAAY,CAAA;AACrB,qDAAqD;AAA5C,qCAAA,WAAW,CAAA;AACpB,iDAAiD;AAAxC,iCAAA,SAAS,CAAA;AAClB,mDAAmD;AAA1C,mCAAA,UAAU,CAAA;AAEnB,uDAAuD;AAA9C,uCAAA,YAAY,CAAA"} | ||
| {"version":3,"file":"main.js","sourceRoot":"","sources":["../ts/main.ts"],"names":[],"mappings":";;AAcA,+BAA8B;AAArB,sBAAA,IAAI,CAAA;AACb,iDAA+C;AAAtC,uCAAA,YAAY,CAAA;AACrB,+CAA6C;AAApC,qCAAA,WAAW,CAAA;AACpB,2CAAyC;AAAhC,iCAAA,SAAS,CAAA;AAClB,6CAA2C;AAAlC,mCAAA,UAAU,CAAA;AAEnB,yCAAuC;AAA9B,+BAAA,QAAQ,CAAA;AAEjB,yDAI6B;AAH5B,+CAAA,gBAAgB,CAAA;AAChB,wCAAA,gBAAgB,CAAa;AAC7B,sCAAA,gBAAgB,CAAW;AAG5B,2CAGsB;AAFrB,iCAAA,SAAS,CAAA;AACT,8BAAA,SAAS,CAAU"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"object-type-definition.js","sourceRoot":"","sources":["../ts/types/object-type-definition.ts"],"names":[],"mappings":""} | ||
| {"version":3,"file":"object-type-definition.js","sourceRoot":"","sources":["../ts/object-type-definition.ts"],"names":[],"mappings":""} |
+14
-14
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const iter_over_1 = require("iter-over"); | ||
| const type_1 = __importDefault(require("./type")); | ||
| class ObjectType extends type_1.default { | ||
| constructor(typeDefinition, objectName = "") { | ||
| super(); | ||
| const type_1 = require("./type"); | ||
| class ObjectType extends type_1.Type { | ||
| constructor(typeDefinition, typeName = "", isOptional = false) { | ||
| super(isOptional); | ||
| this.typeDefinition = typeDefinition; | ||
| this.objectName = objectName; | ||
| this.typeName = typeName; | ||
| } | ||
| static typeDefinitionToReadableJSON(typeDefinition) { | ||
| let iterator = new iter_over_1.IOObjectIterator(typeDefinition); | ||
| let iterator = new iter_over_1.ObjectIterator(typeDefinition); | ||
| let result = {}; | ||
@@ -29,3 +26,3 @@ for (let element of iterator) { | ||
| let structureToStringArray = (struct) => { | ||
| let iterator = new iter_over_1.IOObjectIterator(struct); | ||
| let iterator = new iter_over_1.ObjectIterator(struct); | ||
| let resultLines = []; | ||
@@ -57,8 +54,11 @@ for (let element of iterator) { | ||
| getTypeName() { | ||
| return "object" + (this.objectName !== "" ? " (" + this.objectName + ")" : ""); | ||
| return "object" + (this.typeName !== "" ? " (" + this.typeName + ")" : ""); | ||
| } | ||
| getObjectTypeDefinition() { | ||
| return this.typeDefinition; | ||
| } | ||
| checkConformity(input, typeDefinition = this.typeDefinition) { | ||
| if (!(typeof input === "object") || (input === null)) | ||
| return false; | ||
| let iterator = new iter_over_1.IOObjectIterator(typeDefinition); | ||
| let iterator = new iter_over_1.ObjectIterator(typeDefinition); | ||
| for (let element of iterator) { | ||
@@ -87,3 +87,3 @@ if (element === undefined) | ||
| let clonedInput = JSON.parse(JSON.stringify(input)); | ||
| let iterator = new iter_over_1.IOObjectIterator(clonedInput); | ||
| let iterator = new iter_over_1.ObjectIterator(clonedInput); | ||
| for (let element of iterator) { | ||
@@ -111,3 +111,3 @@ if (element === undefined) | ||
| } | ||
| exports.default = ObjectType; | ||
| exports.ObjectType = ObjectType; | ||
| //# sourceMappingURL=object-type.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"object-type.js","sourceRoot":"","sources":["../ts/types/object-type.ts"],"names":[],"mappings":";;;;;AAMA,yCAA6C;AAC7C,kDAA0B;AAU1B,MAAM,UAAW,SAAQ,cAAI;IAM5B,YAAmB,cAAoC,EAAE,aAAqB,EAAE;QAE/E,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAE9B,CAAC;IAEM,MAAM,CAAC,4BAA4B,CAAC,cAAoC;QAE9E,IAAI,QAAQ,GAAkD,IAAI,4BAAgB,CAA8B,cAAc,CAAC,CAAC;QAChI,IAAI,MAAM,GAAQ,EAAE,CAAC;QAErB,KAAK,IAAI,OAAO,IAAI,QAAQ,EAAE;YAE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,KAAK,CAAC,YAAY,CAAC,CAAC;YAE7C,IAAI,cAAc,CAAC,YAAY,CAAC,KAAK,SAAS,EAAE;gBAE/C,IAAI,cAAc,CAAC,YAAY,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;oBAE3D,IAAI,IAAI,GAAS,cAAc,CAAC,YAAY,CAAS,CAAC;oBAEtD,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;wBAAE,OAAO,KAAK,CAAC;iBAEvD;qBAAM;oBAEN,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,aAAa,EAAE,cAAc,CAAC,YAAY,CAAyB,CAAC;wBAAE,OAAO,KAAK,CAAC;iBAEzH;aAED;;gBAAM,OAAO,KAAK,CAAC;SAEpB;QAED,OAAO,IAAI,CAAC;IAEb,CAAC;CAED;AArKD,gCAqKC"} |
+13
-12
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = __importDefault(require("./type")); | ||
| class SpecialType extends type_1.default { | ||
| constructor(name, validator) { | ||
| super(); | ||
| const type_1 = require("./type"); | ||
| class SpecialType extends type_1.Type { | ||
| constructor(name, isOptional, validator) { | ||
| super(isOptional); | ||
| this.name = name; | ||
@@ -23,7 +20,11 @@ this.validator = validator; | ||
| } | ||
| SpecialType.ANY = new SpecialType("any", (input) => true); | ||
| SpecialType.VOID = new SpecialType("void", (input) => false); | ||
| SpecialType.UNDEFINED = new SpecialType("undefined", (input) => input === undefined); | ||
| SpecialType.NULL = new SpecialType("null", (input) => input === null); | ||
| exports.default = SpecialType; | ||
| SpecialType.ANY = new SpecialType("any", false, (input) => true); | ||
| SpecialType.OPTIONAL_ANY = new SpecialType("any", true, (input) => true); | ||
| SpecialType.VOID = new SpecialType("void", false, (input) => false); | ||
| SpecialType.OPTIONAL_VOID = new SpecialType("void", true, (input) => false); | ||
| SpecialType.UNDEFINED = new SpecialType("undefined", false, (input) => input === undefined); | ||
| SpecialType.OPTIONAL_UNDEFINED = new SpecialType("undefined", true, (input) => input === undefined); | ||
| SpecialType.NULL = new SpecialType("null", false, (input) => input === null); | ||
| SpecialType.OPTIONAL_NULL = new SpecialType("null", true, (input) => input === null); | ||
| exports.SpecialType = SpecialType; | ||
| //# sourceMappingURL=special-type.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"special-type.js","sourceRoot":"","sources":["../ts/types/special-type.ts"],"names":[],"mappings":";;;;;AAMA,kDAA0B;AAW1B,MAAM,WAAe,SAAQ,cAAO;IA0BnC,YAAsB,IAAY,EAAE,SAAoB;QAEvD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAE5B,CAAC;IAEM,WAAW;QAEjB,OAAO,IAAI,CAAC,IAAI,CAAC;IAElB,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAE9B,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEpC,CAAC;;AAjDsB,eAAG,GAAqB,IAAI,WAAW,CAC7D,KAAK,EACL,CAAC,KAAU,EAAW,EAAE,CAAC,IAAI,CAC7B,CAAC;AAEqB,gBAAI,GAAsB,IAAI,WAAW,CAC/D,MAAM,EACN,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,CAC9B,CAAC;AAEqB,qBAAS,GAA2B,IAAI,WAAW,CACzE,WAAW,EACX,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,SAAS,CAC5C,CAAC;AAEqB,gBAAI,GAAsB,IAAI,WAAW,CAC/D,MAAM,EACN,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,IAAI,CACvC,CAAC;AAmC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AAC,KAAK,KAAK,SAAS,CAC5C,CAAC;AAEqB,gBAAI,GAAsB,IAAI,WAAW,CAC/D,MAAM,EACN,KAAK,EACL,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,IAAI,CACvC,CAAC;AAEqB,yBAAa,GAAsB,IAAI,WAAW,CACxE,MAAM,EACN,IAAI,EACJ,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,IAAI,CACvC,CAAC;AAhDH,kCAiFC"} |
+11
-17
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = __importDefault(require("./type")); | ||
| class StandardType extends type_1.default { | ||
| constructor(name, validator) { | ||
| super(); | ||
| const type_1 = require("./type"); | ||
| class StandardType extends type_1.Type { | ||
| constructor(name, isOptional, validator) { | ||
| super(isOptional); | ||
| this.name = name; | ||
@@ -23,12 +20,9 @@ this.validator = validator; | ||
| } | ||
| StandardType.NUMBER = new StandardType("number", (input) => { | ||
| return ((typeof input === "number") && (!isNaN(input))); | ||
| }); | ||
| StandardType.BOOLEAN = new StandardType("boolean", (input) => { | ||
| return (typeof input === "boolean"); | ||
| }); | ||
| StandardType.STRING = new StandardType("string", (input) => { | ||
| return (typeof input === "string"); | ||
| }); | ||
| exports.default = StandardType; | ||
| StandardType.NUMBER = new StandardType("number", false, (input) => (typeof input === "number")); | ||
| StandardType.OPTIONAL_NUMBER = new StandardType("number", true, (input) => (typeof input === "number")); | ||
| StandardType.BOOLEAN = new StandardType("boolean", false, (input) => (typeof input === "boolean")); | ||
| StandardType.OPTIONAL_BOOLEAN = new StandardType("boolean", true, (input) => (typeof input === "boolean")); | ||
| StandardType.STRING = new StandardType("string", false, (input) => (typeof input === "string")); | ||
| StandardType.OPTIONAL_STRING = new StandardType("string", true, (input) => (typeof input === "string")); | ||
| exports.StandardType = StandardType; | ||
| //# sourceMappingURL=standard-type.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"standard-type.js","sourceRoot":"","sources":["../ts/types/standard-type.ts"],"names":[],"mappings":";;;;;AAMA,kDAA0B;AAW1B,MAAM,YAAgB,SAAQ,cAAO;IAiCpC,YAAsB,IAAY,EAAE,SAAoB;QAEvD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAE5B,CAAC;IAEM,WAAW;QAEjB,OAAO,IAAI,CAAC,IAAI,CAAC;IAElB,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAE9B,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEpC,CAAC;;AAxDsB,mBAAM,GAAyB,IAAI,YAAY,CACrE,QAAQ,EACR,CAAC,KAAU,EAAW,EAAE;IAEvB,OAAO,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzD,CAAC,CACD,CAAC;AAEqB,oBAAO,GAA0B,IAAI,YAAY,CACvE,SAAS,EACT,CAAC,KAAU,EAAW,EAAE;IAEvB,OAAO,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC;AAErC,CAAC,CACD,CAAC;AAEqB,mBAAM,GAAyB,IAAI,YAAY,CACrE,QAAQ,EACR,CAAC,KAAU,EAAW,EAAE;IAEvB,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;AAEpC,CAAC,CACD,CAAC;AAmCH,kBAAe,YAAY,CAAC"} | ||
| {"version":3,"file":"standard-type.js","sourceRoot":"","sources":["../ts/standard-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAW9B,MAAa,YAAgB,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U,EAAW,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CACpD,CAAC;AApCH,oCAqEC"} |
+7
-1
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| class Type { | ||
| constructor(isOptional) { | ||
| this.isOptional = isOptional; | ||
| } | ||
| getOptionality() { | ||
| return this.isOptional; | ||
| } | ||
| sanitize(input) { | ||
@@ -13,3 +19,3 @@ if (this.checkConformity(input)) | ||
| } | ||
| exports.default = Type; | ||
| exports.Type = Type; | ||
| //# sourceMappingURL=type.js.map |
+1
-1
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"type.js","sourceRoot":"","sources":["../ts/types/type.ts"],"names":[],"mappings":";;AAaA,MAAe,IAAI;IAQX,QAAQ,CAAC,KAAU;QAEzB,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,KAAU,CAAC;aAC9C;YAEJ,MAAM,IAAI,KAAK,CAAC,qFAAqF;gBACpG,UAAU,GAAG,KAAK,CAAC,QAAQ,EAAE,GAAG,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,CAAC;SAEzE;IAEF,CAAC;CAED;AAED,kBAAe,IAAI,CAAC"} | ||
| {"version":3,"file":"type.js","sourceRoot":"","sources":["../ts/type.ts"],"names":[],"mappings":";;AAaA,MAAsB,IAAI;IAIzB,YAAsB,UAAmB;QAExC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAE9B,CAAC;IAEM,cAAc;QAEpB,OAAO,IAAI,CAAC,UAAU,CAAC;IAExB,CAAC;IAQM,QAAQ,CAAC,KAAU;QAEzB,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,KAAU,CAAC;aAC9C;YAEJ,MAAM,IAAI,KAAK,CAAC,qFAAqF;gBACpG,UAAU,GAAG,KAAK,CAAC,QAAQ,EAAE,GAAG,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,CAAC;SAEzE;IAEF,CAAC;CAED;AAlCD,oBAkCC"} |
+10
-3
| { | ||
| "name": "typit", | ||
| "version": "0.3.0", | ||
| "version": "0.4.0", | ||
| "description": "Fully recursive runtime typechecking.", | ||
@@ -8,3 +8,5 @@ "main": "js/main", | ||
| "scripts": { | ||
| "build": "rm -rf .d.ts/ js/ && tsc -p ts/tsconfig.json" | ||
| "build": "rm -rf .d.ts/ js/ && tsc -p ts/tsconfig.json", | ||
| "main": "node js/main", | ||
| "test": "jest" | ||
| }, | ||
@@ -29,4 +31,9 @@ "repository": { | ||
| "dependencies": { | ||
| "iter-over": "^1.0.2" | ||
| "iter-over": "^1.1.1", | ||
| "merj": "^0.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/jest": "^24.0.14", | ||
| "jest": "^24.8.0" | ||
| } | ||
| } |
+18
-7
@@ -15,8 +15,19 @@ /* | ||
| export { Type } from "./types/type"; | ||
| export { StandardType } from "./types/standard-type"; | ||
| export { SpecialType } from "./types/special-type"; | ||
| export { ArrayType } from "./types/array-type"; | ||
| export { ObjectType } from "./types/object-type"; | ||
| export { ObjectTypeDefinition } from "./types/object-type-definition"; | ||
| export { OptionalType } from "./types/optional-type"; | ||
| export { Type } from "./type"; | ||
| export { StandardType } from "./standard-type"; | ||
| export { SpecialType } from "./special-type"; | ||
| export { ArrayType } from "./array-type"; | ||
| export { ObjectType } from "./object-type"; | ||
| export { ObjectTypeDefinition } from "./object-type-definition"; | ||
| export { EnumType } from "./enum-type"; | ||
| export { | ||
| IntersectionType, | ||
| IntersectionType as MultiType, | ||
| IntersectionType as AndType | ||
| } from "./intersection-type"; | ||
| export { | ||
| UnionType, | ||
| UnionType as OrType | ||
| } from "./union-type"; |
| import Type from "./type"; | ||
| declare class OptionalType<T extends Type<E>, E = any> extends Type<E> { | ||
| private optionalType; | ||
| constructor(optionalType: Type<E>); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } | ||
| export default OptionalType; |
| import { Type } from "./type"; | ||
| export declare class ArrayType<E = any> extends Type<E[]> { | ||
| private arrayType; | ||
| constructor(arrayType: Type<E>); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } |
| import { Type } from "./type"; | ||
| export interface ObjectTypeDefinition { | ||
| readonly [property: string]: Type | ObjectTypeDefinition; | ||
| } |
| import { Type } from "./type"; | ||
| import { ObjectTypeDefinition } from "./object-type-definition"; | ||
| export declare class ObjectType extends Type { | ||
| private readonly objectName; | ||
| private readonly typeDefinition; | ||
| constructor(typeDefinition: ObjectTypeDefinition, objectName?: string); | ||
| static typeDefinitionToReadableJSON(typeDefinition: ObjectTypeDefinition): any; | ||
| static typeDefinitionToString(typeDefinition: ObjectTypeDefinition): string; | ||
| typeDefinitionToReadableJSON(): any; | ||
| typeDefinitionToString(): string; | ||
| getTypeName(): string; | ||
| checkConformity(input: any, typeDefinition?: ObjectTypeDefinition): boolean; | ||
| exhaustivelyCheckConformity(input: any, typeDefinition?: ObjectTypeDefinition): boolean; | ||
| } |
| import { Type } from "./type"; | ||
| export declare class OptionalType<T extends Type<E>, E = any> extends Type<E> { | ||
| private optionalType; | ||
| constructor(optionalType: Type<E>); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } |
| import { Type } from "./type"; | ||
| declare type Validator = (input: any) => boolean; | ||
| export declare class SpecialType<E> extends Type<E> { | ||
| static readonly ANY: SpecialType<any>; | ||
| static readonly VOID: SpecialType<void>; | ||
| static readonly UNDEFINED: SpecialType<undefined>; | ||
| static readonly NULL: SpecialType<null>; | ||
| private name; | ||
| private validator; | ||
| protected constructor(name: string, validator: Validator); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } | ||
| export {}; |
| import { Type } from "./type"; | ||
| declare type Validator = (input: any) => boolean; | ||
| export declare class StandardType<E> extends Type<E> { | ||
| static readonly NUMBER: StandardType<number>; | ||
| static readonly BOOLEAN: StandardType<boolean>; | ||
| static readonly STRING: StandardType<string>; | ||
| private name; | ||
| private validator; | ||
| protected constructor(name: string, validator: Validator); | ||
| getTypeName(): string; | ||
| checkConformity(input: any): boolean; | ||
| exhaustivelyCheckConformity(input: any): boolean; | ||
| } | ||
| export {}; |
| export declare abstract class Type<E = any> { | ||
| abstract getTypeName(): string; | ||
| abstract checkConformity(input: any): boolean; | ||
| abstract exhaustivelyCheckConformity(input: any): boolean; | ||
| sanitize(input: any): E; | ||
| } |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = __importDefault(require("./type")); | ||
| class OptionalType extends type_1.default { | ||
| constructor(optionalType) { | ||
| super(); | ||
| this.optionalType = optionalType; | ||
| } | ||
| getTypeName() { | ||
| return "optional " + this.optionalType.getTypeName(); | ||
| } | ||
| checkConformity(input) { | ||
| return false; | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| return false; | ||
| } | ||
| } | ||
| exports.default = OptionalType; | ||
| //# sourceMappingURL=optional-type.js.map |
| {"version":3,"file":"optional-type.js","sourceRoot":"","sources":["../ts/types/optional-type.ts"],"names":[],"mappings":";;;;;AAMA,kDAA0B;AAS1B,MAAM,YAAyC,SAAQ,cAAO;IAI7D,YAAmB,YAAqB;QAEvC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IAElC,CAAC;IAEM,WAAW;QAEjB,OAAO,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAEtD,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,KAAK,CAAC;IAEd,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,KAAK,CAAC;IAEd,CAAC;CAED;AAED,kBAAe,YAAY,CAAC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = require("./type"); | ||
| class ArrayType extends type_1.Type { | ||
| constructor(arrayType) { | ||
| super(); | ||
| this.arrayType = arrayType; | ||
| } | ||
| getTypeName() { | ||
| return "Array<" + this.arrayType.getTypeName() + ">"; | ||
| } | ||
| checkConformity(input) { | ||
| if (!Array.isArray(input)) | ||
| return false; | ||
| else { | ||
| let inputArray = input; | ||
| for (let element of inputArray) { | ||
| if (!this.arrayType.checkConformity(element)) | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| return this.checkConformity(input); | ||
| } | ||
| } | ||
| exports.ArrayType = ArrayType; | ||
| //# sourceMappingURL=array-type.js.map |
| {"version":3,"file":"array-type.js","sourceRoot":"","sources":["../../ts/types/array-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAS9B,MAAa,SAAmB,SAAQ,WAAS;IAIhD,YAAmB,SAAkB;QAEpC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAE5B,CAAC;IAEM,WAAW;QAEjB,OAAO,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC;IAEtD,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;aACnC;YAEJ,IAAI,UAAU,GAAU,KAAK,CAAC;YAE9B,KAAK,IAAI,OAAO,IAAI,UAAU,EAAE;gBAE/B,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC;oBAAE,OAAO,KAAK,CAAC;aAE3D;SAED;QAED,OAAO,IAAI,CAAC;IAEb,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEpC,CAAC;CAED;AA3CD,8BA2CC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| //# sourceMappingURL=object-type-definition.js.map |
| {"version":3,"file":"object-type-definition.js","sourceRoot":"","sources":["../../ts/types/object-type-definition.ts"],"names":[],"mappings":""} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const iter_over_1 = require("iter-over"); | ||
| const type_1 = require("./type"); | ||
| class ObjectType extends type_1.Type { | ||
| constructor(typeDefinition, objectName = "") { | ||
| super(); | ||
| this.typeDefinition = typeDefinition; | ||
| this.objectName = objectName; | ||
| } | ||
| static typeDefinitionToReadableJSON(typeDefinition) { | ||
| let iterator = new iter_over_1.IOObjectIterator(typeDefinition); | ||
| let result = {}; | ||
| for (let element of iterator) { | ||
| if (element === undefined) | ||
| throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| if (element.value.getTypeName !== undefined) | ||
| result[element.key] = element.value.getTypeName(); | ||
| else | ||
| result[element.key] = ObjectType.typeDefinitionToReadableJSON(element.value); | ||
| } | ||
| return result; | ||
| } | ||
| static typeDefinitionToString(typeDefinition) { | ||
| let structureToStringArray = (struct) => { | ||
| let iterator = new iter_over_1.IOObjectIterator(struct); | ||
| let resultLines = []; | ||
| for (let element of iterator) { | ||
| if (element === undefined) | ||
| throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| if (element.value.getTypeName !== undefined) { | ||
| let typeName = element.value.getTypeName(); | ||
| resultLines.push("| " + element.key + ": " + typeName); | ||
| } | ||
| else { | ||
| resultLines.push("| " + element.key + ": object \u23ce"); | ||
| let nestedResultLines = structureToStringArray(element.value); | ||
| for (let line of nestedResultLines) | ||
| resultLines.push("| " + line); | ||
| } | ||
| } | ||
| return resultLines; | ||
| }; | ||
| return structureToStringArray(typeDefinition).join("\n"); | ||
| } | ||
| typeDefinitionToReadableJSON() { | ||
| return ObjectType.typeDefinitionToReadableJSON(this.typeDefinition); | ||
| } | ||
| typeDefinitionToString() { | ||
| return ObjectType.typeDefinitionToString(this.typeDefinition); | ||
| } | ||
| getTypeName() { | ||
| return "object" + (this.objectName !== "" ? " (" + this.objectName + ")" : ""); | ||
| } | ||
| checkConformity(input, typeDefinition = this.typeDefinition) { | ||
| if (!(typeof input === "object") || (input === null)) | ||
| return false; | ||
| let iterator = new iter_over_1.IOObjectIterator(typeDefinition); | ||
| for (let element of iterator) { | ||
| if (element === undefined) | ||
| throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| let propertyName = element.key; | ||
| let propertyValue = input[propertyName]; | ||
| if (propertyValue === undefined) | ||
| return false; | ||
| if (element.value.getTypeName !== undefined) { | ||
| let type = element.value; | ||
| if (!type.checkConformity(propertyValue)) | ||
| return false; | ||
| } | ||
| else { | ||
| if (!this.checkConformity(propertyValue, element.value)) | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| exhaustivelyCheckConformity(input, typeDefinition = this.typeDefinition) { | ||
| if (!this.checkConformity(input, typeDefinition)) | ||
| return false; | ||
| let clonedInput = JSON.parse(JSON.stringify(input)); | ||
| let iterator = new iter_over_1.IOObjectIterator(clonedInput); | ||
| for (let element of iterator) { | ||
| if (element === undefined) | ||
| throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| let propertyName = element.key; | ||
| let propertyValue = input[propertyName]; | ||
| if (typeDefinition[propertyName] !== undefined) { | ||
| if (typeDefinition[propertyName].getTypeName !== undefined) { | ||
| let type = typeDefinition[propertyName]; | ||
| if (!type.checkConformity(propertyValue)) | ||
| return false; | ||
| } | ||
| else { | ||
| if (!this.exhaustivelyCheckConformity(propertyValue, typeDefinition[propertyName])) | ||
| return false; | ||
| } | ||
| } | ||
| else | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
| exports.ObjectType = ObjectType; | ||
| //# sourceMappingURL=object-type.js.map |
| {"version":3,"file":"object-type.js","sourceRoot":"","sources":["../../ts/types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,CAAC,CAAC,WAAW,KAAK,SAAS,EAAE;oBAE3D,IAAI,IAAI,GAAS,cAAc,CAAC,YAAY,CAAS,CAAC;oBAEtD,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;wBAAE,OAAO,KAAK,CAAC;iBAEvD;qBAAM;oBAEN,IAAI,CAAC,IAAI,CAAC,2BAA2B,CAAC,aAAa,EAAE,cAAc,CAAC,YAAY,CAAyB,CAAC;wBAAE,OAAO,KAAK,CAAC;iBAEzH;aAED;;gBAAM,OAAO,KAAK,CAAC;SAEpB;QAED,OAAO,IAAI,CAAC;IAEb,CAAC;CAED;AA/JD,gCA+JC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = require("./type"); | ||
| class OptionalType extends type_1.Type { | ||
| constructor(optionalType) { | ||
| super(); | ||
| this.optionalType = optionalType; | ||
| } | ||
| getTypeName() { | ||
| return "optional " + this.optionalType.getTypeName(); | ||
| } | ||
| checkConformity(input) { | ||
| return false; | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| return false; | ||
| } | ||
| } | ||
| exports.OptionalType = OptionalType; | ||
| //# sourceMappingURL=optional-type.js.map |
| {"version":3,"file":"optional-type.js","sourceRoot":"","sources":["../../ts/types/optional-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAS9B,MAAa,YAAyC,SAAQ,WAAO;IAIpE,YAAmB,YAAqB;QAEvC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IAElC,CAAC;IAEM,WAAW;QAEjB,OAAO,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;IAEtD,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,KAAK,CAAC;IAEd,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,KAAK,CAAC;IAEd,CAAC;CAED;AA9BD,oCA8BC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = require("./type"); | ||
| class SpecialType extends type_1.Type { | ||
| constructor(name, validator) { | ||
| super(); | ||
| this.name = name; | ||
| this.validator = validator; | ||
| } | ||
| getTypeName() { | ||
| return this.name; | ||
| } | ||
| checkConformity(input) { | ||
| return this.validator(input); | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| return this.checkConformity(input); | ||
| } | ||
| } | ||
| SpecialType.ANY = new SpecialType("any", (input) => true); | ||
| SpecialType.VOID = new SpecialType("void", (input) => false); | ||
| SpecialType.UNDEFINED = new SpecialType("undefined", (input) => input === undefined); | ||
| SpecialType.NULL = new SpecialType("null", (input) => input === null); | ||
| exports.SpecialType = SpecialType; | ||
| //# sourceMappingURL=special-type.js.map |
| {"version":3,"file":"special-type.js","sourceRoot":"","sources":["../../ts/types/special-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAW9B,MAAa,WAAe,SAAQ,WAAO;IA0B1C,YAAsB,IAAY,EAAE,SAAoB;QAEvD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAE5B,CAAC;IAEM,WAAW;QAEjB,OAAO,IAAI,CAAC,IAAI,CAAC;IAElB,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAE9B,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEpC,CAAC;;AAjDsB,eAAG,GAAqB,IAAI,WAAW,CAC7D,KAAK,EACL,CAAC,KAAU,EAAW,EAAE,CAAC,IAAI,CAC7B,CAAC;AAEqB,gBAAI,GAAsB,IAAI,WAAW,CAC/D,MAAM,EACN,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,CAC9B,CAAC;AAEqB,qBAAS,GAA2B,IAAI,WAAW,CACzE,WAAW,EACX,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,SAAS,CAC5C,CAAC;AAEqB,gBAAI,GAAsB,IAAI,WAAW,CAC/D,MAAM,EACN,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,IAAI,CACvC,CAAC;AApBH,kCAqDC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const type_1 = require("./type"); | ||
| class StandardType extends type_1.Type { | ||
| constructor(name, validator) { | ||
| super(); | ||
| this.name = name; | ||
| this.validator = validator; | ||
| } | ||
| getTypeName() { | ||
| return this.name; | ||
| } | ||
| checkConformity(input) { | ||
| return this.validator(input); | ||
| } | ||
| exhaustivelyCheckConformity(input) { | ||
| return this.checkConformity(input); | ||
| } | ||
| } | ||
| StandardType.NUMBER = new StandardType("number", (input) => { | ||
| return ((typeof input === "number") && (!isNaN(input))); | ||
| }); | ||
| StandardType.BOOLEAN = new StandardType("boolean", (input) => { | ||
| return (typeof input === "boolean"); | ||
| }); | ||
| StandardType.STRING = new StandardType("string", (input) => { | ||
| return (typeof input === "string"); | ||
| }); | ||
| exports.StandardType = StandardType; | ||
| //# sourceMappingURL=standard-type.js.map |
| {"version":3,"file":"standard-type.js","sourceRoot":"","sources":["../../ts/types/standard-type.ts"],"names":[],"mappings":";;AAMA,iCAA8B;AAW9B,MAAa,YAAgB,SAAQ,WAAO;IAiC3C,YAAsB,IAAY,EAAE,SAAoB;QAEvD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAE5B,CAAC;IAEM,WAAW;QAEjB,OAAO,IAAI,CAAC,IAAI,CAAC;IAElB,CAAC;IAEM,eAAe,CAAC,KAAU;QAEhC,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAE9B,CAAC;IAEM,2BAA2B,CAAC,KAAU;QAE5C,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAEpC,CAAC;;AAxDsB,mBAAM,GAAyB,IAAI,YAAY,CACrE,QAAQ,EACR,CAAC,KAAU,EAAW,EAAE;IAEvB,OAAO,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEzD,CAAC,CACD,CAAC;AAEqB,oBAAO,GAA0B,IAAI,YAAY,CACvE,SAAS,EACT,CAAC,KAAU,EAAW,EAAE;IAEvB,OAAO,CAAC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC;AAErC,CAAC,CACD,CAAC;AAEqB,mBAAM,GAAyB,IAAI,YAAY,CACrE,QAAQ,EACR,CAAC,KAAU,EAAW,EAAE;IAEvB,OAAO,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC;AAEpC,CAAC,CACD,CAAC;AA3BH,oCA4DC"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| class Type { | ||
| sanitize(input) { | ||
| if (this.checkConformity(input)) | ||
| return input; | ||
| else { | ||
| throw new Error("ERR | Attempted to sanitize content that did not match the desired type signature. " + | ||
| "Type of " + input.toString() + "was not '" + this.getTypeName() + "'"); | ||
| } | ||
| } | ||
| } | ||
| exports.Type = Type; | ||
| //# sourceMappingURL=type.js.map |
| {"version":3,"file":"type.js","sourceRoot":"","sources":["../../ts/types/type.ts"],"names":[],"mappings":";;AAaA,MAAsB,IAAI;IAQlB,QAAQ,CAAC,KAAU;QAEzB,IAAI,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC;YAAE,OAAO,KAAU,CAAC;aAC9C;YAEJ,MAAM,IAAI,KAAK,CAAC,qFAAqF;gBACpG,UAAU,GAAG,KAAK,CAAC,QAAQ,EAAE,GAAG,WAAW,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,CAAC;SAEzE;IAEF,CAAC;CAED;AApBD,oBAoBC"} |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 6:14 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class ArrayType<E = any> extends Type<E[]> { | ||
| private arrayType: Type; | ||
| public constructor(arrayType: Type<E>) { | ||
| super(); | ||
| this.arrayType = arrayType; | ||
| } | ||
| public getTypeName(): string { | ||
| return "Array<" + this.arrayType.getTypeName() + ">"; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| if (!Array.isArray(input)) return false; | ||
| else { | ||
| let inputArray: any[] = input; | ||
| for (let element of inputArray) { | ||
| if (!this.arrayType.checkConformity(element)) return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return this.checkConformity(input); | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 6:55 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export interface ObjectTypeDefinition { | ||
| readonly [property: string]: Type | ObjectTypeDefinition; | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 7:30 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { IOObjectIterator } from "iter-over"; | ||
| import { Type } from "./type"; | ||
| import { ObjectTypeDefinition } from "./object-type-definition"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class ObjectType extends Type { | ||
| private readonly objectName: string; | ||
| private readonly typeDefinition: ObjectTypeDefinition; | ||
| public constructor(typeDefinition: ObjectTypeDefinition, objectName: string = "") { | ||
| super(); | ||
| this.typeDefinition = typeDefinition; | ||
| this.objectName = objectName; | ||
| } | ||
| public static typeDefinitionToReadableJSON(typeDefinition: ObjectTypeDefinition): any { | ||
| let iterator: IOObjectIterator<Type | ObjectTypeDefinition> = new IOObjectIterator<Type | ObjectTypeDefinition>(typeDefinition); | ||
| let result: any = {}; | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| if (element.value.getTypeName !== undefined) result[element.key] = (element.value as Type).getTypeName(); | ||
| else result[element.key] = ObjectType.typeDefinitionToReadableJSON(element.value as ObjectTypeDefinition); | ||
| } | ||
| return result; | ||
| } | ||
| public static typeDefinitionToString(typeDefinition: ObjectTypeDefinition): string { | ||
| let structureToStringArray: (struct: ObjectTypeDefinition) => string[] = (struct: ObjectTypeDefinition): string[] => { | ||
| let iterator: IOObjectIterator<Type | ObjectTypeDefinition> = new IOObjectIterator<Type | ObjectTypeDefinition>(struct); | ||
| let resultLines: string[] = []; | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| if (element.value.getTypeName !== undefined) { | ||
| let typeName: string = (element.value as Type).getTypeName(); | ||
| resultLines.push("| " + element.key + ": " + typeName); | ||
| } else { | ||
| resultLines.push("| " + element.key + ": object \u23ce"); | ||
| let nestedResultLines: string[] = structureToStringArray(element.value as ObjectTypeDefinition); | ||
| for (let line of nestedResultLines) resultLines.push("| " + line); | ||
| } | ||
| } | ||
| return resultLines; | ||
| }; | ||
| return structureToStringArray(typeDefinition).join("\n"); | ||
| } | ||
| public typeDefinitionToReadableJSON(): any { | ||
| return ObjectType.typeDefinitionToReadableJSON(this.typeDefinition); | ||
| } | ||
| public typeDefinitionToString(): string { | ||
| return ObjectType.typeDefinitionToString(this.typeDefinition); | ||
| } | ||
| public getTypeName(): string { | ||
| return "object" + (this.objectName !== "" ? " (" + this.objectName + ")" : ""); | ||
| } | ||
| // TODO [5/27/19 @ 12:54 AM] - Need to take into account that some properties might be optional, nullable, or explicitly undefined. | ||
| public checkConformity(input: any, typeDefinition: ObjectTypeDefinition = this.typeDefinition): boolean { | ||
| if (!(typeof input === "object") || (input === null)) return false; | ||
| let iterator: IOObjectIterator<Type | ObjectTypeDefinition> = new IOObjectIterator<Type | ObjectTypeDefinition>(typeDefinition); | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| let propertyName: string = element.key; | ||
| let propertyValue: any = input[propertyName]; | ||
| if (propertyValue === undefined) return false; | ||
| if (element.value.getTypeName !== undefined) { | ||
| let type: Type = element.value as Type; | ||
| if (!type.checkConformity(propertyValue)) return false; | ||
| } else { | ||
| if (!this.checkConformity(propertyValue, element.value as ObjectTypeDefinition)) return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| public exhaustivelyCheckConformity(input: any, typeDefinition: ObjectTypeDefinition = this.typeDefinition): boolean { | ||
| if (!this.checkConformity(input, typeDefinition)) return false; | ||
| let clonedInput: any = JSON.parse(JSON.stringify(input)); | ||
| let iterator: IOObjectIterator<any> = new IOObjectIterator<any>(clonedInput); | ||
| for (let element of iterator) { | ||
| if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
| let propertyName: string = element.key; | ||
| let propertyValue: any = input[propertyName]; | ||
| if (typeDefinition[propertyName] !== undefined) { | ||
| if (typeDefinition[propertyName].getTypeName !== undefined) { | ||
| let type: Type = typeDefinition[propertyName] as Type; | ||
| if (!type.checkConformity(propertyValue)) return false; | ||
| } else { | ||
| if (!this.exhaustivelyCheckConformity(propertyValue, typeDefinition[propertyName] as ObjectTypeDefinition)) return false; | ||
| } | ||
| } else return false; | ||
| } | ||
| return true; | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 12:23 AM -- May 27th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| /** | ||
| * | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class OptionalType<T extends Type<E>, E = any> extends Type<E> { | ||
| private optionalType: Type<E>; | ||
| public constructor(optionalType: Type<E>) { | ||
| super(); | ||
| this.optionalType = optionalType; | ||
| } | ||
| public getTypeName(): string { | ||
| return "optional " + this.optionalType.getTypeName(); | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return false; | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return false; | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 12:08 AM -- May 27th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| type Validator = (input: any) => boolean; | ||
| /** | ||
| * An enumeration of certain special types found in JavaScript. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class SpecialType<E> extends Type<E> { | ||
| public static readonly ANY: SpecialType<any> = new SpecialType( | ||
| "any", | ||
| (input: any): boolean => true | ||
| ); | ||
| public static readonly VOID: SpecialType<void> = new SpecialType( | ||
| "void", | ||
| (input: any): boolean => false | ||
| ); | ||
| public static readonly UNDEFINED: SpecialType<undefined> = new SpecialType( | ||
| "undefined", | ||
| (input: any): boolean => input === undefined | ||
| ); | ||
| public static readonly NULL: SpecialType<null> = new SpecialType( | ||
| "null", | ||
| (input: any): boolean => input === null | ||
| ); | ||
| private name: string; | ||
| private validator: Validator; | ||
| protected constructor(name: string, validator: Validator) { | ||
| super(); | ||
| this.name = name; | ||
| this.validator = validator; | ||
| } | ||
| public getTypeName(): string { | ||
| return this.name; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return this.validator(input); | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return this.checkConformity(input); | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 5:59 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| import { Type } from "./type"; | ||
| type Validator = (input: any) => boolean; | ||
| /** | ||
| * An enumeration of the standard types found in JavaScript. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export class StandardType<E> extends Type<E> { | ||
| public static readonly NUMBER: StandardType<number> = new StandardType( | ||
| "number", | ||
| (input: any): boolean => { | ||
| return ((typeof input === "number") && (!isNaN(input))); | ||
| } | ||
| ); | ||
| public static readonly BOOLEAN: StandardType<boolean> = new StandardType( | ||
| "boolean", | ||
| (input: any): boolean => { | ||
| return (typeof input === "boolean"); | ||
| } | ||
| ); | ||
| public static readonly STRING: StandardType<string> = new StandardType( | ||
| "string", | ||
| (input: any): boolean => { | ||
| return (typeof input === "string"); | ||
| } | ||
| ); | ||
| private name: string; | ||
| private validator: Validator; | ||
| protected constructor(name: string, validator: Validator) { | ||
| super(); | ||
| this.name = name; | ||
| this.validator = validator; | ||
| } | ||
| public getTypeName(): string { | ||
| return this.name; | ||
| } | ||
| public checkConformity(input: any): boolean { | ||
| return this.validator(input); | ||
| } | ||
| public exhaustivelyCheckConformity(input: any): boolean { | ||
| return this.checkConformity(input); | ||
| } | ||
| } |
| /* | ||
| * Created by Trevor Sears <trevorsears.main@gmail.com>. | ||
| * 5:59 PM -- May 26th, 2019. | ||
| * Project: typit | ||
| */ | ||
| /** | ||
| * An interface for classes that check for conformity to a given type at runtime. | ||
| * | ||
| * @author Trevor Sears <trevorsears.main@gmail.com> | ||
| * @version v0.3.0 | ||
| * @since v0.1.0 | ||
| */ | ||
| export abstract class Type<E = any> { | ||
| public abstract getTypeName(): string; | ||
| public abstract checkConformity(input: any): boolean; | ||
| public abstract exhaustivelyCheckConformity(input: any): boolean; | ||
| public sanitize(input: any): E { | ||
| if (this.checkConformity(input)) return input as E; | ||
| else { | ||
| throw new Error("ERR | Attempted to sanitize content that did not match the desired type signature. " + | ||
| "Type of " + input.toString() + "was not '" + this.getTypeName() + "'"); | ||
| } | ||
| } | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
119578
36.13%1545
57.98%2
100%2
Infinity%53
-7.02%1
Infinity%+ Added
+ Added
Updated