Sindre Sorhus
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with
20 additions and
19 deletions
-
package.json
-
source/lib/predicates/boolean.ts
-
source/lib/predicates/number.ts
-
source/lib/predicates/predicate.ts
-
source/lib/predicates/string.ts
-
tslint.json
|
@ -55,7 +55,7 @@ |
|
|
"del-cli": "^1.1.0", |
|
|
"del-cli": "^1.1.0", |
|
|
"nyc": "^11.2.1", |
|
|
"nyc": "^11.2.1", |
|
|
"tslint": "^5.8.0", |
|
|
"tslint": "^5.8.0", |
|
|
"tslint-xo": "^0.1.0", |
|
|
"tslint-xo": "^0.2.0", |
|
|
"typescript": "^2.6.1" |
|
|
"typescript": "^2.6.1" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
@ -1,7 +1,6 @@ |
|
|
import {Predicate, Context} from './predicate'; |
|
|
import {Predicate, Context} from './predicate'; |
|
|
|
|
|
|
|
|
export class BooleanPredicate extends Predicate<boolean> { |
|
|
export class BooleanPredicate extends Predicate<boolean> { |
|
|
|
|
|
|
|
|
constructor(context?: Context) { |
|
|
constructor(context?: Context) { |
|
|
super('boolean', context); |
|
|
super('boolean', context); |
|
|
} |
|
|
} |
|
|
|
@ -2,7 +2,6 @@ import * as is from '@sindresorhus/is'; |
|
|
import {Predicate, Context} from './predicate'; |
|
|
import {Predicate, Context} from './predicate'; |
|
|
|
|
|
|
|
|
export class NumberPredicate extends Predicate<number> { |
|
|
export class NumberPredicate extends Predicate<number> { |
|
|
|
|
|
|
|
|
constructor(context?: Context) { |
|
|
constructor(context?: Context) { |
|
|
super('number', context); |
|
|
super('number', context); |
|
|
} |
|
|
} |
|
|
|
@ -13,10 +13,11 @@ export interface Context { |
|
|
export const validatorSymbol = Symbol('validators'); |
|
|
export const validatorSymbol = Symbol('validators'); |
|
|
|
|
|
|
|
|
export abstract class Predicate<T = any> { |
|
|
export abstract class Predicate<T = any> { |
|
|
|
|
|
|
|
|
constructor( |
|
|
constructor( |
|
|
type: string, |
|
|
type: string, |
|
|
private context: Context = { validators: [] } |
|
|
private context: Context = { |
|
|
|
|
|
validators: [] |
|
|
|
|
|
} |
|
|
) { |
|
|
) { |
|
|
this.addValidator({ |
|
|
this.addValidator({ |
|
|
message: value => `Expected argument to be of type \`${type}\` but received type \`${is(value)}\``, |
|
|
message: value => `Expected argument to be of type \`${type}\` but received type \`${is(value)}\``, |
|
|
|
@ -2,7 +2,6 @@ import * as valiDate from 'vali-date'; |
|
|
import {Predicate, Context} from './predicate'; |
|
|
import {Predicate, Context} from './predicate'; |
|
|
|
|
|
|
|
|
export class StringPredicate extends Predicate<string> { |
|
|
export class StringPredicate extends Predicate<string> { |
|
|
|
|
|
|
|
|
constructor(context?: Context) { |
|
|
constructor(context?: Context) { |
|
|
super('string', context); |
|
|
super('string', context); |
|
|
} |
|
|
} |
|
|
|
@ -1,3 +1,6 @@ |
|
|
{ |
|
|
{ |
|
|
"extends": "tslint-xo" |
|
|
"extends": "tslint-xo", |
|
|
|
|
|
"rules": { |
|
|
|
|
|
"completed-docs": [true, "methods"] |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|