UNPKG

ducky

Version:

Duck-Typed Value Handling for JavaScript

57 lines (55 loc) 28.3 kB
/*! ** Ducky -- Duck-Typed Value Handling for JavaScript ** Copyright (c) 2010-2023 Dr. Ralf S. Engelschall <rse@engelschall.com> ** ** Permission is hereby granted, free of charge, to any person obtaining ** a copy of this software and associated documentation files (the ** "Software"), to deal in the Software without restriction, including ** without limitation the rights to use, copy, modify, merge, publish, ** distribute, sublicense, and/or sell copies of the Software, and to ** permit persons to whom the Software is furnished to do so, subject to ** the following conditions: ** ** The above copyright notice and this permission notice shall be included ** in all copies or substantial portions of the Software. ** ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE ** SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ (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(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.version=void 0;var version={major:2,minor:8,micro:0,date:20230122};exports.version=version; },{}],2:[function(_dereq_,module,exports){ "use strict";function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var o=0;o<e.length;o++){var r=e[o];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,_toPropertyKey(r.key),r)}}function _createClass(t,e,o){return e&&_defineProperties(t.prototype,e),o&&_defineProperties(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function _toPropertyKey(t){var e=_toPrimitive(t,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var r=o.call(t,e||"default");if("object"!==_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.Token=void 0;var Token=function(){function t(){_classCallCheck(this,t),this.name="",this.text="",this.tokens=[],this.pos=0,this.len=0}return _createClass(t,[{key:"setName",value:function(t){this.name=t}},{key:"setText",value:function(t){this.text=t}},{key:"addToken",value:function(t,e,o,r,n){this.tokens.push({b1:t,b2:e,e2:o,e1:r,symbol:n}),this.len++}},{key:"peek",value:function(t){if(void 0===t&&(t=0),t>=this.len)throw new Error("".concat(this.name,": parse error: not enough tokens"));return this.tokens[this.pos+t].symbol}},{key:"skip",value:function(t){if(void 0===t&&(t=1),t>this.len)throw new Error("".concat(this.name,": parse error: not enough tokens available to skip: ").concat(this.ctx()));this.pos+=t,this.len-=t}},{key:"consume",value:function(t){if(this.len<=0)throw new Error("".concat(this.name,": parse error: no more tokens available to consume: ").concat(this.ctx()));if(this.tokens[this.pos].symbol!==t)throw new Error("".concat(this.name,': parse error: expected token symbol "').concat(t,'": ').concat(this.ctx()));this.pos++,this.len--}},{key:"ctx",value:function(t){void 0===t&&(t=78);var e=this.tokens[this.pos],o="<"+this.text.substr(e.b2,e.e2-e.b2+1)+">";o=this.text.substr(e.b1,e.b2-e.b1)+o;var r=t-(o+=this.text.substr(e.e2+1,e.e1-e.e2)).length;if(r>0){var n,i;if(r=Math.floor(r/2),this.pos>0){var s=0;for(n=this.pos-1;n>=0&&(e=this.tokens[n],!((s+=(i=this.text.substr(e.b1,e.e1-e.b1+1)).length)>r));n--)o=i+o;n>0&&(o="[...]"+o)}if(this.len>1){var a=0;for(n=this.pos+1;n<this.pos+this.len&&(e=this.tokens[n],!((a+=(i=this.text.substr(e.b1,e.e1-e.b1+1)).length)>r));n++)o+=i;n<this.pos+this.len&&(o+="[...]")}}return o=o.replace(/\r/,"\\r").replace(/\n/,"\\n").replace(/\t/,"\\t")}}]),t}();exports.Token=Token; },{}],3:[function(_dereq_,module,exports){ (function (global){(function (){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.registry=void 0;var registry={};exports.registry=registry;for(var std_types=["Object","Boolean","Number","String","Function","RegExp","Array","Date","Error","Set","Map","WeakMap","Promise","Proxy","Iterator"],i=0;i<std_types.length;i++)"function"==typeof global[std_types[i]]&&(registry[std_types[i]]=global[std_types[i]]); }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) },{}],4:[function(_dereq_,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unregister=exports.registered=exports.register=void 0;var _ducky2Registry1Data=_dereq_("./ducky-2-registry-1-data.js"),register=function(e,r){if(2!==arguments.length)throw new Error("register: invalid number of arguments: ".concat(arguments.length," (exactly 2 expected)"));if("string"!=typeof e)throw new Error('register: invalid name argument: "'.concat(e,'" (string expected)'));if("function"!=typeof r)throw new Error('register: invalid type argument: "'.concat(r,'" (function object expected)'));if(void 0!==_ducky2Registry1Data.registry[e])throw new Error('register: type already registered under name: "'.concat(e,'"'));_ducky2Registry1Data.registry[e]=r};exports.register=register;var unregister=function(e){if(1!==arguments.length)throw new Error("unregister: invalid number of arguments: ".concat(arguments.length," (exactly 1 expected)"));if("string"!=typeof e)throw new Error('unregister: invalid name argument: "'.concat(e,'" (string expected)'));if(void 0===_ducky2Registry1Data.registry[e])throw new Error('unregister: no type registered under name: "'.concat(e,'"'));delete _ducky2Registry1Data.registry[e]};exports.unregister=unregister;var registered=function(e){if(1!==arguments.length)throw new Error("registered: invalid number of arguments: ".concat(arguments.length," (exactly 1 expected)"));if("string"!=typeof e)throw new Error('registered: invalid name argument: "'.concat(e,'" (string expected)'));return _ducky2Registry1Data.registry[e]};exports.registered=registered; },{"./ducky-2-registry-1-data.js":3}],5:[function(_dereq_,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.select_compile=void 0;var select_compile=function(e){for(var s,l=[],r=0,t=e;""!==t;){if(null!==(s=t.match(/^\s*(?:\.)?\s*([a-zA-Z$0-9_][a-zA-Z$0-9_:-]*)/)))l.push(s[1]);else if(null!==(s=t.match(/^\s*\[\s*(\d+|\*{1,2})\s*\]/)))l.push(s[1]);else if(null!==(s=t.match(/^\s*\[\s*"((?:\\"|.)*?)"\s*\]/)))l.push(s[1].replace(/\\"/g,'"'));else{if(null===(s=t.match(/^\s*\[\s*'((?:\\'|.)*?)'\s*\]/))){if(null!==(s=t.match(/^\s+$/)))break;throw new Error("select: parse error: invalid character at: "+e.substr(0,r)+"<"+t.substr(0,1)+">"+t.substr(1))}l.push(s[1].replace(/\\'/g,"'"))}r+=s[0].length,t=t.substr(s[0].length)}return l};exports.select_compile=select_compile; },{}],6:[function(_dereq_,module,exports){ "use strict";function _typeof(e){return(_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})(e)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.select_execute=void 0;var 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"!==_typeof(e))throw new Error("select: cannot further dereference: no more intermediate objects in path");e=e[t[o++]]}if("object"!==_typeof(e))throw new Error("select: cannot further dereference: no object at end of path");var r=e[t[o]];if(3===arguments.length){var n=arguments[2];void 0===n?e instanceof Array?e.splice(parseInt(t[o],10),1):delete e[t[o]]:e[t[o]]=n}return r};exports.select_execute=select_execute; },{}],7:[function(_dereq_,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.select=void 0;var _ducky3Select1Compile=_dereq_("./ducky-3-select-1-compile.js"),_ducky3Select2Execute=_dereq_("./ducky-3-select-2-execute.js");function _typeof(e){return(_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})(e)}var select_cache={},select=function(e,t,c){if(arguments.length<2)throw new Error("select: invalid number of arguments: ".concat(arguments.length," (minimum of 2 expected)"));if(arguments.length>3)throw new Error("select: invalid number of arguments: ".concat(arguments.length," (maximum of 3 expected)"));if("string"!=typeof t)throw new Error('select: invalid specification argument: "'.concat(t,'" (string expected)'));var o=select_cache[t];return void 0===o&&(o=(0,_ducky3Select1Compile.select_compile)(t),select_cache[t]=o),2===arguments.length?(0,_ducky3Select2Execute.select_execute)(e,o):(0,_ducky3Select2Execute.select_execute)(e,o,c)};exports.select=select,select.compile=function(e){if(1!==arguments.length)throw new Error("select: invalid number of arguments: ".concat(arguments.length," (exactly 1 expected)"));if("string"!=typeof e)throw new Error('select: invalid specification argument: "'.concat(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: ".concat(arguments.length," (minimum of 2 expected)"));if(arguments.length>3)throw new Error("select: invalid number of arguments: ".concat(arguments.length," (maximum of 3 expected)"));if(!("object"===_typeof(t)&&t instanceof Array))throw new Error('select: invalid path argument: "'.concat(t,'" (array expected)'));return _ducky3Select2Execute.select_execute.apply(void 0,arguments)}; },{"./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,n=new _ducky1Util.Token;n.setName("validate"),n.setText(e);for(var a=0;""!==e;){if(null===(t=e.match(/^(\s*)([^\\{}[\]:,?*+()!|/\s]+|[\\{}[\]:,?*+()!|/])(\s*)/)))throw new Error('validate: parse error: cannot further canonicalize: "'.concat(e,'"'));n.addToken(a,a+t[1].length,a+t[1].length+t[2].length-1,a+t[0].length-1,t[2]),e=e.substr(t[0].length),a+=t[0].length}return n.addToken(a,a,a,a,null),n};exports.validate_tokenize=validate_tokenize; },{"./ducky-1-util.js":2}],9:[function(_dereq_,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.validate_parse=void 0;var validate_parse={parse:function(e){if(e.len<=0)return null;var r=this.parse_spec(e);if(null!==e.peek())throw new Error('validate: parse error: unexpected token (expected end-of-string): "'.concat(e.ctx(),'"'));return r},parse_spec:function(e){if(e.len<=0)return null;var r,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: "'.concat(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("|"),r={type:"or",op1:r,op2:this.parse_spec(e)}}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 p={type:"hash",elements:r};return e.consume("}"),p},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_regexp:function(e){e.consume("/");for(var r,a="";e.len>=1&&"/"!==e.peek(0);)e.len>=2&&"\\"===e.peek(0)&&"/"===e.peek(1)?(a+=e.peek(1),e.skip(2)):(a+=e.peek(0),e.skip(1));e.consume("/");try{r=new RegExp(a)}catch(e){throw new Error('validate: parse error: invalid regular expression "'.concat(a,'": ').concat(e.message))}return{type:"regexp",regexp:r}},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 "'.concat(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 "'.concat(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 "'.concat(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){switch(e.peek()){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 "'.concat(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 _ducky2Registry2Api=_dereq_("./ducky-2-registry-2-api.js");function _typeof(e){return(_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})(e)}function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _iterableToArrayLimit(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,a,o,c,l=[],u=!0,i=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;u=!1}else for(;!(u=(n=o.call(r)).done)&&(l.push(n.value),l.length!==t);u=!0);}catch(e){i=!0,a=e}finally{try{if(!u&&null!=r.return&&(c=r.return(),Object(c)!==c))return}finally{if(i)throw a}}return l}}function _arrayWithHoles(e){if(Array.isArray(e))return e}var errCtx=function(e,t){return""===e?"mismatch at root-level: ".concat(t):'mismatch at path "'.concat(e,'": ').concat(t)},validate_execute={exec_spec:function(e,t,r,n){var a=!1;if(null!==t)switch(t.type){case"not":a=this.exec_not(e,t,r,n);break;case"or":a=this.exec_or(e,t,r,n);break;case"hash":a=this.exec_hash(e,t,r,n);break;case"array":a=this.exec_array(e,t,r,n);break;case"regexp":a=this.exec_regexp(e,t,r,n);break;case"primary":a=this.exec_primary(e,t,r,n);break;case"class":a=this.exec_class(e,t,r,n);break;case"any":a=!0;break;default:throw new Error('validate: invalid validation AST: node has unknown type "'.concat(t.type,'"'))}return a},exec_not:function(e,t,r,n){var a=null!==n?[]:null,o=this.exec_spec(e,t.op,r,a);return(o=!o)||null===n||a.forEach(function(e){return n.push(e)}),o},exec_or:function(e,t,r,n){var a=_slicedToArray(null!==n?[[],[]]:[null,null],2),o=a[0],c=a[1],l=this.exec_spec(e,t.op1,r,o),u=this.exec_spec(e,t.op2,r,c),i=l||u;return i||null===n||(o.forEach(function(e){return n.push(e)}),c.forEach(function(e){return n.push(e)})),i},exec_hash:function(e,t,r,n){var a,o,c,l="object"===_typeof(e)&&null!==e,u={};if(l||null===n){if(l){var i=!1;for(c in e)if(Object.hasOwnProperty.call(e,c)&&Object.propertyIsEnumerable.call(e,c)&&"constructor"!==c&&"prototype"!==c){i=!0;break}for(a=0;a<t.elements.length;a++)if(u[(o=t.elements[a]).key]=o.element,o.arity[0]>0&&("@"===o.key&&!i||"@"!==o.key&&void 0===e[o.key])){if(l=!1,null===n)break;"@"===o.key?n.push(errCtx(r,"mandatory element under arbitrary key not found")):n.push(errCtx(r,'mandatory element under key "'.concat(o.key,'" not found')))}}}else null===e?n.push('mismatch at path "'.concat(r,'": found "null", expected hash')):n.push('mismatch at path "'.concat(r,'": found type "').concat(_typeof(e),'", expected hash'));if(l||null!==n){var s=""!==r?".":"";for(c in e)if(Object.hasOwnProperty.call(e,c)&&Object.propertyIsEnumerable.call(e,c)&&"constructor"!==c&&"prototype"!==c&&(void 0===u[c]&&void 0===u["@"]&&null!==n&&n.push(errCtx(r,'element under key "'.concat(c,'" unexpected'))),!(void 0!==u[c]&&this.exec_spec(e[c],u[c],"".concat(r).concat(s).concat(c),n)||void 0!==u["@"]&&this.exec_spec(e[c],u["@"],"".concat(r).concat(s).concat(c),n)||(l=!1,null!==n))))break}return l},exec_array:function(e,t,r,n){var a,o,c="object"===_typeof(e)&&e instanceof Array;if(c||null===n){if(c){var l=0,u=null;for(a=0;a<t.elements.length;a++){o=t.elements[a];var i=0;for(u=null!==n?[]:null;i<o.arity[1]&&l<e.length&&this.exec_spec(e[l],o.element,"".concat(r,"[").concat(l,"]"),u);)i++,l++;if(i<o.arity[0]){null!==n&&n.push(errCtx("".concat(r,"[").concat(l,"]"),"found only ".concat(i," elements of array element type #").concat(a,", ")+"expected at least ".concat(o.arity[0]," elements"))),c=!1;break}}!c&&null!==u&&u.length>0?null!==n&&u.forEach(function(e){return n.push(e)}):l<e.length&&(null!==n&&n.push(errCtx(r,"matched only ".concat(l," elements, ")+"but ".concat(e.length," elements found"))),c=!1)}}else n.push(errCtx(r,'found type "'.concat(_typeof(e),'", expected array')));return c},exec_regexp:function(e,t,r,n){var a=null!==e&&"function"==typeof e.toString&&t.regexp.test(e.toString());return a||null===n||n.push(errCtx(r,"value failed to match regular expression ".concat(t.regexp.toString()))),a},exec_primary:function(e,t,r,n){var a="null"===t.name&&null===e||_typeof(e)===t.name;return a||null===n||n.push(errCtx(r,'found type "'.concat(_typeof(e),'", expected primary type "').concat(t.name,'"'))),a},exec_class:function(e,t,r,n){var a=(0,_ducky2Registry2Api.registered)(t.name),o="object"===_typeof(e)&&(Object.prototype.toString.call(e)==="[object "+t.name+"]"||"function"==typeof a&&e instanceof a);return o||null===n||n.push(errCtx(r,'found type "'.concat(_typeof(e),'", expected class type "').concat(t.name,'"'))),o}};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: ".concat(arguments.length," (minimum of 2 expected)"));if(arguments.length>3)throw new Error("validate: invalid number of arguments: ".concat(arguments.length," (maximum of 3 expected)"));if("string"!=typeof a)throw new Error('validate: invalid specification argument: "'.concat(a,'" (string expected)'));var r=validate_cache[a];return void 0===r&&(r=e.compile(a),validate_cache[a]=r),e.execute(t,r,i)};exports.validate=validate,validate.compile=function(e){if(1!==arguments.length)throw new Error("validate: invalid number of arguments: ".concat(arguments.length," (exactly 1 expected)"));if("string"!=typeof e)throw new Error('validate: invalid specification argument: "'.concat(e,'" (string expected)'));var t=(0,_ducky4Validate1Tokenize.validate_tokenize)(e);return _ducky4Validate2Parse.validate_parse.parse(t)},validate.execute=function(e,t,a){if(arguments.length<2)throw new Error("validate: invalid number of arguments: ".concat(arguments.length," (minimum of 2 expected)"));if(arguments.length>3)throw new Error("validate: invalid number of arguments: ".concat(arguments.length," (maximum of 3 expected)"));return(arguments.length<3||void 0===a)&&(a=null),_ducky4Validate3Execute.validate_execute.exec_spec(e,t,"",a)}; },{"./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 _ducky4Validate4Api=_dereq_("./ducky-4-validate-4-api.js");function _typeof(a){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a})(a)}var params_is_name_based=function(a,r){var e=!1;if(1===a.length&&"object"===_typeof(a[0]))for(var o in e=!0,a[0])Object.hasOwnProperty.call(a[0],o)||void 0===r[o]&&(e=!1);return e},params_check_validity=function(a,r,e,o,t){if(void 0!==o&&!(0,_ducky4Validate4Api.validate)(e,o))throw new Error("".concat(a,': parameter "').concat(r,'" has ')+"".concat(t," ").concat(JSON.stringify(e),', which does not validate against "').concat(o,'"'))},params=function(a,r,e){var o,t={};for(o in e)Object.hasOwnProperty.call(e,o)&&void 0!==e[o].def&&(void 0!==e[o].valid&&params_check_validity(a,o,e[o].def,e[o].valid,"default value"),t[o]=e[o].def);if(params_is_name_based(r,e)){for(o in r=r[0])if(Object.hasOwnProperty.call(r,o)){if(void 0===e[o])throw new Error("".concat(a,': unknown parameter "').concat(o,'"'));params_check_validity(a,o,r[o],e[o].valid,"value"),t[o]=r[o]}for(o in e)if(Object.hasOwnProperty.call(e,o)&&void 0!==e[o].req&&e[o].req&&void 0===r[o])throw new Error("".concat(a,': required parameter "').concat(o,'" missing'))}else{var i=0,n=0,c={};for(o in e)Object.hasOwnProperty.call(e,o)&&void 0!==e[o].pos&&(c[e[o].pos]=o,"number"==typeof e[o].pos&&i++,void 0!==e[o].req&&e[o].req&&n++);if(r.length<n)throw new Error("".concat(a,": invalid number of arguments (at least ").concat(n," required)"));for(var l=0;l<i&&l<r.length;)params_check_validity(a,c[l],r[l],e[c[l]].valid,"value"),t[c[l]]=r[l],l++;if(l<r.length){if(void 0===c["..."])throw new Error("".concat(a,": too many arguments provided"));for(var s=[];l<r.length;)s.push(r[l++]);params_check_validity(a,c["..."],s,e[c["..."]].valid,"value"),t[c["..."]]=s}}return t};exports.params=params; },{"./ducky-4-validate-4-api.js":11}],13:[function(_dereq_,module,exports){ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.options=void 0;var _ducky3Select3Api=_dereq_("./ducky-3-select-3-api.js"),_ducky4Validate4Api=_dereq_("./ducky-4-validate-4-api.js");function _typeof(o){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o})(o)}var options=function(o,t){var e={},i=[];!function t(n){var r=(0,_ducky3Select3Api.select)(o,n.join("."));if("object"!==_typeof(r)||r instanceof Array||null===r){if(!("object"===_typeof(r)&&r instanceof Array&&null!==r))throw new Error('options: invalid option specification at "'.concat(n,'" (expected object or array)'));if(r.length<=0||r.length>2)throw new Error('options: invalid option specification at "'.concat(n.join("."),'" ')+"(expected array of length 1 or 2)");if("string"!=typeof r[0])throw new Error('options: invalid option specification at "'.concat(n.join("."),'[0]" ')+"(expected string type)");for(var c=e,a=0;a<n.length-1;)"object"!==_typeof(c[n[a]])&&(c[n[a]]={}),c=c[n[a]],a++;if(2===r.length){var p=[];if(!(0,_ducky4Validate4Api.validate)(r[1],r[0],p))throw new Error('options: invalid option specification at "'.concat(n.join("."),'" ')+"(validation does not match default value): ".concat(p.join("; ")));c[n[a]]=r[1]}else i.push(n.join("."))}else for(var l in r)Object.hasOwnProperty.call(r,l)&&t(n.concat(l))}([]);var n=!0;return Object.defineProperty(e,"merge",{configurable:!1,enumerable:!1,writable:!1,value:function(t){var e=this;if(n){n=!1;for(var r=0;r<i.length;r++)if(void 0===(0,_ducky3Select3Api.select)(t,i[r]))throw new Error('options: value for required option "'.concat(i[r],'" missing'))}return function t(i,n){var r=(0,_ducky3Select3Api.select)(o,i);if("object"!==_typeof(r))throw new Error('options: value provided for unknown option "'.concat(i,'" (invalid path)'));if(r instanceof Array){var c=[];if(!(0,_ducky4Validate4Api.validate)(n,r[0],c))throw new Error('options: invalid value for option "'.concat(i,'": ').concat(c.join("; ")));(0,_ducky3Select3Api.select)(e,i,n)}else for(var a in n)Object.hasOwnProperty.call(n,a)&&t(""===i?a:"".concat(i,".").concat(a),n[a])}("",t),this}}),"object"===_typeof(t)&&null!==t&&e.merge(t),e};exports.options=options; },{"./ducky-3-select-3-api.js":7,"./ducky-4-validate-4-api.js":11}],14:[function(_dereq_,module,exports){ "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"),_ducky6Options=_dereq_("./ducky-6-options.js");module.exports={version:_ducky0Version.version,register:_ducky2Registry2Api.register,unregister:_ducky2Registry2Api.unregister,select:_ducky3Select3Api.select,validate:_ducky4Validate4Api.validate,params:_ducky5Params.params,options:_ducky6Options.options}; },{"./ducky-0-version.js":1,"./ducky-2-registry-2-api.js":4,"./ducky-3-select-3-api.js":7,"./ducky-4-validate-4-api.js":11,"./ducky-5-params.js":12,"./ducky-6-options.js":13}]},{},[14])(14) });