-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcomposable.min.js
2 lines (2 loc) · 5.24 KB
/
composable.min.js
1
2
(function(){var n=typeof self==="object"&&self.self===self&&self;var r=function(n){return typeof n==="string"},t=function(n){return typeof n==="number"},e=function(n){return typeof n==="function"},i=function(n){return Array.isArray?Array.isArray(n):Object.prototype.toString.call(n)==="[object Array]"},o=function(n){return Object.prototype.toString.call(n)==="[object NodeList]"},u=function(n){return/^\/(?:\S|\s)*\/[gimy]{0,4}$/.test(n)},a=function(n){var r=n.split("/");var t=r[r.length-1];var e=n.slice(1,(t.length+1)*-1);return new RegExp(e,t)},f=function(n,r){var t,e={};for(t in n){if(n.hasOwnProperty(t)){e[t]=r(t,n[t])}}return e},l=function(n,r){var t,e={};for(t in n){if(n.hasOwnProperty(t)&&r(t,n[t])){e[t]=n[t]}}return e},c=function(n){return function(r){var t=this;if(!t.hasOwnProperty("cache")){t.cache={}}if(!t.cache.hasOwnProperty(n)){t.cache[n]={}}return function(e){if(!e){return null}if(!t.cache[n].hasOwnProperty(e)){t.cache[n][e]={}}if(!t.cache[n][e].hasOwnProperty(r)){t.cache[n][e][r]=e[n](r)}return t.cache[n][e][r]}}};var s={window:function(){return n},document:function(){return n.document},querySelectorAll:function(n){return function(r){return r?r.querySelectorAll(n):null}},querySelector:function(n){return function(r){return r?r.querySelector(n):null}},innerHTML:function(n){return n?n.innerHTML:null},innerText:function(n){return n?n.innerText||n.textContent:null},rootInnerText:function(n){if(!n)return null;var r=[];for(var t=0;t<n.childNodes.length;t++){if(n.childNodes[t].nodeType===n.TEXT_NODE){r.push(h.T.trim(h.T.innerText(n.childNodes[t])))}}return h.T.trim(r.join(" "))},value:function(n){return n?n.value:null},getAttribute:function(n){return function(r){return r&&r.getAttribute?r.getAttribute(n):null}},toInt:function(n){return r(n)||t(n)?parseInt(n,10):null},toFloat:function(n){return r(n)||t(n)?parseFloat(n):null},round:function(n){return t(n)?Math.round(n):null},multiplyBy:function(n){return function(r){return t(r)?n*r:null}},htmlToText:function(r){var t=n.document.createElement("div");t.innerHTML=r;var e=t.firstChild;return e?e.nodeValue+String():""},reverse:function(n){if(r(n)){return n.split("").reverse().join("")}else if(i(n)){return n.reverse()}return null},toString:function(n){return n?n+String():null},trim:function(n){return r(n)?n.trim():null},split:function(n,t){var e=[n];if(typeof t!=="undefined"){e.push(parseInt(t,10))}return function(n){return r(n)?n.split.apply(n,e):null}},join:function(n){return function(r){return i(r)?r.join(n):null}},replace:function(n,t){n=r(n)&&u(n)?a(n):n;return function(e){return r(e)?e.replace(n,t):null}},match:function(n){n=r(n)&&u(n)?a(n):n;return function(t){return r(t)?t.match(n):null}},getIndex:function(n){n=parseInt(n,10);return function(r){return i(r)&&r.length>n?r[n]:null}},slice:function(n,t){var e=[parseInt(n,10)];if(typeof t!=="undefined"){e.push(parseInt(t,10))}return function(n){var t;if(r(n)){t=n?String.prototype.slice.apply(n,e):null}else if(i(n)||o(n)){t=n?Array.prototype.slice.apply(n,e):null}return t}},getProperty:function(n){return function(r){return r?r[n]:null}},getProperties:function(n){return function(r){if(!r){return null}var t=n.split("."),e;while(t.length){e=t.shift();r=r?r[e]:null}return r}}};var p={map:function(n){return function(r){return i(r)||o(r)?Array.prototype.map.call(r,n):null}}};var h=function(n){if(!(this instanceof h)){return new h(n)}return this.extract(n)};h.__objectMerge=function(){var n={};for(var r=0;r<arguments.length;r++){if(typeof arguments[r]==="object"){for(var t in arguments[r]){if(arguments[r].hasOwnProperty(t)){n[t]=arguments[r][t]}}}}return n};h.prototype.T=h.T=h.__objectMerge(s,p);h.prototype.extract=function(n){var r=this;var t=l(n,function(n,r){return i(r)});return f(t,function(n,t){var e,i=null;for(e=0;e<t.length;e+=1){i=r.applyTransformation(i,t[e])}return i})};h.prototype.applyTransformation=function(n,r){var t=this.getTransformation(r);if(!t){throw'Transformation "'+r+'" invalid'}return t(n)};h.prototype.getTransformation=function(n){if(e(n)){return n}else if(!i(n)&&!r(n)){throw"Invalid Input Type: "+typeof n}if(!n||!n.length){return null}var t;if(i(n)){if(n.length===1&&this.T.hasOwnProperty(n[0])){return this.T[n[0]]}t=this.getTransformationForArrayTransformation(n)}else{if(this.T.hasOwnProperty(n)){return this.T[n]}t=this.getTransformationForStringTransformation(n)}if(!t){return null}return this.T[t.command].apply(this,t.args)};h.prototype.getTransformationForArrayTransformation=function(n){var r=n[0];if(!this.T.hasOwnProperty(r)){return null}var t=n.slice(1);if(p.hasOwnProperty(r)){var e=this.getTransformation(t);if(e){t=[e]}}return{command:r,args:t}};h.prototype.getTransformationForStringTransformation=function(n){var r=n.split(":");var t=r.shift();if(!this.T.hasOwnProperty(t)){return null}var e=r.join(":");var i;if(p.hasOwnProperty(t)){i=this.getTransformation(e)}var o=i?[i]:h.extractArgs(e);return{command:t,args:o}};h.extractArgs=function(n){n=n||"";var r=n.match(/^(\/.*?(?:(?:\\\\)+|[^\\])\/[gimy]{0,4})(?:,|$)/i);var t=[];if(r&&r.length){var e=n.slice(0,r[1].length);t.push(e);var i=r[0].length;n=n.slice(i);t=t.concat(n.split(","))}else if(n.length){t=t.concat(n.split(","))}return t};h.VERSION="0.4.5";n.Composable=h;if(typeof define==="function"&&define.amd){define("composable",[],function(){return h})}})();
//# sourceMappingURL=composable.min.map