UNPKG

10.7 kBJavaScriptView Raw
1!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.scour=t()}}(function(){return function t(n,e,r){function i(u,s){if(!e[u]){if(!n[u]){var f="function"==typeof require&&require;if(!s&&f)return f(u,!0);if(o)return o(u,!0);var a=new Error("Cannot find module '"+u+"'");throw a.code="MODULE_NOT_FOUND",a}var c=e[u]={exports:{}};n[u][0].call(c.exports,function(t){var e=n[u][1][t];return i(e?e:t)},c,c.exports,t,n,e,r)}return e[u].exports}for(var o="function"==typeof require&&require,u=0;u<r.length;u++)i(r[u]);return i}({1:[function(t,n){"use strict";var e=t("../utilities/map");n.exports=function(t,n){var r=t.length?t.join(".")+".":"";return e(n,function(t,n){return n=(r+n).replace(/\./g,"\\.").replace(/\*\*/g,"::all::").replace(/\*/g,"::any::").replace(/::all::/g,".*").replace(/::any::/g,"[^.]+"),n=new RegExp("^"+n+"$"),[n,t]})}},{"../utilities/map":10}],2:[function(t,n){"use strict";n.exports=function(t,n){return"string"==typeof t?t.split("."):n&&1===t.length?Array.isArray(t[0])?t[0].map(function(t){return""+t}):"number"==typeof t[0]?[""+t[0]]:(""+t[0]).split("."):(n&&(t=[].slice.call(t)),t.map(function(t){return""+t}))}},{}],3:[function(t,n){"use strict";function e(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}var r=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;n.exports=Object.assign||function(t){for(var n,o,u=e(t),s=1;s<arguments.length;s++){n=Object(arguments[s]);for(var f in n)r.call(n,f)&&(u[f]=n[f]);if(Object.getOwnPropertySymbols){o=Object.getOwnPropertySymbols(n);for(var a=0;a<o.length;a++)i.call(n,o[a])&&(u[o[a]]=n[o[a]])}}return u}},{}],4:[function(t,n){!function(){"use strict";function t(t){return"function"==typeof t}function e(t){return"[object Array]"===Object.prototype.toString.call(t)}function r(t){return t instanceof Date?t.getTime():t instanceof Array?t.map(r):t}function i(t){return function(n,r){if(!e(r)||!r.length)return t(n,r);for(var i=0,o=r.length;o>i;i++)if(t(n,r[i]))return!0;return!1}}function o(t){return function(n,r){if(!e(r)||!r.length)return t(n,r);for(var i=0,o=r.length;o>i;i++)if(!t(n,r[i]))return!1;return!0}}function u(t,n){return t.v(t.a,n)}function s(t,n){for(var e=0;e<t.length;e++)if(u(n,t[e]))return e;return-1}function f(t,n){return{a:t,v:n}}function a(t,n){var e=[];return c(n,t.k,0,e),1===e.length?u(t.nv,e[0]):!!~s(e,t.nv)}function c(t,n,r,i){if(r===n.length||void 0==t)return void i.push(t);if(e(t))for(var o=0,u=t.length;u>o;o++)c(t[o],n,r,i);else c(t[n[r]],n,r+1,i)}function l(t,n){return{a:{k:t,nv:n},v:a}}function h(t){t=r(t),(!t||"Object"!==t.constructor.toString()&&"functionObject(){[nativecode]}"!==t.constructor.toString().replace(/\n/g,"").replace(/ /g,""))&&(t={$eq:t});var n=[];for(var e in t){var i=t[e];if("$options"!==e)if(g[e])d[e]&&(i=d[e](i,t)),n.push(f(r(i),g[e]));else{if(36===e.charCodeAt(0))throw new Error("Unknown operation "+e);n.push(l(e.split("."),h(i)))}}return 1===n.length?n[0]:f(n,g.$and)}function p(t,n){var e=h(t);return n&&(e={a:e,v:function(t,e){return u(t,n(e))}}),e}function y(n,e,r){function i(t){return u(o,t)}t(e)&&(r=e,e=void 0);var o=p(n,r);return e?Array.isArray(e)?e.filter(i):v(e,i):i}function v(t,n){var e={};for(var r in t)if(t.hasOwnProperty(r)){var i=t[r];n(i)&&(e[r]=i)}return e}var g={$eq:i(function(t,n){return t(n)}),$ne:o(function(t,n){return!t(n)}),$or:function(t,n){for(var e=0,r=t.length;r>e;e++)if(u(t[e],n))return!0;return!1},$gt:i(function(t,n){return typeof r(n)==typeof t&&r(n)>t}),$gte:i(function(t,n){return typeof r(n)==typeof t&&r(n)>=t}),$lt:i(function(t,n){return typeof r(n)==typeof t&&r(n)<t}),$lte:i(function(t,n){return typeof r(n)==typeof t&&r(n)<=t}),$mod:i(function(t,n){return n%t[0]==t[1]}),$in:function(t,n){if(!(n instanceof Array))return!!~t.indexOf(r(n));for(var e=n.length;e--;)if(~t.indexOf(r(n[e])))return!0;return!1},$nin:function(t,n){return!g.$in(t,n)},$not:function(t,n){return!u(t,n)},$type:function(t,n){return void 0!=n?n instanceof t||n.constructor==t:!1},$all:function(t,n){n||(n=[]);for(var e=t.length;e--;)if(!~r(n).indexOf(t[e]))return!1;return!0},$size:function(t,n){return n?t===n.length:!1},$nor:function(t,n){for(var e=0,r=t.length;r>e;e++)if(u(t[e],n))return!1;return!0},$and:function(t,n){for(var e=0,r=t.length;r>e;e++)if(!u(t[e],n))return!1;return!0},$regex:i(function(t,n){return"string"==typeof n&&t.test(n)}),$where:function(t,n){return t.call(n,n)},$elemMatch:function(t,n){return e(n)?!!~s(n,t):u(t,n)},$exists:function(t,n){return void 0!=n===t}},d={$eq:function(t){return t instanceof RegExp?function(n){return"string"==typeof n&&t.test(n)}:t instanceof Function?t:e(t)&&!t.length?function(t){return e(t)&&!t.length}:null===t?function(t){return null==t}:function(n){return t===r(n)}},$ne:function(t){return d.$eq(t)},$and:function(t){return t.map(h)},$or:function(t){return t.map(h)},$nor:function(t){return t.map(h)},$not:function(t){return h(t)},$regex:function(t,n){return new RegExp(t,n.$options)},$where:function(t){return"string"==typeof t?new Function("obj","return "+t):t},$elemMatch:function(t){return h(t)},$exists:function(t){return!!t}};y.use=function(n){if(t(n))return n(y);for(var e in n)36===e.charCodeAt(0)&&(g[e]=n[e])},y.indexOf=function(t,n,e){return s(n,p(t,e))},y.keyOf=function(t,n,e){var r=p(t,e);for(var i in n)if(n.hasOwnProperty(i)&&u(r,n[i]))return i},"undefined"!=typeof n&&"undefined"!=typeof n.exports&&(n.exports=y),"undefined"!=typeof window&&(window.sift=y)}()},{}],5:[function(t,n){"use strict";function e(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}function r(t,n){return this instanceof r?(this.value=t,this.root=n&&n.root||this,this.keypath=n&&n.keypath||[],this.extensions=n&&n.extensions||[],void(this.extensions.length&&this.applyExtensions())):new r(t,n)}function i(t){return function(){return t.bind(null,this.forEach.bind(this)).apply(this,arguments)}}var o=t("sift"),u=t("object-assign"),s=t("./lib/build_extensions"),f=t("./lib/normalize_keypath");r.prototype={go:function(){var t=f(arguments,!0),n=this.get.apply(this,t);return this._get(n,t,!0)},at:function(t){if(Array.isArray(this.value))return this._get(this.value[t],[""+t]);var n=this.keys()[t];return this._get(this.value[n],[""+n])},filter:function(t){var n=o(t,this.value);return this._get(n,[])},find:function(t){var n=o.keyOf(t,this.value);if("undefined"!=typeof n)return this._get(this.value[n],[n])},first:function(){return this.at(0)},last:function(){return this.at(this.len()-1)},get:function(){for(var t=this.value,n=f(arguments,!0),e=0,r=n.length;r>e;e++)if(t=t[n[e]],!t)return;return t},len:function(){return this.value?Array.isArray(this.value)?this.value.length:this.keys().length:0},toArray:function(){if(Array.isArray(this.value))return this.value;var t=[];return r.each(this.value,function(n){return t.push(n)}),t},values:function(){return this.toArray()},keys:function(){return Object.keys(this.value)},set:function(t,n){if(t=f(t),this.root!==this)return this.root.set(this.keypath.concat(t),n).go(this.keypath);var e=r.set(this.value,t,n);return this.replace(e,{root:null})},del:function(t){if(t=f(t),this.root!==this)return this.root.del(this.keypath.concat(t)).go(this.keypath);var n=r.del(this.value,t);return this.replace(n,{root:null})},extend:function(){if("object"===e(this.value)&&!Array.isArray(this.value)){var t={};u(t,this.value);for(var n=0,r=arguments.length;r>n;n++){if("object"!==e(arguments[n]))return;u(t,arguments[n])}return this.root!==this?this.root.set(this.keypath,t).go(this.keypath):this.replace(t)}},use:function(t){var n=s(this.keypath,t);return this.root===this?this.replace(this.value,{extensions:n,root:null}):this.root.replace(this.root.value,{extensions:n,root:null}).replace(this.value,{keypath:this.keypath})},toJSON:function(){return this.value},valueOf:function(){return this.value},toString:function(){return"[scour ("+this.keys().join(", ")+")]"},forEach:function(t){var n=this;return r.each(this.value,function(e,r){t.call(e,n._get(e,[r]),r)}),this},each:function(t){return this.forEach(t)},map:i(t("./utilities/map")),_get:function(t,n){return"undefined"==typeof t||null===t?t:this.replace(t,{keypath:this.keypath.concat(n)})},replace:function(t,n){var e=n||{};return new r(t||this.value,{root:"undefined"!=typeof e.root?e.root:this.root,keypath:"undefined"!=typeof e.keypath?e.keypath:this.keypath,extensions:"undefined"!=typeof e.extensions?this.extensions.concat(e.extensions):this.extensions})},applyExtensions:function(){var t=this,n=this.keypath.join(".");this.extensions.forEach(function(e){e[0].test(n)&&u(t,e[1])})}},r.set=t("./utilities/set"),r.del=t("./utilities/del"),r.each=t("./utilities/each"),r.map=t("./utilities/map"),n.exports=r},{"./lib/build_extensions":1,"./lib/normalize_keypath":2,"./utilities/del":8,"./utilities/each":9,"./utilities/map":10,"./utilities/set":11,"object-assign":3,sift:4}],6:[function(t,n){"use strict";n.exports=function(n){var e=t("object-assign");return Array.isArray(n)?[].slice.call(n):e({},n)}},{"object-assign":3}],7:[function(t,n){"use strict";n.exports=function(t,n){if(Array.isArray(t))return t.slice(0,+n).concat(t.slice(+n+1));var e={};n=""+n;for(var r in t)t.hasOwnProperty(r)&&n!==r&&(e[r]=t[r]);return e}},{}],8:[function(t,n){"use strict";function e(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}var r=t("./clone"),i=t("./clone_without");n.exports=function(t,n){for(var o={},u={},s=0,f=n.length;f>s;s++)if(0===s)u[s]=t;else if(u[s]=u[s-1][n[s-1]],!u[s]||"object"!==e(u[s]))return t;for(var s=n.length-1;s>=0;s--)s===n.length-1?(o[s]=i(u[s],n[s]),delete o[s][n[s]]):(o[s]=r(u[s]),o[s][n[s]]=o[s+1]);return o[0]}},{"./clone":6,"./clone_without":7}],9:[function(t,n){"use strict";function e(t,n){if(t){var e,r,i=t.length;if("number"==typeof i)for(e=0;i>e;e++)n(t[e],e);else{r=0;for(e in t)t.hasOwnProperty(e)&&n(t[e],e,r++)}return t}}n.exports=e},{}],10:[function(t,n){"use strict";var e=t("./each");n.exports=function(t,n){"function"!=typeof t&&(t=e.bind(this,t));var r=[];return t(function(){r.push(n.apply(this,arguments))}),r}},{"./each":9}],11:[function(t,n){"use strict";function e(t){return t&&"undefined"!=typeof Symbol&&t.constructor===Symbol?"symbol":typeof t}var r=t("./clone");n.exports=function(t,n,i){for(var o={},u={},s=0,f=n.length;f>s;s++)0===s?u[s]=t:(u[s]=u[s-1][n[s-1]]||{},"object"!==e(u[s])&&(u[s]={}));for(var s=n.length;s>=0;s--)u[s]?(o[s]=r(u[s]),o[s][n[s]]=o[s+1]):o[s]=i;return o[0]}},{"./clone":6}]},{},[5])(5)});
\No newline at end of file