mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #7918 from marcinporebski/master
js-schema definitions
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
///<reference path="js-schema.d.ts" />
|
||||
|
||||
import {default as schema} from 'js-schema';
|
||||
|
||||
var Duck = schema({ // A duck
|
||||
swim : Function, // - can swim
|
||||
quack : Function, // - can quack
|
||||
age : Number.min(0).max(5), // - is 0 to 5 years old
|
||||
color : ['yellow', 'brown'] // - has either yellow or brown color
|
||||
});
|
||||
|
||||
// Some animals
|
||||
var myDuck = { swim : function() {}, quack : function() {}, age : 2, color : 'yellow' },
|
||||
myCat = { walk : function() {}, purr : function() {}, age : 3, color : 'black' },
|
||||
animals = [ myDuck, myCat, {}, /*...*/ ];
|
||||
|
||||
// Simple checks
|
||||
console.log( Duck(myDuck) ); // true
|
||||
console.log( Duck(myCat) ); // false
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
// Type definitions for js-schema
|
||||
// Project: https://github.com/molnarg/js-schema
|
||||
// Definitions by: Marcin Porebski <https://github.com/marcinporebski>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
declare module 'js-schema'
|
||||
{
|
||||
export interface Schema
|
||||
{
|
||||
(obj: any): boolean; // test obj against the schema
|
||||
}
|
||||
|
||||
export default function schema(definition: any): Schema
|
||||
}
|
||||
|
||||
interface NumberConstructor
|
||||
{
|
||||
min(n: number): NumberConstructor;
|
||||
max(n: number): NumberConstructor;
|
||||
below(n: number): NumberConstructor;
|
||||
above(n: number): NumberConstructor;
|
||||
step(n: number): NumberConstructor;
|
||||
}
|
||||
|
||||
interface StringConstructor
|
||||
{
|
||||
of(charset: string): StringConstructor;
|
||||
of(length: number, charset: string): StringConstructor;
|
||||
of(minLength: number, maxLength: number, charset: string): StringConstructor;
|
||||
}
|
||||
|
||||
interface ArrayConstructor
|
||||
{
|
||||
like(arr: Array<any>): ArrayConstructor;
|
||||
of(pattern: any): ArrayConstructor;
|
||||
of(length: number, pattern: any): ArrayConstructor;
|
||||
of(minLength: number, maxLength: number, pattern: any): ArrayConstructor;
|
||||
}
|
||||
|
||||
interface ObjectConstructor
|
||||
{
|
||||
like(obj: any): ObjectConstructor;
|
||||
reference(obj: any): ObjectConstructor;
|
||||
}
|
||||
|
||||
interface FunctionConstructor
|
||||
{
|
||||
reference(func: Function): FunctionConstructor;
|
||||
}
|
||||
Reference in New Issue
Block a user