Comparing version 0.2.0 to 0.3.0
{ | ||
"name": "quack", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Check the values of passed arguments in a function - see if they quack like a duck.", | ||
@@ -5,0 +5,0 @@ "main": "quack.js", |
55
quack.js
@@ -8,3 +8,3 @@ /* | ||
void (function(root, undefined){ | ||
void(function(root, undefined) { | ||
@@ -22,3 +22,3 @@ 'use strict'; | ||
*/ | ||
var quack = function quack(signature, args){ | ||
var quack = function quack(signature, args) { | ||
var i, max, sig, arg; | ||
@@ -38,2 +38,3 @@ | ||
sig = signature[i].toLowerCase(); | ||
sig = shorthand[sig] || sig; // test for shorthand methods | ||
arg = args[i]; | ||
@@ -70,4 +71,3 @@ | ||
var toString = Object().toString; | ||
var toString = {}.toString; | ||
var objectTypes = { | ||
@@ -77,40 +77,43 @@ 'function': true, | ||
}; | ||
var shorthand = { | ||
'""': 'string', | ||
'1': 'number', | ||
'[]': 'array' | ||
}; | ||
function isArguments(value){ | ||
var isArguments = function(value) { | ||
return toString.call(value) == '[object Arguments]'; | ||
} | ||
}; | ||
// fallback for browsers that can't detect `arguments` objects by [[Class]] | ||
if (! isArguments(arguments)) { | ||
isArguments = function(value) { | ||
return value ? Object().hasOwnProperty.call(value, 'callee') : false; | ||
}; | ||
} | ||
if (! isArguments(arguments)) isArguments = isArgumentsFallback; | ||
var isArgumentsFallback = function(value) { | ||
return value ? {}.hasOwnProperty.call(value, 'callee') : false; | ||
}; | ||
function isObject(value) { | ||
var isObject = function(value) { | ||
return value ? !! objectTypes[typeof value] : false; | ||
} | ||
}; | ||
function isArray(value){ | ||
var isArray = function(value) { | ||
return value ? (typeof value == 'object' && toString.call(value) == '[object Array]') : false; | ||
} | ||
}; | ||
function isFunction(value){ | ||
var isFunction = function(value) { | ||
return typeof value == 'function'; | ||
} | ||
}; | ||
// fallback for older versions of Chrome and Safari | ||
if (isFunction(/x/)) { | ||
isFunction = function(value){ | ||
return typeof value == 'function' && toString.call(value) == '[object Function]'; | ||
}; | ||
} | ||
var isFunctionFallback = function(value) { | ||
return typeof value == 'function' && toString.call(value) == '[object Function]'; | ||
}; | ||
if (isFunction(/x/)) isFunction = isFunctionFallback; | ||
function isDate(value){ | ||
var isDate = function(value) { | ||
return value ? (typeof value == 'object' && toString.call(value) == '[object Date]') : false; | ||
} | ||
}; | ||
function isRegExp(value) { | ||
var isRegExp = function(value) { | ||
return value ? (typeof value == 'object' && toString.call(value) == '[object RegExp]') : false; | ||
} | ||
}; | ||
@@ -117,0 +120,0 @@ /* |
@@ -96,12 +96,13 @@ # quack | ||
- 0.2: **DONE** add `function`, `date`, `regexp`, `arguments` | ||
- 0.3: shorthand | ||
eg. `'"", {}, [], 1'` short for `'string, object, array, number'` | ||
- 0.3: **DONE** shorthand | ||
eg. `'"", [], 1'` short for `'string, array, number'` | ||
- 0.4: `options`: a third argument | ||
- **throws** `boolean`: throw and error if validation fails | ||
- **throws** `boolean`: throw an error if validation fails | ||
- **console** `boolean`: log to the console if validation fails | ||
- **message** `string`: a specific message for logged/thrown errors | ||
- 0.5: types of `arrays` & `object` properties | ||
- `'string[]'`: an `array` of `strings` | ||
- `'[]string'`: an `array` of `strings` | ||
- `'[string, number]'`: specific types within an `array` | ||
- `'string{}'`: and `object` with only `string` properties | ||
- `'{}string'`: an `object` with only `string` properties | ||
- `'{val1: string, val2: number}'`: specific `object` property names and types | ||
- 0.6: **plain object** type, with `'{}'` shorthand |
@@ -5,2 +5,3 @@ // quack is passed in, minified or unminified | ||
require('./values.js')(quack); | ||
require('./shorthand.js')(quack); | ||
}; |
@@ -1,22 +0,2 @@ | ||
// common types | ||
var types = { | ||
aString: 'a string', | ||
anEmptyString: '', | ||
aNumber: 123, | ||
notANumber: NaN, | ||
aBoolean: true, | ||
aFalseBoolean: false, | ||
anObject: {foo: 'bar'}, | ||
anEmptyObject: {}, | ||
anStrObject: new String(), | ||
anNumObject: new Number(), | ||
anArray: [undefined, 'one', 2], | ||
anEmptyArray: [], | ||
anArgsObject: (function(){return arguments;})('one', 2), | ||
aFunction: function(){}, | ||
aDate: new Date(), | ||
aRegExp: / /i, | ||
aNull: null, | ||
anUndefined: void 0 | ||
}; | ||
var types = require('./types'); | ||
@@ -75,4 +55,4 @@ // quack is passed in, minified or unminified | ||
quack('object', [types.anEmptyObject]).should.equal(true); | ||
quack('object', [types.anStrObject]).should.equal(true); | ||
quack('object', [types.anNumObject]).should.equal(true); | ||
quack('object', [types.aStrObject]).should.equal(true); | ||
quack('object', [types.aNumObject]).should.equal(true); | ||
quack('object', [types.aDate]).should.equal(true); | ||
@@ -79,0 +59,0 @@ quack('object', [types.anArray]).should.equal(true); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
71363
16
287
108