0.1.6 • Published 10 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.1
integer
-1
boolean
-true
,false
object
-{}
,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
,Infinity
notEmpty
-[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'));