0.1.6 • Published 11 years ago
pattern-matching v0.1.6
- node.js, browserify
npm install pattern-matching --save- requirejs
bower install pattern-matching --saveНебольшая библиотека придуманная для верификации аргументов переданных в функцию.
string-'blah',''notEmptyString-'blah'number-1,0.1integer-1boolean-true,falseobject-{},new Object()notEmptyObject-{ field: 1 }date-new Date()regExp-new RegExp()error-new Error()array-[],new Array()function-new Function(),function() {}primitive-null,1,'blah',false,undefined,InfinitynotEmpty-[1],{ test: 1 },'1',1,true,Infinity*- any value
var patternMatching = require('pattern-matching');
console.assert(patternMatching({
name: 'Bob',
age: 23,
isAlive: true
}, {
name: 'notEmptyString',
age: 'integer',
isAlive: 'boolean'
}));
console.assert(patternMatching(false, 'boolean'));
console.assert(patternMatching({
field: 1,
deep: {
foo: 'bar'
}
}, {
field: 'integer',
deep: {
foo: 'notEmptyString'
}
}));patternMatching.isUpperCase = function(value) {
return value.toUpperCase() === value;
};
console.assert(patternMatching('HELLO WORLD!', 'upperCase'));