Comparing version 0.0.5 to 0.0.6
@@ -0,1 +1,2 @@ | ||
import { Type } from "./Type"; | ||
export interface Flaw { | ||
@@ -8,3 +9,5 @@ property?: string | number; | ||
export declare namespace Flaw { | ||
function is(value: any | Flaw): value is Flaw; | ||
const type: Type<Flaw>; | ||
const is: (value: any) => value is Flaw; | ||
const flaw: (value: any) => Flaw | undefined; | ||
} |
@@ -0,12 +1,19 @@ | ||
import { array } from "./array"; | ||
import { lazy } from "./lazy"; | ||
import { number } from "./number"; | ||
import { object } from "./object"; | ||
import { optional } from "./optional"; | ||
import { string } from "./string"; | ||
import { union } from "./union"; | ||
export var Flaw; | ||
(function (Flaw) { | ||
function is(value) { | ||
return (typeof value == "object" && | ||
(value.property == undefined || typeof value.property == "string") && | ||
typeof value.type == "string" && | ||
(value.flaws == undefined || (Array.isArray(value.flaws) && value.flaws.every(Flaw.is))) && | ||
(value.condition == undefined || typeof value.condition == "string")); | ||
} | ||
Flaw.is = is; | ||
Flaw.type = object({ | ||
property: optional(union(string(), number())), | ||
type: string(), | ||
flaws: optional(array(lazy(() => Flaw.type))), | ||
condition: optional(string()), | ||
}); | ||
Flaw.is = Flaw.type.is; | ||
Flaw.flaw = Flaw.type.flaw; | ||
})(Flaw || (Flaw = {})); | ||
//# sourceMappingURL=Flaw.js.map |
@@ -1,9 +0,14 @@ | ||
import { Array, array } from "./Array"; | ||
import { any } from "./any"; | ||
import { array } from "./array"; | ||
import { boolean } from "./boolean"; | ||
import { Flaw } from "./Flaw"; | ||
import { Number, number } from "./Number"; | ||
import { Object, object } from "./Object"; | ||
import { String, string } from "./String"; | ||
import { Tuple, tuple } from "./Tuple"; | ||
import { lazy } from "./lazy"; | ||
import { named } from "./named"; | ||
import { number } from "./number"; | ||
import { object } from "./object"; | ||
import { optional } from "./optional"; | ||
import { string } from "./string"; | ||
import { tuple } from "./tuple"; | ||
import { Type } from "./Type"; | ||
import { Union, union } from "./Union"; | ||
export { Array, array, Flaw, Number, number, Object, object, String, string, Tuple, tuple, Type, Union, union }; | ||
import { union } from "./union"; | ||
export { any, array, boolean, Flaw, lazy, named, number, object, optional, string, tuple, Type, union }; |
@@ -1,10 +0,15 @@ | ||
import { array } from "./Array"; | ||
import { any } from "./any"; | ||
import { array } from "./array"; | ||
import { boolean } from "./boolean"; | ||
import { Flaw } from "./Flaw"; | ||
import { number } from "./Number"; | ||
import { object } from "./Object"; | ||
import { string } from "./String"; | ||
import { tuple } from "./Tuple"; | ||
import { lazy } from "./lazy"; | ||
import { named } from "./named"; | ||
import { number } from "./number"; | ||
import { object } from "./object"; | ||
import { optional } from "./optional"; | ||
import { string } from "./string"; | ||
import { tuple } from "./tuple"; | ||
import { Type } from "./Type"; | ||
import { union } from "./Union"; | ||
export { array, Flaw, number, object, string, tuple, Type, union }; | ||
import { union } from "./union"; | ||
export { any, array, boolean, Flaw, lazy, named, number, object, optional, string, tuple, Type, union }; | ||
//# sourceMappingURL=index.js.map |
import { Flaw } from "./Flaw"; | ||
export declare abstract class Type<T> { | ||
abstract readonly name: string; | ||
export interface Type<T> { | ||
readonly name: string; | ||
readonly condition?: string; | ||
abstract is(value: any | T): value is T; | ||
abstract flaw(value: any): true | Flaw; | ||
is(value: any | T): value is T; | ||
flaw(value: any): undefined | Flaw; | ||
} | ||
export declare namespace Type { | ||
type IsFunction<T> = (value: any | T) => value is T; | ||
type FlawFunction = (value: any) => undefined | Flaw; | ||
function create<T>(name: string | (() => string), is: IsFunction<T>, flaw: FlawFunction, condition?: string): Type<T>; | ||
} |
@@ -1,6 +0,12 @@ | ||
export class Type { | ||
constructor() { | ||
this.condition = ""; | ||
export var Type; | ||
(function (Type) { | ||
function create(name, is, flaw, condition) { | ||
return Object.defineProperty({ | ||
is, | ||
flaw, | ||
condition, | ||
}, "name", { get: typeof name == "function" ? name : () => name }); | ||
} | ||
} | ||
Type.create = create; | ||
})(Type || (Type = {})); | ||
//# sourceMappingURL=Type.js.map |
26
Flaw.ts
@@ -0,1 +1,10 @@ | ||
import { array } from "./array" | ||
import { lazy } from "./lazy" | ||
import { number } from "./number" | ||
import { object } from "./object" | ||
import { optional } from "./optional" | ||
import { string } from "./string" | ||
import { Type } from "./Type" | ||
import { union } from "./union" | ||
export interface Flaw { | ||
@@ -9,11 +18,10 @@ property?: string | number | ||
export namespace Flaw { | ||
export function is(value: any | Flaw): value is Flaw { | ||
return ( | ||
typeof value == "object" && | ||
(value.property == undefined || typeof value.property == "string") && | ||
typeof value.type == "string" && | ||
(value.flaws == undefined || (Array.isArray(value.flaws) && value.flaws.every(Flaw.is))) && | ||
(value.condition == undefined || typeof value.condition == "string") | ||
) | ||
} | ||
export const type: Type<Flaw> = object({ | ||
property: optional(union<string | number>(string(), number())), | ||
type: string(), | ||
flaws: optional(array(lazy(() => type))), | ||
condition: optional(string()), | ||
}) | ||
export const is = type.is | ||
export const flaw = type.flaw | ||
} |
19
index.ts
@@ -1,10 +0,15 @@ | ||
import { Array, array } from "./Array" | ||
import { any } from "./any" | ||
import { array } from "./array" | ||
import { boolean } from "./boolean" | ||
import { Flaw } from "./Flaw" | ||
import { Number, number } from "./Number" | ||
import { Object, object } from "./Object" | ||
import { String, string } from "./String" | ||
import { Tuple, tuple } from "./Tuple" | ||
import { lazy } from "./lazy" | ||
import { named } from "./named" | ||
import { number } from "./number" | ||
import { object } from "./object" | ||
import { optional } from "./optional" | ||
import { string } from "./string" | ||
import { tuple } from "./tuple" | ||
import { Type } from "./Type" | ||
import { Union, union } from "./Union" | ||
import { union } from "./union" | ||
export { Array, array, Flaw, Number, number, Object, object, String, string, Tuple, tuple, Type, Union, union } | ||
export { any, array, boolean, Flaw, lazy, named, number, object, optional, string, tuple, Type, union } |
{ | ||
"name": "isly", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Library for type checking.", | ||
@@ -57,14 +57,14 @@ "author": "Utily Contributors", | ||
"devDependencies": { | ||
"@types/jest": "^29.2.0", | ||
"@typescript-eslint/eslint-plugin": "5.41.0", | ||
"@typescript-eslint/parser": "5.41.0", | ||
"eslint": "^8.26.0", | ||
"eslint-plugin-prettierx": "github:utily/eslint-plugin-prettierx#utily-20221021", | ||
"@types/jest": "^29.2.5", | ||
"@typescript-eslint/eslint-plugin": "5.48.1", | ||
"@typescript-eslint/parser": "5.48.1", | ||
"eslint": "^8.31.0", | ||
"eslint-plugin-prettierx": "github:utily/eslint-plugin-prettierx#utily-20221229", | ||
"eslint-plugin-simple-import-sort": "^8.0.0", | ||
"jest": "^29.2.2", | ||
"prettierx": "github:utily/prettierx#utily-20221021", | ||
"jest": "^29.3.1", | ||
"prettierx": "github:utily/prettierx#utily-20221229", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^29.0.3", | ||
"typescript": "^4.8.4" | ||
"typescript": "^4.9.4" | ||
} | ||
} |
36
Type.ts
import { Flaw } from "./Flaw" | ||
export abstract class Type<T> { | ||
abstract readonly name: string | ||
readonly condition?: string = "" | ||
abstract is(value: any | T): value is T | ||
abstract flaw(value: any): true | Flaw | ||
export interface Type<T> { | ||
readonly name: string | ||
readonly condition?: string | ||
is(value: any | T): value is T | ||
flaw(value: any): undefined | Flaw | ||
} | ||
export namespace Type { | ||
export type IsFunction<T> = (value: any | T) => value is T | ||
export type FlawFunction = (value: any) => undefined | Flaw | ||
export function create<T>( | ||
name: string | (() => string), | ||
is: IsFunction<T>, | ||
flaw: FlawFunction, | ||
condition?: string | ||
): Type<T> { | ||
return Object.defineProperty( | ||
{ | ||
is, | ||
flaw, | ||
condition, | ||
}, | ||
"name", | ||
{ get: typeof name == "function" ? name : () => name } | ||
) as Type<T> | ||
} | ||
} | ||
// export interface Type<T> { | ||
// readonly name: string | ||
// readonly condition?: string | ||
// is(value: any | T): value is T | ||
// flaw(value: any): true | Flaw | ||
// } |
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
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
44754
69
693
1