Comparing version 0.4.0 to 0.5.0
import { Type } from "./type"; | ||
export declare class ArrayType<E = any> extends Type<E[]> { | ||
private arrayType; | ||
constructor(arrayType: Type<E>, isOptional?: boolean); | ||
protected arrayType: Type; | ||
constructor(arrayType?: Type<E>, isOptional?: boolean); | ||
getTypeName(): string; | ||
@@ -6,0 +6,0 @@ checkConformity(input: any): boolean; |
import { Type } from "./type"; | ||
export declare class EnumType<E = any> extends Type { | ||
private typeName; | ||
private acceptableValues; | ||
protected typeName: string; | ||
protected acceptableValues: E[]; | ||
constructor(acceptableValues: E[], typeName?: string, isOptional?: boolean); | ||
@@ -6,0 +6,0 @@ getTypeName(): string; |
import { ObjectType } from "./object-type"; | ||
export declare class IntersectionType extends ObjectType { | ||
protected typeName: string; | ||
constructor(types: ObjectType[], isOptional?: boolean); | ||
} |
import { Type } from "./type"; | ||
import { ObjectTypeDefinition } from "./object-type-definition"; | ||
export declare class ObjectType extends Type { | ||
protected typeName: string; | ||
protected typeName: string | undefined; | ||
protected typeDefinition: ObjectTypeDefinition; | ||
constructor(typeDefinition: ObjectTypeDefinition, typeName?: string, isOptional?: boolean); | ||
constructor(typeDefinition?: ObjectTypeDefinition, typeName?: string, isOptional?: boolean); | ||
static typeDefinitionToReadableJSON(typeDefinition: ObjectTypeDefinition): any; | ||
@@ -8,0 +8,0 @@ static typeDefinitionToString(typeDefinition: ObjectTypeDefinition): string; |
@@ -12,4 +12,4 @@ import { Type } from "./type"; | ||
static readonly OPTIONAL_NULL: SpecialType<null>; | ||
private name; | ||
private validator; | ||
protected typeName: string; | ||
protected validator: Validator; | ||
protected constructor(name: string, isOptional: boolean, validator: Validator); | ||
@@ -16,0 +16,0 @@ getTypeName(): string; |
@@ -10,4 +10,4 @@ import { Type } from "./type"; | ||
static readonly OPTIONAL_STRING: StandardType<string>; | ||
private name; | ||
private validator; | ||
protected typeName: string; | ||
protected validator: Validator; | ||
protected constructor(name: string, isOptional: boolean, validator: Validator); | ||
@@ -14,0 +14,0 @@ getTypeName(): string; |
export declare abstract class Type<E = any> { | ||
protected readonly isOptional: boolean; | ||
protected optional: boolean; | ||
protected constructor(isOptional: boolean); | ||
getOptionality(): boolean; | ||
isOptional(): boolean; | ||
abstract getTypeName(): string; | ||
@@ -6,0 +6,0 @@ abstract checkConformity(input: any): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const type_1 = require("./type"); | ||
const special_type_1 = require("./special-type"); | ||
class ArrayType extends type_1.Type { | ||
constructor(arrayType, isOptional = false) { | ||
constructor(arrayType = special_type_1.SpecialType.ANY, isOptional = false) { | ||
super(isOptional); | ||
@@ -7,0 +8,0 @@ this.arrayType = arrayType; |
@@ -6,3 +6,3 @@ "use strict"; | ||
class ObjectType extends type_1.Type { | ||
constructor(typeDefinition, typeName = "", isOptional = false) { | ||
constructor(typeDefinition = {}, typeName, isOptional = false) { | ||
super(isOptional); | ||
@@ -54,3 +54,3 @@ this.typeDefinition = typeDefinition; | ||
getTypeName() { | ||
return "object" + (this.typeName !== "" ? " (" + this.typeName + ")" : ""); | ||
return "object" + (this.typeName !== undefined ? " (" + this.typeName + ")" : ""); | ||
} | ||
@@ -64,16 +64,15 @@ getObjectTypeDefinition() { | ||
let iterator = new iter_over_1.ObjectIterator(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)) | ||
for (let typeOrTypeDefinition of iterator) { | ||
let typePropertyName = typeOrTypeDefinition.key; | ||
if (typeOrTypeDefinition.value.getTypeName !== undefined) { | ||
let type = typeOrTypeDefinition.value; | ||
if (input.hasOwnProperty(typePropertyName)) { | ||
if (!type.checkConformity(input[typePropertyName])) | ||
return false; | ||
} | ||
else if (!type.isOptional()) | ||
return false; | ||
} | ||
else { | ||
if (!this.checkConformity(propertyValue, element.value)) | ||
if (!this.checkConformity(input[typePropertyName], typeOrTypeDefinition.value)) | ||
return false; | ||
@@ -87,17 +86,14 @@ } | ||
return false; | ||
let clonedInput = JSON.parse(JSON.stringify(input)); | ||
let iterator = new iter_over_1.ObjectIterator(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)) | ||
let iterator = new iter_over_1.ObjectIterator(input); | ||
for (let inputKVPair of iterator) { | ||
let inputPropertyName = inputKVPair.key; | ||
let inputPropertyValue = input[inputPropertyName]; | ||
if (typeDefinition[inputPropertyName] !== undefined) { | ||
if (typeDefinition[inputPropertyName].getTypeName !== undefined) { | ||
let type = typeDefinition[inputPropertyName]; | ||
if (!type.checkConformity(inputPropertyValue)) | ||
return false; | ||
} | ||
else { | ||
if (!this.exhaustivelyCheckConformity(propertyValue, typeDefinition[propertyName])) | ||
if (!this.exhaustivelyCheckConformity(inputPropertyValue, typeDefinition[inputPropertyName])) | ||
return false; | ||
@@ -104,0 +100,0 @@ } |
@@ -7,7 +7,7 @@ "use strict"; | ||
super(isOptional); | ||
this.name = name; | ||
this.typeName = name; | ||
this.validator = validator; | ||
} | ||
getTypeName() { | ||
return this.name; | ||
return this.typeName; | ||
} | ||
@@ -14,0 +14,0 @@ checkConformity(input) { |
@@ -7,7 +7,7 @@ "use strict"; | ||
super(isOptional); | ||
this.name = name; | ||
this.typeName = name; | ||
this.validator = validator; | ||
} | ||
getTypeName() { | ||
return this.name; | ||
return this.typeName; | ||
} | ||
@@ -14,0 +14,0 @@ checkConformity(input) { |
@@ -5,6 +5,6 @@ "use strict"; | ||
constructor(isOptional) { | ||
this.isOptional = isOptional; | ||
this.optional = isOptional; | ||
} | ||
getOptionality() { | ||
return this.isOptional; | ||
isOptional() { | ||
return this.optional; | ||
} | ||
@@ -11,0 +11,0 @@ sanitize(input) { |
{ | ||
"name": "typit", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Fully recursive runtime typechecking.", | ||
@@ -30,3 +30,3 @@ "main": "js/main", | ||
"dependencies": { | ||
"iter-over": "^1.1.1", | ||
"iter-over": "^1.1.2", | ||
"merj": "^0.1.0" | ||
@@ -33,0 +33,0 @@ }, |
@@ -8,8 +8,9 @@ /* | ||
import { Type } from "./type"; | ||
import { SpecialType } from "./special-type"; | ||
/** | ||
* A type that represents an Array of a given type. | ||
* | ||
* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.3.0 | ||
* @version v0.5.0 | ||
* @since v0.1.0 | ||
@@ -19,5 +20,19 @@ */ | ||
private arrayType: Type; | ||
/** | ||
* The type to which the members of the arrays passed to this ArrayType should conform. | ||
* | ||
* In other words, this is the type of the members of the array. | ||
*/ | ||
protected arrayType: Type; | ||
public constructor(arrayType: Type<E>, isOptional: boolean = false) { | ||
/** | ||
* Initializes a new ArrayType with a given member type and optionality. | ||
* | ||
* The `arrayType` parameter defaults to `SpecialType.ANY` so that if no arguments are passed to this constructor, | ||
* inputs that are checked for conformity by the constructed type will pass so long as they are actually arrays. | ||
* | ||
* @param arrayType The type of the members of the array. | ||
* @param isOptional Whether or not this type should be optional when present in an {@link ObjectType}. | ||
*/ | ||
public constructor(arrayType: Type<E> = SpecialType.ANY, isOptional: boolean = false) { | ||
@@ -30,2 +45,7 @@ super(isOptional); | ||
/** | ||
* Returns the string name of this ArrayType. | ||
* | ||
* @return The string name of this ArrayType. | ||
*/ | ||
public getTypeName(): string { | ||
@@ -37,2 +57,8 @@ | ||
/** | ||
* Checks that the provided input is an array, and that the array's contents conform to the given type of this | ||
* ArrayType. | ||
* | ||
* @param input Any variable to check for conformity to this ArrayType. | ||
*/ | ||
public checkConformity(input: any): boolean { | ||
@@ -57,2 +83,8 @@ | ||
/** | ||
* Due to the fact that an exhaustive check of an array wouldn't do anything different than the normal conformity | ||
* check, this method simply redirects to {@link ArrayType#checkConformity}. | ||
* | ||
* @param input Any variable to exhaustively check for conformity to this ArrayType. | ||
*/ | ||
public exhaustivelyCheckConformity(input: any): boolean { | ||
@@ -59,0 +91,0 @@ |
@@ -13,11 +13,32 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @version v0.5.0 | ||
* @since v0.4.0 | ||
*/ | ||
export class EnumType<E = any> extends Type { | ||
private typeName: string; | ||
/** | ||
* The name of this type. | ||
*/ | ||
protected typeName: string; | ||
private acceptableValues: E[]; | ||
/** | ||
* An array of acceptable values for which any conforming instances of this type should hold one of the items in | ||
* this array as a value. | ||
* | ||
* In other words, this EnumType's conformity check will pass so long as the value of any inputs passed to said | ||
* method are contained in this array. | ||
*/ | ||
protected acceptableValues: E[]; | ||
/** | ||
* Initializes a new EnumType with the provided list of acceptable values, an optional type name, and a given | ||
* optionality. | ||
* | ||
* If a type name is not provided, the type name will be set simply to "Enum". | ||
* | ||
* @param acceptableValues An array of acceptable values that conforming instances of this type should take on as | ||
* values. | ||
* @param typeName An optional name for this EnumType. | ||
* @param isOptional Whether or not this type should be optional when present in an {@link ObjectType}. | ||
*/ | ||
public constructor(acceptableValues: E[], typeName?: string, isOptional: boolean = false) { | ||
@@ -35,2 +56,3 @@ | ||
// TODO [6/14/19 @ 2:50 PM] - Attempt to derive acceptableValue type and iterate over getTypeName or raw value. | ||
// TODO [6/15/19 @ 7:29 PM] - Remember to change the doc-comment for the constructor once this logic is changed. | ||
@@ -41,2 +63,7 @@ } | ||
/** | ||
* Returns the string name of this EnumType. | ||
* | ||
* @return The string name of this EnumType. | ||
*/ | ||
public getTypeName(): string { | ||
@@ -48,2 +75,8 @@ | ||
/** | ||
* Returns true if and only if the input value is one of the acceptable values of this EnumType. | ||
* | ||
* @param input Any variable to check for conformity to this EnumType. | ||
* @return true if and only if the input value is one of the acceptable values of this EnumType. | ||
*/ | ||
public checkConformity(input: any): boolean { | ||
@@ -55,2 +88,8 @@ | ||
/** | ||
* Returns true if and only if the input value is equal to exactly one of the acceptable values of this EnumType. | ||
* | ||
* @param input Any variable to exhaustively check for conformity to this EnumType. | ||
* @return true if and only if the input value is equal to exactly one of the acceptable values of this EnumType. | ||
*/ | ||
public exhaustivelyCheckConformity(input: any): boolean { | ||
@@ -57,0 +96,0 @@ |
@@ -34,9 +34,8 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @version v0.5.0 | ||
* @since v0.4.0 | ||
*/ | ||
export class IntersectionType extends ObjectType { | ||
protected typeName: string; | ||
// DOC-ME [6/15/19 @ 7:13 PM] - Documentation required! | ||
public constructor(types: ObjectType[], isOptional: boolean = false) { | ||
@@ -43,0 +42,0 @@ |
@@ -10,4 +10,4 @@ /* | ||
/** | ||
* TODO | ||
* | ||
* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
@@ -19,4 +19,5 @@ * @version v0.3.0 | ||
// DOC-ME [6/15/19 @ 7:13 PM] - Documentation required! | ||
readonly [property: string]: Type | ObjectTypeDefinition; | ||
} |
@@ -12,6 +12,6 @@ /* | ||
/** | ||
* A type that represents a potentially complex, multi-level JavaScript object. | ||
* | ||
* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.3.0 | ||
* @version v0.5.0 | ||
* @since v0.1.0 | ||
@@ -21,10 +21,26 @@ */ | ||
// TODO [5/27/19 @ 12:54 AM] - Need to take into account that some properties might be optional, nullable, or explicitly undefined. | ||
/** | ||
* The name of this type. | ||
*/ | ||
protected typeName: string | undefined; | ||
protected typeName: string; | ||
/** | ||
* The {@link ObjectTypeDefinition} that this ObjectType uses to check the conformity of provided inputs. | ||
*/ | ||
protected typeDefinition: ObjectTypeDefinition; | ||
public constructor(typeDefinition: ObjectTypeDefinition, typeName: string = "", isOptional: boolean = false) { | ||
/** | ||
* Initializes a new ObjectType with a given {@link ObjectTypeDefinition}, type name, and optionality. | ||
* | ||
* The type definition argument is optional, and if not passed will default to an empty type definition, meaning | ||
* that any provided inputs will succeed given that they are objects of any form. | ||
* | ||
* The type name is optional as well and | ||
* | ||
* @param typeDefinition | ||
* @param typeName | ||
* @param isOptional | ||
*/ | ||
public constructor(typeDefinition: ObjectTypeDefinition = {}, typeName?: string, isOptional: boolean = false) { | ||
super(isOptional); | ||
@@ -34,5 +50,6 @@ | ||
this.typeName = typeName; | ||
} | ||
// DOC-ME [6/15/19 @ 5:53 PM] - Documentation required! | ||
public static typeDefinitionToReadableJSON(typeDefinition: ObjectTypeDefinition): any { | ||
@@ -53,5 +70,6 @@ | ||
return result; | ||
} | ||
// DOC-ME [6/15/19 @ 5:53 PM] - Documentation required! | ||
public static typeDefinitionToString(typeDefinition: ObjectTypeDefinition): string { | ||
@@ -94,2 +112,3 @@ | ||
// DOC-ME [6/15/19 @ 5:53 PM] - Documentation required! | ||
public typeDefinitionToReadableJSON(): any { | ||
@@ -101,2 +120,3 @@ | ||
// DOC-ME [6/15/19 @ 5:53 PM] - Documentation required! | ||
public typeDefinitionToString(): string { | ||
@@ -108,8 +128,14 @@ | ||
/** | ||
* Returns the string name of this ObjectType. | ||
* | ||
* @return The string name of this ObjectType. | ||
*/ | ||
public getTypeName(): string { | ||
return "object" + (this.typeName !== "" ? " (" + this.typeName + ")" : ""); | ||
return "object" + (this.typeName !== undefined ? " (" + this.typeName + ")" : ""); | ||
} | ||
// DOC-ME [6/15/19 @ 5:53 PM] - Documentation required! | ||
public getObjectTypeDefinition(): ObjectTypeDefinition { | ||
@@ -121,2 +147,7 @@ | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to check for conformity to this ObjectType. | ||
*/ | ||
public checkConformity(input: any, typeDefinition: ObjectTypeDefinition = this.typeDefinition): boolean { | ||
@@ -128,20 +159,24 @@ | ||
for (let element of iterator) { | ||
for (let typeOrTypeDefinition of iterator) { | ||
if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
let typePropertyName: string = typeOrTypeDefinition.key; | ||
let propertyName: string = element.key; | ||
let propertyValue: any = input[propertyName]; | ||
if (propertyValue === undefined) return false; | ||
if (element.value.getTypeName !== undefined) { | ||
// We're dealing with a Type, not an ObjectTypeDefinition. | ||
if (typeOrTypeDefinition.value.getTypeName !== undefined) { | ||
let type: Type = element.value as Type; | ||
let type: Type = typeOrTypeDefinition.value as Type; | ||
if (!type.checkConformity(propertyValue)) return false; | ||
// If the provided input has a property by the name defined in the type definition... | ||
if (input.hasOwnProperty(typePropertyName)) { | ||
// If the input's equivalent property does not conform to the type definition of said property... | ||
if (!type.checkConformity(input[typePropertyName])) return false; | ||
// If the value/type was not optionally defined... | ||
} else if (!type.isOptional()) return false; | ||
// We're dealing with a ObjectTypeDefinition, not an Type. | ||
} else { | ||
if (!this.checkConformity(propertyValue, element.value as ObjectTypeDefinition)) return false; | ||
if (!this.checkConformity(input[typePropertyName], typeOrTypeDefinition.value as ObjectTypeDefinition)) return false; | ||
@@ -156,2 +191,7 @@ } | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to exhaustively check for conformity to this ObjectType. | ||
*/ | ||
public exhaustivelyCheckConformity(input: any, typeDefinition: ObjectTypeDefinition = this.typeDefinition): boolean { | ||
@@ -161,23 +201,20 @@ | ||
let clonedInput: any = JSON.parse(JSON.stringify(input)); | ||
let iterator: ObjectIterator<any> = new ObjectIterator<any>(clonedInput); | ||
let iterator: ObjectIterator = new ObjectIterator(input); | ||
for (let element of iterator) { | ||
for (let inputKVPair of iterator) { | ||
if (element === undefined) throw new Error("ERR | Attempted to use an undefined type definition."); | ||
let inputPropertyName: string = inputKVPair.key; | ||
let inputPropertyValue: any = input[inputPropertyName]; | ||
let propertyName: string = element.key; | ||
let propertyValue: any = input[propertyName]; | ||
if (typeDefinition[propertyName] !== undefined) { | ||
if (typeDefinition[inputPropertyName] !== undefined) { | ||
if (typeDefinition[propertyName].getTypeName !== undefined) { | ||
if (typeDefinition[inputPropertyName].getTypeName !== undefined) { | ||
let type: Type = typeDefinition[propertyName] as Type; | ||
let type: Type = typeDefinition[inputPropertyName] as Type; | ||
if (!type.checkConformity(propertyValue)) return false; | ||
if (!type.checkConformity(inputPropertyValue)) return false; | ||
} else { | ||
if (!this.exhaustivelyCheckConformity(propertyValue, typeDefinition[propertyName] as ObjectTypeDefinition)) return false; | ||
if (!this.exhaustivelyCheckConformity(inputPropertyValue, typeDefinition[inputPropertyName] as ObjectTypeDefinition)) return false; | ||
@@ -184,0 +221,0 @@ } |
@@ -15,3 +15,3 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.3.0 | ||
* @version v0.5.0 | ||
* @since v0.1.0 | ||
@@ -21,2 +21,3 @@ */ | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly ANY: SpecialType<any> = new SpecialType( | ||
@@ -28,2 +29,3 @@ "any", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_ANY: SpecialType<any> = new SpecialType( | ||
@@ -35,2 +37,3 @@ "any", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly VOID: SpecialType<void> = new SpecialType( | ||
@@ -42,2 +45,3 @@ "void", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_VOID: SpecialType<void> = new SpecialType( | ||
@@ -49,2 +53,3 @@ "void", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly UNDEFINED: SpecialType<undefined> = new SpecialType( | ||
@@ -56,2 +61,3 @@ "undefined", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_UNDEFINED: SpecialType<undefined> = new SpecialType( | ||
@@ -63,2 +69,3 @@ "undefined", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly NULL: SpecialType<null> = new SpecialType( | ||
@@ -70,2 +77,3 @@ "null", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_NULL: SpecialType<null> = new SpecialType( | ||
@@ -77,6 +85,13 @@ "null", | ||
private name: string; | ||
/** | ||
* The name of this type. | ||
*/ | ||
protected typeName: string; | ||
private validator: Validator; | ||
/** | ||
* The method that is used to check inputs for conformity to the given type. | ||
*/ | ||
protected validator: Validator; | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
protected constructor(name: string, isOptional: boolean, validator: Validator) { | ||
@@ -86,3 +101,3 @@ | ||
this.name = name; | ||
this.typeName = name; | ||
this.validator = validator; | ||
@@ -92,8 +107,18 @@ | ||
/** | ||
* Returns the string name of this SpecialType. | ||
* | ||
* @return The string name of this SpecialType. | ||
*/ | ||
public getTypeName(): string { | ||
return this.name; | ||
return this.typeName; | ||
} | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to check for conformity to this SpecialType. | ||
*/ | ||
public checkConformity(input: any): boolean { | ||
@@ -105,2 +130,7 @@ | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to exhaustively check for conformity to this SpecialType. | ||
*/ | ||
public exhaustivelyCheckConformity(input: any): boolean { | ||
@@ -107,0 +137,0 @@ |
@@ -15,3 +15,3 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.3.0 | ||
* @version v0.5.0 | ||
* @since v0.1.0 | ||
@@ -21,2 +21,3 @@ */ | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly NUMBER: StandardType<number> = new StandardType( | ||
@@ -28,2 +29,3 @@ "number", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_NUMBER: StandardType<number> = new StandardType( | ||
@@ -35,2 +37,3 @@ "number", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly BOOLEAN: StandardType<boolean> = new StandardType( | ||
@@ -42,2 +45,3 @@ "boolean", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_BOOLEAN: StandardType<boolean> = new StandardType( | ||
@@ -49,2 +53,3 @@ "boolean", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly STRING: StandardType<string> = new StandardType( | ||
@@ -56,2 +61,3 @@ "string", | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public static readonly OPTIONAL_STRING: StandardType<string> = new StandardType( | ||
@@ -63,6 +69,13 @@ "string", | ||
private name: string; | ||
/** | ||
* The name of this type. | ||
*/ | ||
protected typeName: string; | ||
private validator: Validator; | ||
/** | ||
* The method that is used to check inputs for conformity to the given type. | ||
*/ | ||
protected validator: Validator; | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
protected constructor(name: string, isOptional: boolean, validator: Validator) { | ||
@@ -72,3 +85,3 @@ | ||
this.name = name; | ||
this.typeName = name; | ||
this.validator = validator; | ||
@@ -78,8 +91,19 @@ | ||
/** | ||
* Returns the string name of this StandardType. | ||
* | ||
* @return The string name of this StandardType. | ||
*/ | ||
public getTypeName(): string { | ||
return this.name; | ||
return this.typeName; | ||
} | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to check for conformity to this StandardType. | ||
* @return | ||
*/ | ||
public checkConformity(input: any): boolean { | ||
@@ -91,2 +115,7 @@ | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to exhaustively check for conformity to this StandardType. | ||
*/ | ||
public exhaustivelyCheckConformity(input: any): boolean { | ||
@@ -93,0 +122,0 @@ |
@@ -14,4 +14,4 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @version v0.4.0 | ||
* @since v0.4.0 | ||
*/ | ||
@@ -18,0 +18,0 @@ |
@@ -11,3 +11,3 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.3.0 | ||
* @version v0.5.0 | ||
* @since v0.1.0 | ||
@@ -17,18 +17,57 @@ */ | ||
protected readonly isOptional: boolean; | ||
/** | ||
* Whether or not this value is optional. | ||
* | ||
* @see Type#isOptional | ||
*/ | ||
protected optional: boolean; | ||
/** | ||
* Initializes a new Type with the given optionality. | ||
* | ||
* @param isOptional true if this Type should be optional. | ||
*/ | ||
protected constructor(isOptional: boolean) { | ||
this.isOptional = isOptional; | ||
this.optional = isOptional; | ||
} | ||
public getOptionality(): boolean { | ||
/** | ||
* Returns the optionality of this Type. | ||
* | ||
* Optionality refers to whether or not the given type must appear at all on the object which is being checked for | ||
* a value of 'this' Type. Keep in mind that optionality does not refer to whether or not accessing the variable | ||
* will return 'undefined'. As counter-intuitive as it may seem, a value may be defined as 'undefined'. To better | ||
* represent this problem, an example: | ||
* | ||
* let obj = { | ||
* myVal: undefined | ||
* } | ||
* | ||
* console.log(obj.myVal); // returns 'undefined' | ||
* console.log(obj.yourVal); // returns 'undefined' | ||
* | ||
* Given the above demonstration, you can see that both 'non-present' (also called 'blank', etc) variables, as well | ||
* as 'present' and defined variables will evaluate to 'undefined'. With this understanding, it might now be easier | ||
* to understand what optionality is: if a value is optional it can either be 'present' and of the Type represented | ||
* by this class, or it can be entirely 'non-present' - both of which cases would ensure conformity to this type | ||
* (given that this type is defined as optional). | ||
*/ | ||
public isOptional(): boolean { | ||
return this.isOptional; | ||
return this.optional; | ||
} | ||
/** | ||
* Returns the name of this Type. | ||
*/ | ||
public abstract getTypeName(): string; | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to check for conformity to this Type. | ||
*/ | ||
public abstract checkConformity(input: any): boolean; | ||
@@ -35,0 +74,0 @@ |
@@ -13,11 +13,16 @@ /* | ||
* @author Trevor Sears <trevorsears.main@gmail.com> | ||
* @version v0.1.0 | ||
* @since v0.1.0 | ||
* @version v0.5.0 | ||
* @since v0.4.0 | ||
*/ | ||
export class UnionType<E = any> extends Type<E> { | ||
/** | ||
* The name of this type. | ||
*/ | ||
protected typeName: string; | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
protected acceptableTypes: Type[]; | ||
// DOC-ME [6/15/19 @ 7:14 PM] - Documentation required! | ||
public constructor(types: Type[], isOptional: boolean = false) { | ||
@@ -39,2 +44,5 @@ | ||
/** | ||
* Returns the name of this Type. | ||
*/ | ||
public getTypeName(): string { | ||
@@ -46,2 +54,7 @@ | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to check for conformity to this UnionType. | ||
*/ | ||
public checkConformity(input: any): boolean { | ||
@@ -53,2 +66,7 @@ | ||
/** | ||
* TODO | ||
* | ||
* @param input Any variable to exhaustively check for conformity to this UnionType. | ||
*/ | ||
public exhaustivelyCheckConformity(input: any): boolean { | ||
@@ -55,0 +73,0 @@ |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
129041
57
1806
0
Updatediter-over@^1.1.2