Socket
Socket
Sign inDemoInstall

typit

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

typit - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

.d.ts/enum-type.d.ts

7

.d.ts/array-type.d.ts

@@ -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;

@@ -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 {};

@@ -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;
"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
"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
"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
"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
"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
"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
{
"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"
}
}

@@ -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";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc