-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
367 additions
and
5,254 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/dist | ||
/node_modules | ||
/yarn-*.log | ||
/coverage | ||
/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
nodejs 18.15.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import Type, { IType } from './type.js' | ||
|
||
import ArrayType from './types/array.js' | ||
import Sum from './types/sum.js' | ||
import Option from './types/option.js' | ||
import Struct from './types/struct.js' | ||
|
||
export default { | ||
check(type: IType, value: unknown): boolean { | ||
return type.__check(value) | ||
}, | ||
Type, | ||
|
||
String: new Type( | ||
v => Object.prototype.toString.call(v) === '[object String]' | ||
), | ||
Number: new Type( | ||
v => Object.prototype.toString.call(v) === '[object Number]' | ||
), | ||
Boolean: new Type( | ||
v => Object.prototype.toString.call(v) === '[object Boolean]' | ||
), | ||
|
||
Array: (type: IType) => new ArrayType(type), | ||
Sum: (...types: unknown[]) => new Sum(types), | ||
Option: (type: IType) => new Option(type), | ||
Struct: (def: Record<string, IType>) => new Struct(def), | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type TypeCheckFn = (value: unknown) => boolean | ||
|
||
export interface IType { | ||
__check(value: unknown): boolean | ||
} | ||
|
||
export default class Type implements IType { | ||
checker: TypeCheckFn | ||
|
||
constructor(checker: TypeCheckFn) { | ||
this.checker = checker | ||
} | ||
|
||
__check(value: unknown) { | ||
return this.checker(value) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IType } from '../type.js' | ||
export default class TArray implements IType { | ||
type: IType | ||
|
||
constructor(type: IType) { | ||
this.type = type | ||
} | ||
|
||
__check(value: unknown) { | ||
if (!Array.isArray(value)) return false | ||
|
||
return value.every(v => this.type.__check(v)) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { IType } from '../type.js' | ||
export default class Option implements IType { | ||
type: IType | ||
|
||
constructor(type: IType) { | ||
this.type = type | ||
} | ||
|
||
__check(value: unknown) { | ||
if (value === null) return true | ||
if (value === undefined) return true | ||
|
||
return this.type.__check(value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { isType } from '../util.js' | ||
import { IType } from '../type.js' | ||
|
||
export default class Sum implements IType { | ||
values: unknown[] | ||
|
||
constructor(values: unknown[]) { | ||
this.values = values | ||
} | ||
|
||
__check(value: unknown) { | ||
return this.values.some(v => { | ||
if (isType(v)) { | ||
return v.__check(value) | ||
} else { | ||
return v === value | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { IType } from './type.js' | ||
|
||
export function isObject(v: unknown): v is Record<string, unknown> { | ||
return Object.prototype.toString.call(v) === '[object Object]' | ||
} | ||
|
||
export function isType(v: unknown): v is IType { | ||
return isObject(v) && '__check' in v | ||
} | ||
|
||
export function hasOwnProperty(obj: Object, prop: string): boolean { | ||
return Object.prototype.hasOwnProperty.call(obj, prop) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.