Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

quack

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quack - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

.npmignore

14

package.json
{
"name": "quack",
"version": "0.0.0",
"version": "0.1.0",
"description": "Check the values of passed arguments in a function - see if they quack like a duck.",
"main": "quack.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "mocha should -w -G -r should test/unminified-test.js",
"test-min": "npm run build; mocha test/minified-test.js",
"prepublish": "npm test-min",
"build": "./node_modules/uglify-js/bin/uglifyjs quack.js -m -o quack.min.js"
},

@@ -22,3 +25,8 @@ "repository": {

"author": "glen@screenrev.com",
"license": "BSD"
"license": "BSD",
"devDependencies": {
"mocha": "~1.9.0",
"uglify-js": "~2.2.5",
"should": "~1.2.2"
}
}

@@ -13,14 +13,27 @@ /*

check the arguments against the expected signature
quack('string, number, array', 'one', 2, [3]); // true
@param {string|string[]} signature: string (for one), or array of strings to check against
@param {arguments|array|string} args: array-like arguments (or array of arguments) to check
@param {string|string[]} signature: string (for one), or array of strings to check against
@returns {boolean} true if the arguments match the signature
*/
var quack = function quack(args, signature){
// convert strings to arrays
if (typeof signature === 'string') signature = [signature];
if (typeof args === 'string') args = [args];
var quack = function quack(signature, args){
// convert array-like "arguments" to an array
if (isArguments(args)) args = [].slice.apply(args);
args = [].slice.apply(args);
// convert signature to an array
if (typeof signature == 'string') {
// trim whitespace and split on commas (with or without spaces)
signature = signature.replace(/^\s*|\s*$/g, '').split(/\s*,\s*/);
}
// iterate over the signature, matching types against arguments
for (var i = 0, max = signature.length; i < max; i++) {
if (typeof signature[i] !== args[i].toLowerCase()) return false;
var sig = signature[i].toLowerCase();
var arg = args[i];
if (sig == 'object') return isObject(arg);
else if (sig == 'array') return isArray(arg);
else if (sig !== typeof arg) return false;
}

@@ -31,3 +44,29 @@

// module definitions
/*
Type checking
*/
var objectTypes = {
'function': true,
'object': true
};
function isArguments(value){
return toString.call(value) == '[object Arguments]';
}
function isObject(value) {
return value ? !! objectTypes[typeof value] : false;
}
function isArray(value){
return value ? (typeof value == 'object' && toString.call(value) == '[object Array]') : false;
}
/*
module definitions
*/
if (exports) module.exports = quack; // NodeJS

@@ -34,0 +73,0 @@ else if (define && define.amd) define(quack); // AMD

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc