New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ducky

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ducky - npm Package Compare versions

Comparing version 2.4.0 to 2.5.0

2

bower.json
{
"name": "ducky",
"version": "2.4.0",
"version": "2.5.0",
"description": "Duck-Typed Value Handling for JavaScript",

@@ -5,0 +5,0 @@ "main": "./lib/ducky.browser.js",

@@ -96,3 +96,3 @@ /*

options: {
config: "eslint.json"
configFile: "eslint.json"
},

@@ -99,0 +99,0 @@ gruntfile: [ "Gruntfile.js" ],

@@ -26,3 +26,3 @@ /*!

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ducky = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:2,minor:4,micro:0,date:20160313};exports.version=version;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var version={major:2,minor:5,micro:0,date:20161120};exports.version=version;
},{}],2:[function(_dereq_,module,exports){

@@ -40,15 +40,15 @@ "use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,s,n){return s&&e(t.prototype,s),n&&e(t,n),t}}(),Token=function(){function e(){_classCallCheck(this,e),this.name="",this.text="",this.tokens=[],this.pos=0,this.len=0}return _createClass(e,[{key:"setName",value:function(e){this.name=e}},{key:"setText",value:function(e){this.text=e}},{key:"addToken",value:function(e,t,s,n,o){this.tokens.push({b1:e,b2:t,e2:s,e1:n,symbol:o}),this.len++}},{key:"peek",value:function(e){if("undefined"==typeof e&&(e=0),e>=this.len)throw new Error(this.name+": parse error: not enough tokens");return this.tokens[this.pos+e].symbol}},{key:"skip",value:function(e){if("undefined"==typeof e&&(e=1),e>this.len)throw new Error(this.name+": parse error: not enough tokens available to skip: "+this.ctx());this.pos+=e,this.len-=e}},{key:"consume",value:function(e){if(this.len<=0)throw new Error(this.name+": parse error: no more tokens available to consume: "+this.ctx());if(this.tokens[this.pos].symbol!==e)throw new Error(this.name+': parse error: expected token symbol "'+e+'": '+this.ctx());this.pos++,this.len--}},{key:"ctx",value:function(e){"undefined"==typeof e&&(e=78);var t=this.tokens[this.pos],s="<"+this.text.substr(t.b2,t.e2-t.b2+1)+">";s=this.text.substr(t.b1,t.b2-t.b1)+s,s+=this.text.substr(t.e2+1,t.e1-t.e2);var n=e-s.length;if(n>0){n=Math.floor(n/2);var o=void 0,i=void 0;if(this.pos>0){var r=0;for(o=this.pos-1;o>=0&&(t=this.tokens[o],i=this.text.substr(t.b1,t.e1-t.b1+1),r+=i.length,!(r>n));o--)s=i+s;o>0&&(s="[...]"+s)}if(this.len>1){var h=0;for(o=this.pos+1;o<this.pos+this.len&&(t=this.tokens[o],i=this.text.substr(t.b1,t.e1-t.b1+1),h+=i.length,!(h>n));o++)s+=i;o<this.pos+this.len&&(s+="[...]")}}return s=s.replace(/\r/,"\\r").replace(/\n/,"\\n").replace(/\t/,"\\t")}}]),e}();exports.Token=Token;

},{}],6:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},select_execute=function(e,t){if(0===t.length){if(3===arguments.length)throw new Error("select: cannot set value on empty path");return e}for(var o=0;o<t.length-1;){if("object"!==("undefined"==typeof e?"undefined":_typeof(e)))throw new Error("select: cannot further dereference: no more intermediate objects in path");e=e[t[o++]]}if("object"!==("undefined"==typeof e?"undefined":_typeof(e)))throw new Error("select: cannot further dereference: no object at end of path");var n=e[t[o]];if(3===arguments.length){var r=arguments[2];void 0===r?e instanceof Array?e.splice(parseInt(t[o],10),1):delete e[t[o]]:e[t[o]]=r}return n};exports.select_execute=select_execute;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},select_execute=function(e,t){if(0===t.length){if(3===arguments.length)throw new Error("select: cannot set value on empty path");return e}for(var o=0;o<t.length-1;){if("object"!==("undefined"==typeof e?"undefined":_typeof(e)))throw new Error("select: cannot further dereference: no more intermediate objects in path");e=e[t[o++]]}if("object"!==("undefined"==typeof e?"undefined":_typeof(e)))throw new Error("select: cannot further dereference: no object at end of path");var n=e[t[o]];if(3===arguments.length){var r=arguments[2];void 0===r?e instanceof Array?e.splice(parseInt(t[o],10),1):delete e[t[o]]:e[t[o]]=r}return n};exports.select_execute=select_execute;
},{}],7:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.select=void 0;var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_ducky3Select1Compile=_dereq_("./ducky-3-select-1-compile.js"),_ducky3Select2Execute=_dereq_("./ducky-3-select-2-execute.js"),select_cache={},select=function(e,t,c){if(arguments.length<2)throw new Error("select: invalid number of arguments: "+arguments.length+" (minimum of 2 expected)");if(arguments.length>3)throw new Error("select: invalid number of arguments: "+arguments.length+" (maximum of 3 expected)");if("string"!=typeof t)throw new Error('select: invalid specification argument: "'+t+'" (string expected)');var r=select_cache[t];return"undefined"==typeof r&&(r=(0,_ducky3Select1Compile.select_compile)(t),select_cache[t]=r),2===arguments.length?(0,_ducky3Select2Execute.select_execute)(e,r):(0,_ducky3Select2Execute.select_execute)(e,r,c)};select.compile=function(e){if(1!==arguments.length)throw new Error("select: invalid number of arguments: "+arguments.length+" (exactly 1 expected)");if("string"!=typeof e)throw new Error('select: invalid specification argument: "'+e+'" (string expected)');return _ducky3Select1Compile.select_compile.apply(void 0,arguments)},select.execute=function(e,t){if(arguments.length<2)throw new Error("select: invalid number of arguments: "+arguments.length+" (minimum of 2 expected)");if(arguments.length>3)throw new Error("select: invalid number of arguments: "+arguments.length+" (maximum of 3 expected)");if(!("object"===("undefined"==typeof t?"undefined":_typeof(t))&&t instanceof Array))throw new Error('select: invalid path argument: "'+t+'" (array expected)');return _ducky3Select2Execute.select_execute.apply(void 0,arguments)},exports.select=select;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.select=void 0;var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_ducky3Select1Compile=_dereq_("./ducky-3-select-1-compile.js"),_ducky3Select2Execute=_dereq_("./ducky-3-select-2-execute.js"),select_cache={},select=function(e,t,c){if(arguments.length<2)throw new Error("select: invalid number of arguments: "+arguments.length+" (minimum of 2 expected)");if(arguments.length>3)throw new Error("select: invalid number of arguments: "+arguments.length+" (maximum of 3 expected)");if("string"!=typeof t)throw new Error('select: invalid specification argument: "'+t+'" (string expected)');var r=select_cache[t];return"undefined"==typeof r&&(r=(0,_ducky3Select1Compile.select_compile)(t),select_cache[t]=r),2===arguments.length?(0,_ducky3Select2Execute.select_execute)(e,r):(0,_ducky3Select2Execute.select_execute)(e,r,c)};select.compile=function(e){if(1!==arguments.length)throw new Error("select: invalid number of arguments: "+arguments.length+" (exactly 1 expected)");if("string"!=typeof e)throw new Error('select: invalid specification argument: "'+e+'" (string expected)');return _ducky3Select1Compile.select_compile.apply(void 0,arguments)},select.execute=function(e,t){if(arguments.length<2)throw new Error("select: invalid number of arguments: "+arguments.length+" (minimum of 2 expected)");if(arguments.length>3)throw new Error("select: invalid number of arguments: "+arguments.length+" (maximum of 3 expected)");if(!("object"===("undefined"==typeof t?"undefined":_typeof(t))&&t instanceof Array))throw new Error('select: invalid path argument: "'+t+'" (array expected)');return _ducky3Select2Execute.select_execute.apply(void 0,arguments)},exports.select=select;
},{"./ducky-3-select-1-compile.js":5,"./ducky-3-select-2-execute.js":6}],8:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validate_tokenize=void 0;var _ducky1Util=_dereq_("./ducky-1-util.js"),validate_tokenize=function(e){var t=new _ducky1Util.Token;t.setName("validate"),t.setText(e);for(var n=void 0,r=0;""!==e;){if(n=e.match(/^(\s*)([^{}\[\]:,?*+()!|\s]+|[{}\[\]:,?*+()!|])(\s*)/),null===n)throw new Error('validate: parse error: cannot further canonicalize: "'+e+'"');t.addToken(r,r+n[1].length,r+n[1].length+n[2].length-1,r+n[0].length-1,n[2]),e=e.substr(n[0].length),r+=n[0].length}return t.addToken(r,r,r,r,null),t};exports.validate_tokenize=validate_tokenize;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validate_tokenize=void 0;var _ducky1Util=_dereq_("./ducky-1-util.js"),validate_tokenize=function(e){var t=new _ducky1Util.Token;t.setName("validate"),t.setText(e);for(var n=void 0,r=0;""!==e;){if(n=e.match(/^(\s*)([^{}\[\]:,?*+()!|\/\s]+|[{}\[\]:,?*+()!|\/])(\s*)/),null===n)throw new Error('validate: parse error: cannot further canonicalize: "'+e+'"');t.addToken(r,r+n[1].length,r+n[1].length+n[2].length-1,r+n[0].length-1,n[2]),e=e.substr(n[0].length),r+=n[0].length}return t.addToken(r,r,r,r,null),t};exports.validate_tokenize=validate_tokenize;
},{"./ducky-1-util.js":2}],9:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var validate_parse={parse:function(e){if(e.len<=0)return null;var r=this.parse_spec(e),a=e.peek();if(null!==a)throw new Error('validate: parse error: unexpected token (expected end-of-string): "'+e.ctx()+'"');return r},parse_spec:function(e){if(e.len<=0)return null;var r=void 0,a=e.peek();if("!"===a)r=this.parse_not(e);else if("("===a)r=this.parse_group(e);else if("{"===a)r=this.parse_hash(e);else if("["===a)r=this.parse_array(e);else if(a.match(/^(?:null|undefined|boolean|number|string|function|object)$/))r=this.parse_primary(e);else if("any"===a)r=this.parse_any(e);else{if(!a.match(/^[_a-zA-Z$][_a-zA-Z$0-9]*(?:\.[_a-zA-Z$][_a-zA-Z$0-9]*)*$/))throw new Error('validate: parse error: invalid token symbol: "'+e.ctx()+'"');r=this.parse_class(e)}return r},parse_not:function(e){e.consume("!");var r=this.parse_spec(e);return r={type:"not",op:r}},parse_group:function(e){e.consume("(");for(var r=this.parse_spec(e);"|"===e.peek();){e.consume("|");var a=this.parse_spec(e);r={type:"or",op1:r,op2:a}}return e.consume(")"),r},parse_hash:function(e){e.consume("{");for(var r=[];"}"!==e.peek();){var a=this.parse_key(e),s=this.parse_arity(e,"?");e.consume(":");var t=this.parse_spec(e);if(r.push({type:"element",key:a,arity:s,element:t}),","!==e.peek())break;e.skip()}var n={type:"hash",elements:r};return e.consume("}"),n},parse_array:function(e){e.consume("[");for(var r=[];"]"!==e.peek();){var a=this.parse_spec(e),s=this.parse_arity(e,"?*+");if(r.push({type:"element",element:a,arity:s}),","!==e.peek())break;e.skip()}var t={type:"array",elements:r};return e.consume("]"),t},parse_primary:function(e){var r=e.peek();if(!r.match(/^(?:null|undefined|boolean|number|string|function|object)$/))throw new Error('validate: parse error: invalid primary type "'+r+'"');return e.skip(),{type:"primary",name:r}},parse_any:function(e){var r=e.peek();if("any"!==r)throw new Error('validate: parse error: invalid any type "'+r+'"');return e.skip(),{type:"any"}},parse_class:function(e){var r=e.peek();if(!r.match(/^[_a-zA-Z$][_a-zA-Z$0-9]*(?:\.[_a-zA-Z$][_a-zA-Z$0-9]*)*$/))throw new Error('validate: parse error: invalid class type "'+r+'"');return e.skip(),{type:"class",name:r}},parse_arity:function(e,r){var a=[1,1];if(e.len>=5&&"{"===e.peek(0)&&e.peek(1).match(/^[0-9]+$/)&&","===e.peek(2)&&e.peek(3).match(/^(?:[0-9]+|oo)$/)&&"}"===e.peek(4))a=[parseInt(e.peek(1),10),"oo"===e.peek(3)?Number.MAX_VALUE:parseInt(e.peek(3),10)],e.skip(5);else if(e.len>=1&&1===e.peek().length&&r.indexOf(e.peek())>=0){var s=e.peek();switch(s){case"?":a=[0,1];break;case"*":a=[0,Number.MAX_VALUE];break;case"+":a=[1,Number.MAX_VALUE]}e.skip()}return a},parse_key:function(e){var r=e.peek();if(!r.match(/^(?:[_a-zA-Z$][_a-zA-Z$0-9]*|@)$/))throw new Error('validate: parse error: invalid key "'+r+'"');return e.skip(),r}};exports.validate_parse=validate_parse;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var validate_parse={parse:function(e){if(e.len<=0)return null;var r=this.parse_spec(e),a=e.peek();if(null!==a)throw new Error('validate: parse error: unexpected token (expected end-of-string): "'+e.ctx()+'"');return r},parse_spec:function(e){if(e.len<=0)return null;var r=void 0,a=e.peek();if("!"===a)r=this.parse_not(e);else if("("===a)r=this.parse_group(e);else if("{"===a)r=this.parse_hash(e);else if("["===a)r=this.parse_array(e);else if("/"===a)r=this.parse_regexp(e);else if(a.match(/^(?:null|undefined|boolean|number|string|function|object)$/))r=this.parse_primary(e);else if("any"===a)r=this.parse_any(e);else{if(!a.match(/^[_a-zA-Z$][_a-zA-Z$0-9]*(?:\.[_a-zA-Z$][_a-zA-Z$0-9]*)*$/))throw new Error('validate: parse error: invalid token symbol: "'+e.ctx()+'"');r=this.parse_class(e)}return r},parse_not:function(e){e.consume("!");var r=this.parse_spec(e);return r={type:"not",op:r}},parse_group:function(e){e.consume("(");for(var r=this.parse_spec(e);"|"===e.peek();){e.consume("|");var a=this.parse_spec(e);r={type:"or",op1:r,op2:a}}return e.consume(")"),r},parse_hash:function(e){e.consume("{");for(var r=[];"}"!==e.peek();){var a=this.parse_key(e),s=this.parse_arity(e,"?");e.consume(":");var p=this.parse_spec(e);if(r.push({type:"element",key:a,arity:s,element:p}),","!==e.peek())break;e.skip()}var t={type:"hash",elements:r};return e.consume("}"),t},parse_array:function(e){e.consume("[");for(var r=[];"]"!==e.peek();){var a=this.parse_spec(e),s=this.parse_arity(e,"?*+");if(r.push({type:"element",element:a,arity:s}),","!==e.peek())break;e.skip()}var p={type:"array",elements:r};return e.consume("]"),p},parse_regexp:function(e){e.consume("/");for(var r="";e.len>=1&&"/"!==e.peek(0);)e.len>=2&&"\\"===e.peek(0)&&"/"===e.peek(1)?(r+=e.peek(1),e.skip(2)):(r+=e.peek(0),e.skip(1));e.consume("/");var a=void 0;try{a=new RegExp(r)}catch(e){throw new Error('validate: parse error: invalid regular expression "'+r+'": '+e.message)}var s={type:"regexp",regexp:a};return s},parse_primary:function(e){var r=e.peek();if(!r.match(/^(?:null|undefined|boolean|number|string|function|object)$/))throw new Error('validate: parse error: invalid primary type "'+r+'"');return e.skip(),{type:"primary",name:r}},parse_any:function(e){var r=e.peek();if("any"!==r)throw new Error('validate: parse error: invalid any type "'+r+'"');return e.skip(),{type:"any"}},parse_class:function(e){var r=e.peek();if(!r.match(/^[_a-zA-Z$][_a-zA-Z$0-9]*(?:\.[_a-zA-Z$][_a-zA-Z$0-9]*)*$/))throw new Error('validate: parse error: invalid class type "'+r+'"');return e.skip(),{type:"class",name:r}},parse_arity:function(e,r){var a=[1,1];if(e.len>=5&&"{"===e.peek(0)&&e.peek(1).match(/^[0-9]+$/)&&","===e.peek(2)&&e.peek(3).match(/^(?:[0-9]+|oo)$/)&&"}"===e.peek(4))a=[parseInt(e.peek(1),10),"oo"===e.peek(3)?Number.MAX_VALUE:parseInt(e.peek(3),10)],e.skip(5);else if(e.len>=3&&"{"===e.peek(0)&&e.peek(1).match(/^[0-9]+$/)&&"}"===e.peek(2))a=[parseInt(e.peek(1),10),parseInt(e.peek(1),10)],e.skip(3);else if(e.len>=1&&1===e.peek().length&&r.indexOf(e.peek())>=0){var s=e.peek();switch(s){case"?":a=[0,1];break;case"*":a=[0,Number.MAX_VALUE];break;case"+":a=[1,Number.MAX_VALUE]}e.skip()}return a},parse_key:function(e){var r=e.peek();if(!r.match(/^(?:[_a-zA-Z$][_a-zA-Z$0-9]*|@)$/))throw new Error('validate: parse error: invalid key "'+r+'"');return e.skip(),r}};exports.validate_parse=validate_parse;
},{}],10:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validate_execute=void 0;var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_slicedToArray=function(){function e(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(r=(a=i.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(l){o=!0,u=l}finally{try{!r&&i["return"]&&i["return"]()}finally{if(o)throw u}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_ducky2Registry2Api=_dereq_("./ducky-2-registry-2-api.js"),errCtx=function(e,t){return""===e?"mismatch at root-level: "+t:'mismatch at path "'+e+'": '+t},validate_execute={exec_spec:function(e,t,n,r){var o=!1;if(null!==t)switch(t.type){case"not":o=this.exec_not(e,t,n,r);break;case"or":o=this.exec_or(e,t,n,r);break;case"hash":o=this.exec_hash(e,t,n,r);break;case"array":o=this.exec_array(e,t,n,r);break;case"primary":o=this.exec_primary(e,t,n,r);break;case"class":o=this.exec_class(e,t,n,r);break;case"any":o=!0;break;default:throw new Error('validate: invalid validation AST: node has unknown type "'+t.type+'"')}return o},exec_not:function(e,t,n,r){var o=null!==r?[]:null,u=this.exec_spec(e,t.op,n,o);return u=!u,u||null===r||o.forEach(function(e){return r.push(e)}),u},exec_or:function(e,t,n,r){var o=null!==r?[[],[]]:[null,null],u=_slicedToArray(o,2),a=u[0],i=u[1],l=this.exec_spec(e,t.op1,n,a),c=this.exec_spec(e,t.op2,n,i),f=l||c;return f||null===r||(a.forEach(function(e){return r.push(e)}),i.forEach(function(e){return r.push(e)})),f},exec_hash:function(e,t,n,r){var o=void 0,u=void 0,a="object"===("undefined"==typeof e?"undefined":_typeof(e)),i={},l=void 0;if(a||null===r){if(a){var c=!1;for(l in e)if(Object.hasOwnProperty.call(e,l)&&Object.propertyIsEnumerable.call(e,l)&&"constructor"!==l&&"prototype"!==l){c=!0;break}for(o=0;o<t.elements.length;o++)if(u=t.elements[o],i[u.key]=u.element,u.arity[0]>0&&("@"===u.key&&!c||"@"!==u.key&&"undefined"==typeof e[u.key])){if(a=!1,null===r)break;"@"===u.key?r.push(errCtx(n,"mandatory element under arbitrary key not found")):r.push(errCtx(n,'mandatory element under key "'+u.key+'" not found'))}}}else r.push('mismatch at path "'+n+'": found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected hash');if(a||null!==r){var f=""!==n?".":"";for(l in e)if(Object.hasOwnProperty.call(e,l)&&Object.propertyIsEnumerable.call(e,l)&&"constructor"!==l&&"prototype"!==l&&("undefined"==typeof i[l]&&"undefined"==typeof i["@"]&&null!==r&&r.push(errCtx(n,'element under key "'+l+'" unexpected')),!("undefined"!=typeof i[l]&&this.exec_spec(e[l],i[l],""+n+f+l,r)||"undefined"!=typeof i["@"]&&this.exec_spec(e[l],i["@"],""+n+f+l,r)||(a=!1,null!==r))))break}return a},exec_array:function(e,t,n,r){var o=void 0,u=void 0,a="object"===("undefined"==typeof e?"undefined":_typeof(e))&&e instanceof Array;if(a||null===r){if(a){var i=0,l=null;for(o=0;o<t.elements.length;o++){u=t.elements[o];var c=0;for(l=null!==r?[]:null;c<u.arity[1]&&i<e.length&&this.exec_spec(e[i],u.element,n+"["+i+"]",l);)c++,i++;if(c<u.arity[0]){null!==r&&r.push(errCtx(n+"["+i+"]","found only "+c+" elements of array element type #"+o+", "+("expected at least "+u.arity[0]+" elements"))),a=!1;break}}!a&&null!==l&&l.length>0?null!==r&&l.forEach(function(e){return r.push(e)}):i<e.length&&(null!==r&&r.push(errCtx(n,"matched only "+i+" elements, "+("but "+e.length+" elements found"))),a=!1)}}else r.push(errCtx(n,'found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected array'));return a},exec_primary:function(e,t,n,r){var o="null"===t.name&&null===e||("undefined"==typeof e?"undefined":_typeof(e))===t.name;return o||null===r||r.push(errCtx(n,'found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected primary type "'+t.name+'"')),o},exec_class:function(e,t,n,r){var o=(0,_ducky2Registry2Api.registered)(t.name),u="object"===("undefined"==typeof e?"undefined":_typeof(e))&&(Object.prototype.toString.call(e)==="[object "+t.name+"]"||"function"==typeof o&&e instanceof o);return u||null===r||r.push(errCtx(n,'found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected class type "'+t.name+'"')),u}};exports.validate_execute=validate_execute;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validate_execute=void 0;var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_slicedToArray=function(){function e(e,t){var n=[],r=!0,o=!1,u=void 0;try{for(var a,i=e[Symbol.iterator]();!(r=(a=i.next()).done)&&(n.push(a.value),!t||n.length!==t);r=!0);}catch(e){o=!0,u=e}finally{try{!r&&i.return&&i.return()}finally{if(o)throw u}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_ducky2Registry2Api=_dereq_("./ducky-2-registry-2-api.js"),errCtx=function(e,t){return""===e?"mismatch at root-level: "+t:'mismatch at path "'+e+'": '+t},validate_execute={exec_spec:function(e,t,n,r){var o=!1;if(null!==t)switch(t.type){case"not":o=this.exec_not(e,t,n,r);break;case"or":o=this.exec_or(e,t,n,r);break;case"hash":o=this.exec_hash(e,t,n,r);break;case"array":o=this.exec_array(e,t,n,r);break;case"regexp":o=this.exec_regexp(e,t,n,r);break;case"primary":o=this.exec_primary(e,t,n,r);break;case"class":o=this.exec_class(e,t,n,r);break;case"any":o=!0;break;default:throw new Error('validate: invalid validation AST: node has unknown type "'+t.type+'"')}return o},exec_not:function(e,t,n,r){var o=null!==r?[]:null,u=this.exec_spec(e,t.op,n,o);return u=!u,u||null===r||o.forEach(function(e){return r.push(e)}),u},exec_or:function(e,t,n,r){var o=null!==r?[[],[]]:[null,null],u=_slicedToArray(o,2),a=u[0],i=u[1],l=this.exec_spec(e,t.op1,n,a),c=this.exec_spec(e,t.op2,n,i),f=l||c;return f||null===r||(a.forEach(function(e){return r.push(e)}),i.forEach(function(e){return r.push(e)})),f},exec_hash:function(e,t,n,r){var o=void 0,u=void 0,a="object"===("undefined"==typeof e?"undefined":_typeof(e)),i={},l=void 0;if(a||null===r){if(a){var c=!1;for(l in e)if(Object.hasOwnProperty.call(e,l)&&Object.propertyIsEnumerable.call(e,l)&&"constructor"!==l&&"prototype"!==l){c=!0;break}for(o=0;o<t.elements.length;o++)if(u=t.elements[o],i[u.key]=u.element,u.arity[0]>0&&("@"===u.key&&!c||"@"!==u.key&&"undefined"==typeof e[u.key])){if(a=!1,null===r)break;"@"===u.key?r.push(errCtx(n,"mandatory element under arbitrary key not found")):r.push(errCtx(n,'mandatory element under key "'+u.key+'" not found'))}}}else r.push('mismatch at path "'+n+'": found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected hash');if(a||null!==r){var f=""!==n?".":"";for(l in e)if(Object.hasOwnProperty.call(e,l)&&Object.propertyIsEnumerable.call(e,l)&&"constructor"!==l&&"prototype"!==l&&("undefined"==typeof i[l]&&"undefined"==typeof i["@"]&&null!==r&&r.push(errCtx(n,'element under key "'+l+'" unexpected')),!("undefined"!=typeof i[l]&&this.exec_spec(e[l],i[l],""+n+f+l,r)||"undefined"!=typeof i["@"]&&this.exec_spec(e[l],i["@"],""+n+f+l,r)||(a=!1,null!==r))))break}return a},exec_array:function(e,t,n,r){var o=void 0,u=void 0,a="object"===("undefined"==typeof e?"undefined":_typeof(e))&&e instanceof Array;if(a||null===r){if(a){var i=0,l=null;for(o=0;o<t.elements.length;o++){u=t.elements[o];var c=0;for(l=null!==r?[]:null;c<u.arity[1]&&i<e.length&&this.exec_spec(e[i],u.element,n+"["+i+"]",l);)c++,i++;if(c<u.arity[0]){null!==r&&r.push(errCtx(n+"["+i+"]","found only "+c+" elements of array element type #"+o+", "+("expected at least "+u.arity[0]+" elements"))),a=!1;break}}!a&&null!==l&&l.length>0?null!==r&&l.forEach(function(e){return r.push(e)}):i<e.length&&(null!==r&&r.push(errCtx(n,"matched only "+i+" elements, "+("but "+e.length+" elements found"))),a=!1)}}else r.push(errCtx(n,'found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected array'));return a},exec_regexp:function(e,t,n,r){var o=t.regexp.test(e.toString());return o||null===r||r.push(errCtx(n,"value failed to match regular expression "+t.regexp.toString())),o},exec_primary:function(e,t,n,r){var o="null"===t.name&&null===e||("undefined"==typeof e?"undefined":_typeof(e))===t.name;return o||null===r||r.push(errCtx(n,'found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected primary type "'+t.name+'"')),o},exec_class:function(e,t,n,r){var o=(0,_ducky2Registry2Api.registered)(t.name),u="object"===("undefined"==typeof e?"undefined":_typeof(e))&&(Object.prototype.toString.call(e)==="[object "+t.name+"]"||"function"==typeof o&&e instanceof o);return u||null===r||r.push(errCtx(n,'found type "'+("undefined"==typeof e?"undefined":_typeof(e))+'", expected class type "'+t.name+'"')),u}};exports.validate_execute=validate_execute;
},{"./ducky-2-registry-2-api.js":4}],11:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validate=void 0;var _ducky4Validate1Tokenize=_dereq_("./ducky-4-validate-1-tokenize.js"),_ducky4Validate2Parse=_dereq_("./ducky-4-validate-2-parse.js"),_ducky4Validate3Execute=_dereq_("./ducky-4-validate-3-execute.js"),validate_cache={},validate=function e(t,a,i){if(arguments.length<2)throw new Error("validate: invalid number of arguments: "+arguments.length+" (minimum of 2 expected)");if(arguments.length>3)throw new Error("validate: invalid number of arguments: "+arguments.length+" (maximum of 3 expected)");if("string"!=typeof a)throw new Error('validate: invalid specification argument: "'+a+'" (string expected)');var r=validate_cache[a];return"undefined"==typeof r&&(r=e.compile(a),validate_cache[a]=r),e.execute(t,r,i)};validate.compile=function(e){if(1!==arguments.length)throw new Error("validate: invalid number of arguments: "+arguments.length+" (exactly 1 expected)");if("string"!=typeof e)throw new Error('validate: invalid specification argument: "'+e+'" (string expected)');var t=(0,_ducky4Validate1Tokenize.validate_tokenize)(e),a=_ducky4Validate2Parse.validate_parse.parse(t);return a},validate.execute=function(e,t,a){if(arguments.length<2)throw new Error("validate: invalid number of arguments: "+arguments.length+" (minimum of 2 expected)");if(arguments.length>3)throw new Error("validate: invalid number of arguments: "+arguments.length+" (maximum of 3 expected)");return(arguments.length<3||"undefined"==typeof a)&&(a=null),_ducky4Validate3Execute.validate_execute.exec_spec(e,t,"",a)},exports.validate=validate;
},{"./ducky-4-validate-1-tokenize.js":8,"./ducky-4-validate-2-parse.js":9,"./ducky-4-validate-3-execute.js":10}],12:[function(_dereq_,module,exports){
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.params=void 0;var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},_ducky4Validate4Api=_dereq_("./ducky-4-validate-4-api.js"),params_is_name_based=function(e,r){var a=!1;if(1===e.length&&"object"===_typeof(e[0])){a=!0;for(var t in e[0])Object.hasOwnProperty.call(e[0],t)||"undefined"==typeof r[t]&&(a=!1)}return a},params_check_validity=function(e,r,a,t,n){if("undefined"!=typeof t&&!(0,_ducky4Validate4Api.validate)(a,t))throw new Error(e+': parameter "'+r+'" has '+(n+" "+JSON.stringify(a)+', which does not validate against "'+t+'"'))},params=function e(r,a,t){var e={},n=void 0;for(n in t)Object.hasOwnProperty.call(t,n)&&"undefined"!=typeof t[n].def&&("undefined"!=typeof t[n].valid&&params_check_validity(r,n,t[n].def,t[n].valid,"default value"),e[n]=t[n].def);if(params_is_name_based(a,t)){a=a[0];for(n in a)if(Object.hasOwnProperty.call(a,n)){if("undefined"==typeof t[n])throw new Error(r+': unknown parameter "'+n+'"');params_check_validity(r,n,a[n],t[n].valid,"value"),e[n]=a[n]}for(n in t)if(Object.hasOwnProperty.call(t,n)&&"undefined"!=typeof t[n].req&&t[n].req&&"undefined"==typeof a[n])throw new Error(r+': required parameter "'+n+'" missing')}else{var o=0,i=0,f={};for(n in t)Object.hasOwnProperty.call(t,n)&&"undefined"!=typeof t[n].pos&&(f[t[n].pos]=n,"number"==typeof t[n].pos&&o++,"undefined"!=typeof t[n].req&&t[n].req&&i++);if(a.length<i)throw new Error(r+": invalid number of arguments (at least "+i+" required)");for(var d=0;o>d&&d<a.length;)params_check_validity(r,f[d],a[d],t[f[d]].valid,"value"),e[f[d]]=a[d],d++;if(d<a.length){if("undefined"==typeof f["..."])throw new Error(r+": too many arguments provided");for(var p=[];d<a.length;)p.push(a[d++]);params_check_validity(r,f["..."],p,t[f["..."]].valid,"value"),e[f["..."]]=p}}return e};exports.params=params;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.params=void 0;var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_ducky4Validate4Api=_dereq_("./ducky-4-validate-4-api.js"),params_is_name_based=function(e,r){var a=!1;if(1===e.length&&"object"===_typeof(e[0])){a=!0;for(var t in e[0])Object.hasOwnProperty.call(e[0],t)||"undefined"==typeof r[t]&&(a=!1)}return a},params_check_validity=function(e,r,a,t,o){if("undefined"!=typeof t&&!(0,_ducky4Validate4Api.validate)(a,t))throw new Error(e+': parameter "'+r+'" has '+(o+" "+JSON.stringify(a)+', which does not validate against "'+t+'"'))},params=function e(r,a,t){var e={},o=void 0;for(o in t)Object.hasOwnProperty.call(t,o)&&"undefined"!=typeof t[o].def&&("undefined"!=typeof t[o].valid&&params_check_validity(r,o,t[o].def,t[o].valid,"default value"),e[o]=t[o].def);if(params_is_name_based(a,t)){a=a[0];for(o in a)if(Object.hasOwnProperty.call(a,o)){if("undefined"==typeof t[o])throw new Error(r+': unknown parameter "'+o+'"');params_check_validity(r,o,a[o],t[o].valid,"value"),e[o]=a[o]}for(o in t)if(Object.hasOwnProperty.call(t,o)&&"undefined"!=typeof t[o].req&&t[o].req&&"undefined"==typeof a[o])throw new Error(r+': required parameter "'+o+'" missing')}else{var n=0,i=0,f={};for(o in t)Object.hasOwnProperty.call(t,o)&&"undefined"!=typeof t[o].pos&&(f[t[o].pos]=o,"number"==typeof t[o].pos&&n++,"undefined"!=typeof t[o].req&&t[o].req&&i++);if(a.length<i)throw new Error(r+": invalid number of arguments (at least "+i+" required)");for(var d=0;d<n&&d<a.length;)params_check_validity(r,f[d],a[d],t[f[d]].valid,"value"),e[f[d]]=a[d],d++;if(d<a.length){if("undefined"==typeof f["..."])throw new Error(r+": too many arguments provided");for(var p=[];d<a.length;)p.push(a[d++]);params_check_validity(r,f["..."],p,t[f["..."]].valid,"value"),e[f["..."]]=p}}return e};exports.params=params;
},{"./ducky-4-validate-4-api.js":11}],13:[function(_dereq_,module,exports){

@@ -55,0 +55,0 @@ "use strict";var _ducky0Version=_dereq_("./ducky-0-version.js"),_ducky2Registry2Api=_dereq_("./ducky-2-registry-2-api.js"),_ducky3Select3Api=_dereq_("./ducky-3-select-3-api.js"),_ducky4Validate4Api=_dereq_("./ducky-4-validate-4-api.js"),_ducky5Params=_dereq_("./ducky-5-params.js");module.exports={version:_ducky0Version.version,register:_ducky2Registry2Api.register,unregister:_ducky2Registry2Api.unregister,select:_ducky3Select3Api.select,validate:_ducky4Validate4Api.validate,params:_ducky5Params.params};

@@ -5,3 +5,3 @@ {

"description": "Duck-Typed Value Handling for JavaScript",
"version": "2.4.0",
"version": "2.5.0",
"license": "MIT",

@@ -25,19 +25,19 @@ "author": {

"devDependencies": {
"grunt": "~0.4.5",
"grunt-cli": "~0.1.13",
"grunt": "~1.0.1",
"grunt-cli": "~1.2.0",
"grunt-contrib-jshint": "~1.0.0",
"grunt-contrib-uglify": "~1.0.0",
"grunt-contrib-uglify": "~2.0.0",
"grunt-contrib-clean": "~1.0.0",
"grunt-eslint": "~18.0.0",
"babel-eslint": "~5.0.0",
"grunt-eslint": "~19.0.0",
"babel-eslint": "~7.1.1",
"estraverse-fb": "~1.3.1",
"grunt-browserify": "~5.0.0",
"grunt-mocha-test": "~0.12.7",
"mocha": "~2.4.5",
"grunt-mocha-test": "~0.13.2",
"mocha": "~3.1.2",
"chai": "~3.5.0",
"chai-fuzzy": "~1.6.0",
"chai-fuzzy": "~1.6.1",
"underscore": "~1.8.3",
"babelify": "~7.2.0",
"babel-preset-es2015": "~6.6.0",
"minifyify": "~7.3.2",
"babelify": "~7.3.0",
"babel-preset-es2015": "~6.18.0",
"minifyify": "~7.3.4",
"browserify-replace": "~0.9.0",

@@ -44,0 +44,0 @@ "browserify-header": "~0.9.2",

@@ -123,3 +123,3 @@

------------ | --- | -----------------------------
spec | ::= | not &#124; alt &#124; hash &#124; array &#124; any &#124; primary &#124; class
spec | ::= | not &#124; alt &#124; hash &#124; array &#124; any &#124; regexp &#124; primary &#124; class
not | ::= | `"!"` spec

@@ -133,2 +133,3 @@ alt | ::= | `"("` spec (`"`&#124;`"` spec)\* `")"`

any | ::= | `"any"`
regexp | ::= | `/^\/(?:\\\/|.)*\/$/`
primary | ::= | `/^(?:null|undefined|boolean|number|string|function|object)$/`

@@ -135,0 +136,0 @@ class | ::= | `/^[_a-zA-Z$][_a-zA-Z$0-9]\*(?:\.[_a-zA-Z$][_a-zA-Z$0-9]\*)\*$/`

@@ -38,3 +38,3 @@ /*

while (spec !== "") {
m = spec.match(/^(\s*)([^{}\[\]:,?*+()!|\s]+|[{}\[\]:,?*+()!|])(\s*)/)
m = spec.match(/^(\s*)([^{}\[\]:,?*+()!|/\s]+|[{}\[\]:,?*+()!|/])(\s*)/)
if (m === null)

@@ -41,0 +41,0 @@ throw new Error(`validate: parse error: cannot further canonicalize: "${spec}"`)

@@ -51,2 +51,4 @@ /*

ast = this.parse_array(token)
else if (symbol === "/")
ast = this.parse_regexp(token)
else if (symbol.match(/^(?:null|undefined|boolean|number|string|function|object)$/))

@@ -122,2 +124,28 @@ ast = this.parse_primary(token)

/* parse regular expression specification */
parse_regexp (token) {
token.consume("/")
let text = ""
while (token.len >= 1) {
if (token.peek(0) === "/")
break
else if (token.len >= 2 && token.peek(0) === "\\" && token.peek(1) === "/") {
text += token.peek(1)
token.skip(2)
}
else {
text += token.peek(0)
token.skip(1)
}
}
token.consume("/")
let regexp
try { regexp = new RegExp(text) }
catch (ex) {
throw new Error(`validate: parse error: invalid regular expression "${text}": ${ex.message}`)
}
let ast = { type: "regexp", regexp: regexp }
return ast
},
/* parse primary type specification */

@@ -167,2 +195,12 @@ parse_primary (token) {

}
else if ( token.len >= 3
&& token.peek(0) === "{"
&& token.peek(1).match(/^[0-9]+$/)
&& token.peek(2) === "}" ) {
arity = [
parseInt(token.peek(1), 10),
parseInt(token.peek(1), 10)
]
token.skip(3)
}
else if (

@@ -169,0 +207,0 @@ token.len >= 1

@@ -45,2 +45,3 @@ /*

case "array": valid = this.exec_array( value, node, path, errors); break
case "regexp": valid = this.exec_regexp( value, node, path, errors); break
case "primary": valid = this.exec_primary(value, node, path, errors); break

@@ -199,2 +200,10 @@ case "class": valid = this.exec_class( value, node, path, errors); break

/* validate regular expression */
exec_regexp (value, node, path, errors) {
let valid = node.regexp.test(value.toString())
if (!valid && errors !== null)
errors.push(errCtx(path, `value failed to match regular expression ${node.regexp.toString()}`))
return valid
},
/* validate standard JavaScript type */

@@ -201,0 +210,0 @@ exec_primary (value, node, path, errors) {

@@ -51,2 +51,7 @@ /*

})
it("should validate stand-alone string with regular expression", function () {
expect(validate("foo", "/foo/")).to.be.true
expect(validate("foo", "/fo+/")).to.be.true
expect(validate("foo", "/bar/")).to.be.false
})
it("should validate stand-alone object", function () {

@@ -120,4 +125,4 @@ expect(validate(null, "object")).to.be.true

expect(validate(
{ foo: { bar: "bar", baz: [ 7, 42 ], quux: "quux" } },
"{ foo: { bar: string, baz: [ number* ], quux?: string } }"
{ foo: { bar: [ "foo", "bar" ], baz: [ 7, 42 ], quux: "quux" } },
"{ foo: { bar: [ /^(?:foo|bar)$/{2} ], baz: [ number* ], quux?: string } }"
)).to.be.true

@@ -124,0 +129,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

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