@cclr/utils 0.1.23 → 0.1.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("@cclr/lang");function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r){return t&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,c(n.key),n)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function n(e,t,r){return(t=c(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t);else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,t)||f(e,t)||function(){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 l(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||f(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function f(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}function s(){s=function(e,t){return new r(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function r(e,n,o){var i=RegExp(e,n);return t.set(i,o||t.get(e)),u(i,r.prototype)}function n(e,r){var n=t.get(r);return Object.keys(n).reduce((function(t,r){var o=n[r];if("number"==typeof o)t[r]=e[o];else{for(var i=0;void 0===e[o[i]]&&i+1<o.length;)i++;t[r]=e[o[i]]}return t}),Object.create(null))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(r,RegExp),r.prototype.exec=function(t){var r=e.exec.call(this,t);if(r){r.groups=n(r,this);var o=r.indices;o&&(o.groups=n(o,this))}return r},r.prototype[Symbol.replace]=function(r,o){if("string"==typeof o){var i=t.get(this);return e[Symbol.replace].call(this,r,o.replace(/\$<([^>]+)>/g,(function(e,t){var r=i[t];return"$"+(Array.isArray(r)?r.join("$"):r)})))}if("function"==typeof o){var u=this;return e[Symbol.replace].call(this,r,(function(){var e=arguments;return"object"!=typeof e[e.length-1]&&(e=[].slice.call(e)).push(n(e,u)),o.apply(this,e)}))}return e[Symbol.replace].call(this,r,o)},s.apply(this,arguments)}var p=function(){return r((function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),n(this,"handler",[])}),[{key:"use",value:function(e,t){return this.handler.push({fulfilled:e,rejected:t}),this.handler.length-1}},{key:"eject",value:function(e){this.handler[e]&&(this.handler[e]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.forEach(this.handler,(function(e){e&&t(e)}),r)}},{key:"run",value:function(e){var t=arguments;return new Promise(function(r,n){var o=t.length>1&&void 0!==t[1]&&t[1],i=Promise.resolve(e());return this.forEach((function(e){i=i.then(e.fulfilled,e.rejected)}),o),r(i)}.bind(this))}}])}(),h=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),y=s(/\?([^#]*)/,{query:1}),v=s(/#(.*)/,{hash:1}),d=s(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),b=function(e){var t=e.protocol,r=e.auth,n=e.host,o=e.hostname,i=e.port,u=e.pathname,a=e.query,l=e.search,c=e.hash,f=t?"".concat(t,"//"):"",s=r?"".concat(r,"@"):"",p=n||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):l||"",y=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(y)},m=function(e){if(!e)return"";var t=e.split("?")[1];return t?t.replace(v,""):""},g=function(e){if(!e)return{};var t=m(e);return t?t.split("&").reduce((function(e,t){var r=t.indexOf("="),n=(-1!==r?[t.substring(0,r),t.substring(r+1)]:[t]).map((function(e){return decodeURIComponent(e.replace("+"," "))}));return e[n[0]]=n[1],e}),{}):{}};function O(t){var r=t.match(h),n=e.get(r,"groups",{}),o=n.protocol,i=n.auth,u=n.host,l=n.pathname,c=n.query,f=n.hash,s=null,p=null;if(u){var y=a(u.split(":"),2);s=y[0],p=y[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:s||null,port:p||null,pathname:l||null,search:c?"?".concat(c):null,query:c||null,hash:f||null}}var j=function(t){var r=[];for(var n in t){var o=t[n];e.isUndefinedOrNull(o)?r.push(encodeURIComponent(n)+"="):r.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return r.join("&")},w=["queryObj"],x=function(e,t){var r=t.queryObj,n=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,w),o=i(i({},O(e)),n),u=i(i({},g(o.search||"")),r);return b(i(i({},o),{},{search:"",query:j(u)}))};function P(e){var t,r=e.match(d);if(r)return(null===(t=r.groups)||void 0===t?void 0:t.pathname)||""}var E={parseUrl:O,getPathArr:function(t){var r=P(t);if(!e.isUndefined(r))return r.split("/").filter(Boolean)},getPathStr:P,getQuery:m,getQueryObj:g,toQueryString:j,change:x,addQuery:function(e,t){return x(e,{queryObj:t})},combine:b};exports.HASH_REGEX=v,exports.Interceptor=p,exports.PATHNAME_REGEX=d,exports.QUERY_REGEX=y,exports.URL_REGEX=h,exports.debounce=function(e,t){var r,n,o,i,u,a=null==t?void 0:t.maxWait,c=null!==(r=null==t?void 0:t.wait)&&void 0!==r?r:500,f=null===(n=null==t?void 0:t.leading)||void 0===n||n,s=null===(o=null==t?void 0:t.trailing)||void 0===o||o,p=!1,h=0,y=a&&a>c,v=function(){clearTimeout(i),i=null},d=function(){p=!1,y&&(h=Date.now()),e.apply(void 0,l(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(p&&s)return d(),void b();v()}),c)},m=function(){p=!0;for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];u=t,i||(f?d():y&&(h=Date.now())),y&&Date.now()-h>=a&&(d(),b()),b()};return m.cancel=v,m.flush=function(){i&&p&&(d(),b())},m.fun=e,m},exports.deepClone=function(e){return JSON.parse(JSON.stringify(e))},exports.enumToArray=function(t){return e.isPlainObject(t)?[Object.keys(t)]:[]},exports.listToMap=function(e,t){return e.reduce((function(e,r){var o=r[t];return i(i({},e),{},n({},o,r))}),{})},exports.numInRange=function(e,t){return e<=t[1]&&e>=t[0]},exports.sleep=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(e.isNumber(t))return new Promise((function(e){return setTimeout(e,t)}))},exports.throttle=function(e,t){var r,n,o,i,u,a=null!==(r=null==t?void 0:t.wait)&&void 0!==r?r:500,c=null===(n=null==t?void 0:t.leading)||void 0===n||n,f=null===(o=null==t?void 0:t.trailing)||void 0===o||o,s=!1,p=function(){clearTimeout(i),i=null,s=!1},h=function(){s=!1,e.apply(void 0,l(u))},y=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return h(),void y();p()}),a)},v=function(){s=!0;for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];u=t,i||(c&&h(),y())};return v.cancel=p,v.flush=function(){i&&s&&(h(),y())},v.fun=e,v},exports.uri=E,exports.uuid=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],r=[],n=0;n<e;n++)r[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return r.join("")};
1
+ "use strict";var r=require("@cclr/lang");function t(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,n=Array(t);e<t;e++)n[e]=r[e];return n}function e(r,t,e){return t&&function(r,t){for(var e=0;e<t.length;e++){var n=t[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(r,c(n.key),n)}}(r.prototype,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function n(r,t,e){return(t=c(t))in r?Object.defineProperty(r,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):r[t]=e,r}function o(r,t){var e=Object.keys(r);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(r);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),e.push.apply(e,n)}return e}function i(r){for(var t=1;t<arguments.length;t++){var e=null!=arguments[t]?arguments[t]:{};t%2?o(Object(e),!0).forEach((function(t){n(r,t,e[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(e)):o(Object(e)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(e,t))}))}return r}function u(r,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},u(r,t)}function a(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=e){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(e=e.call(r)).next,0===t){if(Object(e)!==e)return;l=!1}else for(;!(l=(n=i.call(e)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(r){c=!0,o=r}finally{try{if(!l&&null!=e.return&&(u=e.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(r,t)||f(r,t)||function(){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 l(r){return function(r){if(Array.isArray(r))return t(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||f(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(r){var t=function(r,t){if("object"!=typeof r||!r)return r;var e=r[Symbol.toPrimitive];if(void 0!==e){var n=e.call(r,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}(r,"string");return"symbol"==typeof t?t:t+""}function f(r,e){if(r){if("string"==typeof r)return t(r,e);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(r,e):void 0}}function s(){s=function(r,t){return new e(r,void 0,t)};var r=RegExp.prototype,t=new WeakMap;function e(r,n,o){var i=RegExp(r,n);return t.set(i,o||t.get(r)),u(i,e.prototype)}function n(r,e){var n=t.get(e);return Object.keys(n).reduce((function(t,e){var o=n[e];if("number"==typeof o)t[e]=r[o];else{for(var i=0;void 0===r[o[i]]&&i+1<o.length;)i++;t[e]=r[o[i]]}return t}),Object.create(null))}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&u(r,t)}(e,RegExp),e.prototype.exec=function(t){var e=r.exec.call(this,t);if(e){e.groups=n(e,this);var o=e.indices;o&&(o.groups=n(o,this))}return e},e.prototype[Symbol.replace]=function(e,o){if("string"==typeof o){var i=t.get(this);return r[Symbol.replace].call(this,e,o.replace(/\$<([^>]+)>/g,(function(r,t){var e=i[t];return"$"+(Array.isArray(e)?e.join("$"):e)})))}if("function"==typeof o){var u=this;return r[Symbol.replace].call(this,e,(function(){var r=arguments;return"object"!=typeof r[r.length-1]&&(r=[].slice.call(r)).push(n(r,u)),o.apply(this,r)}))}return r[Symbol.replace].call(this,e,o)},s.apply(this,arguments)}function p(r,t,e){t/=100,e/=100;var n=(1-Math.abs(2*e-1))*t,o=n*(1-Math.abs(r/60%2-1)),i=e-n/2,u=0,a=0,l=0;return r<60?(u=n,a=o,l=0):r<120?(u=o,a=n,l=0):r<180?(u=0,a=n,l=o):r<240?(u=0,a=o,l=n):r<300?(u=o,a=0,l=n):(u=n,a=0,l=o),[Math.round(255*(u+i)),Math.round(255*(a+i)),Math.round(255*(l+i))]}function h(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return r?(t<0&&(t=0),Number(r.toFixed(t))):0}var v=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(r>t){var e=[t,r];r=e[0],t=e[1]}else if(r===t)return h(r);return Math.floor(Math.random()*(t-r+1)+r)},d=Object.freeze({__proto__:null,randomInt:v,toFixed:h});function y(r){var t=r||{},e=t.h,n=t.l,o=t.s;return[v(e?e[0]:0,e?e[1]:359),v(n?n[0]:50,n?n[1]:100),v(o?o[0]:50,o?o[1]:50)]}var b=Object.freeze({__proto__:null,hexToHsl:function(r){if(3===(r=r.replace(/^#/,"")).length&&(r=r.split("").map((function(r){return r+r})).join("")),!/^([0-9a-fA-F]{6})$/.test(r))throw new Error("Invalid hex color");var t=parseInt(r.slice(0,2),16)/255,e=parseInt(r.slice(2,4),16)/255,n=parseInt(r.slice(4,6),16)/255,o=Math.max(t,e,n),i=Math.min(t,e,n),u=0,a=0,l=(o+i)/2;if(o!==i){var c=o-i;switch(a=l>.5?c/(2-o-i):c/(o+i),o){case t:u=(e-n)/c+(e<n?6:0);break;case e:u=(n-t)/c+2;break;case n:u=(t-e)/c+4}u*=60}return[Math.round(u),Math.round(100*a),Math.round(100*l)]},hexToRgb:function(r){if(3===(r=r.replace(/^#/,"")).length&&(r=r.split("").map((function(r){return r+r})).join("")),6!==r.length)throw new Error("Invalid hex color format. Use #RRGGBB or #RGB.");return[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]},hslToRgb:p,hslToRgbString:function(r,t,e){var n=a(p(r,t,e),3),o=n[0],i=n[1],u=n[2];return"rgb(".concat(o,", ").concat(i,", ").concat(u,")")},randomHSL:y,randomHSLString:function(r){var t=a(y(r),3),e=t[0],n=t[1],o=t[2];return"hsl(".concat(e,", ").concat(n,"%, ").concat(o,"%)")},randomHex:function(){var r=Math.floor(16777215*Math.random()).toString(16).padStart(6,"0");return"#".concat(r.toUpperCase())}});var m=function(){return e((function r(){!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),n(this,"handler",[])}),[{key:"use",value:function(r,t){return this.handler.push({fulfilled:r,rejected:t}),this.handler.length-1}},{key:"eject",value:function(r){this.handler[r]&&(this.handler[r]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];r.forEach(this.handler,(function(r){r&&t(r)}),e)}},{key:"run",value:function(r){var t=arguments;return new Promise(function(e,n){var o=t.length>1&&void 0!==t[1]&&t[1],i=Promise.resolve(r());return this.forEach((function(r){i=i.then(r.fulfilled,r.rejected)}),o),e(i)}.bind(this))}}])}(),g=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),O=s(/\?([^#]*)/,{query:1}),j=s(/#(.*)/,{hash:1}),w=s(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),x=function(r){var t=r.protocol,e=r.auth,n=r.host,o=r.hostname,i=r.port,u=r.pathname,a=r.query,l=r.search,c=r.hash,f=t?"".concat(t,"//"):"",s=e?"".concat(e,"@"):"",p=n||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):l||"",v=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(v)},S=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(j,""):""},E=function(r){if(!r)return{};var t=S(r);return t?t.split("&").reduce((function(r,t){var e=t.indexOf("="),n=(-1!==e?[t.substring(0,e),t.substring(e+1)]:[t]).map((function(r){return decodeURIComponent(r.replace("+"," "))}));return r[n[0]]=n[1],r}),{}):{}};function P(t){var e=t.match(g),n=r.get(e,"groups",{}),o=n.protocol,i=n.auth,u=n.host,l=n.pathname,c=n.query,f=n.hash,s=null,p=null;if(u){var h=a(u.split(":"),2);s=h[0],p=h[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:s||null,port:p||null,pathname:l||null,search:c?"?".concat(c):null,query:c||null,hash:f||null}}var A=function(t){var e=[];for(var n in t){var o=t[n];r.isUndefinedOrNull(o)?e.push(encodeURIComponent(n)+"="):e.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return e.join("&")},I=["queryObj"],R=function(r,t){var e=t.queryObj,n=function(r,t){if(null==r)return{};var e,n,o=function(r,t){if(null==r)return{};var e={};for(var n in r)if({}.hasOwnProperty.call(r,n)){if(-1!==t.indexOf(n))continue;e[n]=r[n]}return e}(r,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);for(n=0;n<i.length;n++)e=i[n],-1===t.indexOf(e)&&{}.propertyIsEnumerable.call(r,e)&&(o[e]=r[e])}return o}(t,I),o=i(i({},P(r)),n),u=i(i({},E(o.search||"")),e);return x(i(i({},o),{},{search:"",query:A(u)}))};function M(r){var t,e=r.match(w);if(e)return(null===(t=e.groups)||void 0===t?void 0:t.pathname)||""}var T={parseUrl:P,getPathArr:function(t){var e=M(t);if(!r.isUndefined(e))return e.split("/").filter(Boolean)},getPathStr:M,getQuery:S,getQueryObj:E,toQueryString:A,change:R,addQuery:function(r,t){return R(r,{queryObj:t})},combine:x};exports.Color=b,exports.HASH_REGEX=j,exports.Interceptor=m,exports.Num=d,exports.PATHNAME_REGEX=w,exports.QUERY_REGEX=O,exports.URL_REGEX=g,exports.debounce=function(r,t){var e,n,o,i,u,a=null==t?void 0:t.maxWait,c=null!==(e=null==t?void 0:t.wait)&&void 0!==e?e:500,f=null===(n=null==t?void 0:t.leading)||void 0===n||n,s=null===(o=null==t?void 0:t.trailing)||void 0===o||o,p=!1,h=0,v=a&&a>c,d=function(){clearTimeout(i),i=null},y=function(){p=!1,v&&(h=Date.now()),r.apply(void 0,l(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(p&&s)return y(),void b();d()}),c)},m=function(){p=!0;for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];u=t,i||(f?y():v&&(h=Date.now())),v&&Date.now()-h>=a&&(y(),b()),b()};return m.cancel=d,m.flush=function(){i&&p&&(y(),b())},m.fun=r,m},exports.deepClone=function(r){return JSON.parse(JSON.stringify(r))},exports.enumToArray=function(t){return r.isPlainObject(t)?[Object.keys(t)]:[]},exports.listToMap=function(r,t){return r.reduce((function(r,e){var o=e[t];return i(i({},r),{},n({},o,e))}),{})},exports.numInRange=function(r,t){return r<=t[1]&&r>=t[0]},exports.randomInt=v,exports.sleep=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(r.isNumber(t))return new Promise((function(r){return setTimeout(r,t)}))},exports.throttle=function(r,t){var e,n,o,i,u,a=null!==(e=null==t?void 0:t.wait)&&void 0!==e?e:500,c=null===(n=null==t?void 0:t.leading)||void 0===n||n,f=null===(o=null==t?void 0:t.trailing)||void 0===o||o,s=!1,p=function(){clearTimeout(i),i=null,s=!1},h=function(){s=!1,r.apply(void 0,l(u))},v=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return h(),void v();p()}),a)},d=function(){s=!0;for(var r=arguments.length,t=new Array(r),e=0;e<r;e++)t[e]=arguments[e];u=t,i||(c&&h(),v())};return d.cancel=p,d.flush=function(){i&&s&&(h(),v())},d.fun=r,d},exports.toFixed=h,exports.uri=T,exports.uuid=function(){for(var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],e=[],n=0;n<r;n++)e[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return e.join("")};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{isPlainObject as t,forEach as n,isNumber as r,get as e,isUndefinedOrNull as o,isUndefined as i}from"@cclr/lang";var u=function(t){return JSON.parse(JSON.stringify(t))},a=function(n){return t(n)?[Object.keys(n)]:[]};function l(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=Array(n);r<n;r++)e[r]=t[r];return e}function c(t,n,r){return n&&function(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,d(e.key),e)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,n,r){return(n=d(n))in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function s(t,n){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);n&&(e=e.filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),r.push.apply(r,e)}return r}function p(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?s(Object(r),!0).forEach((function(n){f(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(r,n))}))}return t}function h(t,n){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},h(t,n)}function y(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var e,o,i,u,a=[],l=!0,c=!1;try{if(i=(r=r.call(t)).next,0===n);else for(;!(l=(e=i.call(r)).done)&&(a.push(e.value),a.length!==n);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(t,n)||b(t,n)||function(){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 v(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||b(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){var n=function(t,n){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.call(t,n);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:n+""}function b(t,n){if(t){if("string"==typeof t)return l(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,n):void 0}}function m(){m=function(t,n){return new r(t,void 0,n)};var t=RegExp.prototype,n=new WeakMap;function r(t,e,o){var i=RegExp(t,e);return n.set(i,o||n.get(t)),h(i,r.prototype)}function e(t,r){var e=n.get(r);return Object.keys(e).reduce((function(n,r){var o=e[r];if("number"==typeof o)n[r]=t[o];else{for(var i=0;void 0===t[o[i]]&&i+1<o.length;)i++;n[r]=t[o[i]]}return n}),Object.create(null))}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),n&&h(t,n)}(r,RegExp),r.prototype.exec=function(n){var r=t.exec.call(this,n);if(r){r.groups=e(r,this);var o=r.indices;o&&(o.groups=e(o,this))}return r},r.prototype[Symbol.replace]=function(r,o){if("string"==typeof o){var i=n.get(this);return t[Symbol.replace].call(this,r,o.replace(/\$<([^>]+)>/g,(function(t,n){var r=i[n];return"$"+(Array.isArray(r)?r.join("$"):r)})))}if("function"==typeof o){var u=this;return t[Symbol.replace].call(this,r,(function(){var t=arguments;return"object"!=typeof t[t.length-1]&&(t=[].slice.call(t)).push(e(t,u)),o.apply(this,t)}))}return t[Symbol.replace].call(this,r,o)},m.apply(this,arguments)}var g=function(t,n){return t.reduce((function(t,r){var e=r[n];return p(p({},t),{},f({},e,r))}),{})};function O(t,n){return t<=n[1]&&t>=n[0]}var j=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,n=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],r=[],e=0;e<t;e++)r[e]=8===e||13===e||18===e||23===e?"-":n[Math.ceil(Math.random()*n.length-1)];return r.join("")},w=function(){return c((function t(){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),f(this,"handler",[])}),[{key:"use",value:function(t,n){return this.handler.push({fulfilled:t,rejected:n}),this.handler.length-1}},{key:"eject",value:function(t){this.handler[t]&&(this.handler[t]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];n(this.handler,(function(n){n&&t(n)}),r)}},{key:"run",value:function(t){var n=arguments;return new Promise(function(r,e){var o=n.length>1&&void 0!==n[1]&&n[1],i=Promise.resolve(t());return this.forEach((function(t){i=i.then(t.fulfilled,t.rejected)}),o),r(i)}.bind(this))}}])}(),P=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),S=m(/\?([^#]*)/,{query:1}),A=m(/#(.*)/,{hash:1}),E=m(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),x=function(t,n){var r,e,o,i,u,a=null==n?void 0:n.maxWait,l=null!==(r=null==n?void 0:n.wait)&&void 0!==r?r:500,c=null===(e=null==n?void 0:n.leading)||void 0===e||e,f=null===(o=null==n?void 0:n.trailing)||void 0===o||o,s=!1,p=0,h=a&&a>l,y=function(){clearTimeout(i),i=null},d=function(){s=!1,h&&(p=Date.now()),t.apply(void 0,v(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return d(),void b();y()}),l)},m=function(){s=!0;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];u=n,i||(c?d():h&&(p=Date.now())),h&&Date.now()-p>=a&&(d(),b()),b()};return m.cancel=y,m.flush=function(){i&&s&&(d(),b())},m.fun=t,m},T=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(r(t))return new Promise((function(n){return setTimeout(n,t)}))},k=function(t,n){var r,e,o,i,u,a=null!==(r=null==n?void 0:n.wait)&&void 0!==r?r:500,l=null===(e=null==n?void 0:n.leading)||void 0===e||e,c=null===(o=null==n?void 0:n.trailing)||void 0===o||o,f=!1,s=function(){clearTimeout(i),i=null,f=!1},p=function(){f=!1,t.apply(void 0,v(u))},h=function(){clearTimeout(i),i=setTimeout((function(){if(f&&c)return p(),void h();s()}),a)},y=function(){f=!0;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];u=n,i||(l&&p(),h())};return y.cancel=s,y.flush=function(){i&&f&&(p(),h())},y.fun=t,y},I=function(t){var n=t.protocol,r=t.auth,e=t.host,o=t.hostname,i=t.port,u=t.pathname,a=t.query,l=t.search,c=t.hash,f=n?"".concat(n,"//"):"",s=r?"".concat(r,"@"):"",p=e||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):l||"",y=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(y)},q=function(t){if(!t)return"";var n=t.split("?")[1];return n?n.replace(A,""):""},R=function(t){if(!t)return{};var n=q(t);return n?n.split("&").reduce((function(t,n){var r=n.indexOf("="),e=(-1!==r?[n.substring(0,r),n.substring(r+1)]:[n]).map((function(t){return decodeURIComponent(t.replace("+"," "))}));return t[e[0]]=e[1],t}),{}):{}};function D(t){var n=t.match(P),r=e(n,"groups",{}),o=r.protocol,i=r.auth,u=r.host,a=r.pathname,l=r.query,c=r.hash,f=null,s=null;if(u){var p=y(u.split(":"),2);f=p[0],s=p[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:f||null,port:s||null,pathname:a||null,search:l?"?".concat(l):null,query:l||null,hash:c||null}}var C=function(t){var n=[];for(var r in t){var e=t[r];o(e)?n.push(encodeURIComponent(r)+"="):n.push(encodeURIComponent(r)+"="+encodeURIComponent(e))}return n.join("&")},U=["queryObj"],z=function(t,n){var r=n.queryObj,e=function(t,n){if(null==t)return{};var r,e,o=function(t,n){if(null==t)return{};var r={};for(var e in t)if({}.hasOwnProperty.call(t,e)){if(-1!==n.indexOf(e))continue;r[e]=t[e]}return r}(t,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(e=0;e<i.length;e++)r=i[e],-1===n.indexOf(r)&&{}.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}(n,U),o=p(p({},D(t)),e),i=p(p({},R(o.search||"")),r);return I(p(p({},o),{},{search:"",query:C(i)}))};function M(t){var n,r=t.match(E);if(r)return(null===(n=r.groups)||void 0===n?void 0:n.pathname)||""}var Q={parseUrl:D,getPathArr:function(t){var n=M(t);if(!i(n))return n.split("/").filter(Boolean)},getPathStr:M,getQuery:q,getQueryObj:R,toQueryString:C,change:z,addQuery:function(t,n){return z(t,{queryObj:n})},combine:I};export{A as HASH_REGEX,w as Interceptor,E as PATHNAME_REGEX,S as QUERY_REGEX,P as URL_REGEX,x as debounce,u as deepClone,a as enumToArray,g as listToMap,O as numInRange,T as sleep,k as throttle,Q as uri,j as uuid};
1
+ import{isPlainObject as r,forEach as t,isNumber as n,get as e,isUndefinedOrNull as o,isUndefined as i}from"@cclr/lang";function a(r,t){(null==t||t>r.length)&&(t=r.length);for(var n=0,e=Array(t);n<t;n++)e[n]=r[n];return e}function u(r,t,n){return t&&function(r,t){for(var n=0;n<t.length;n++){var e=t[n];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(r,v(e.key),e)}}(r.prototype,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function l(r,t,n){return(t=v(t))in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function c(r,t){var n=Object.keys(r);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(r);t&&(e=e.filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),n.push.apply(n,e)}return n}function f(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){l(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))}))}return r}function s(r,t){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},s(r,t)}function p(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var n=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=n){var e,o,i,a,u=[],l=!0,c=!1;try{if(i=(n=n.call(r)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(e=i.call(n)).done)&&(u.push(e.value),u.length!==t);l=!0);}catch(r){c=!0,o=r}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return u}}(r,t)||y(r,t)||function(){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 h(r){return function(r){if(Array.isArray(r))return a(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||y(r)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(r){var t=function(r,t){if("object"!=typeof r||!r)return r;var n=r[Symbol.toPrimitive];if(void 0!==n){var e=n.call(r,t);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}(r,"string");return"symbol"==typeof t?t:t+""}function y(r,t){if(r){if("string"==typeof r)return a(r,t);var n={}.toString.call(r).slice(8,-1);return"Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n?Array.from(r):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?a(r,t):void 0}}function d(){d=function(r,t){return new n(r,void 0,t)};var r=RegExp.prototype,t=new WeakMap;function n(r,e,o){var i=RegExp(r,e);return t.set(i,o||t.get(r)),s(i,n.prototype)}function e(r,n){var e=t.get(n);return Object.keys(e).reduce((function(t,n){var o=e[n];if("number"==typeof o)t[n]=r[o];else{for(var i=0;void 0===r[o[i]]&&i+1<o.length;)i++;t[n]=r[o[i]]}return t}),Object.create(null))}return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");r.prototype=Object.create(t&&t.prototype,{constructor:{value:r,writable:!0,configurable:!0}}),Object.defineProperty(r,"prototype",{writable:!1}),t&&s(r,t)}(n,RegExp),n.prototype.exec=function(t){var n=r.exec.call(this,t);if(n){n.groups=e(n,this);var o=n.indices;o&&(o.groups=e(o,this))}return n},n.prototype[Symbol.replace]=function(n,o){if("string"==typeof o){var i=t.get(this);return r[Symbol.replace].call(this,n,o.replace(/\$<([^>]+)>/g,(function(r,t){var n=i[t];return"$"+(Array.isArray(n)?n.join("$"):n)})))}if("function"==typeof o){var a=this;return r[Symbol.replace].call(this,n,(function(){var r=arguments;return"object"!=typeof r[r.length-1]&&(r=[].slice.call(r)).push(e(r,a)),o.apply(this,r)}))}return r[Symbol.replace].call(this,n,o)},d.apply(this,arguments)}function b(r,t,n){t/=100,n/=100;var e=(1-Math.abs(2*n-1))*t,o=e*(1-Math.abs(r/60%2-1)),i=n-e/2,a=0,u=0,l=0;return r<60?(a=e,u=o,l=0):r<120?(a=o,u=e,l=0):r<180?(a=0,u=e,l=o):r<240?(a=0,u=o,l=e):r<300?(a=o,u=0,l=e):(a=e,u=0,l=o),[Math.round(255*(a+i)),Math.round(255*(u+i)),Math.round(255*(l+i))]}function m(r){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return r?(t<0&&(t=0),Number(r.toFixed(t))):0}var g=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(r>t){var n=[t,r];r=n[0],t=n[1]}else if(r===t)return m(r);return Math.floor(Math.random()*(t-r+1)+r)},O=Object.freeze({__proto__:null,randomInt:g,toFixed:m});function j(r){var t=r||{},n=t.h,e=t.l,o=t.s;return[g(n?n[0]:0,n?n[1]:359),g(e?e[0]:50,e?e[1]:100),g(o?o[0]:50,o?o[1]:50)]}var w=Object.freeze({__proto__:null,hexToHsl:function(r){if(3===(r=r.replace(/^#/,"")).length&&(r=r.split("").map((function(r){return r+r})).join("")),!/^([0-9a-fA-F]{6})$/.test(r))throw new Error("Invalid hex color");var t=parseInt(r.slice(0,2),16)/255,n=parseInt(r.slice(2,4),16)/255,e=parseInt(r.slice(4,6),16)/255,o=Math.max(t,n,e),i=Math.min(t,n,e),a=0,u=0,l=(o+i)/2;if(o!==i){var c=o-i;switch(u=l>.5?c/(2-o-i):c/(o+i),o){case t:a=(n-e)/c+(n<e?6:0);break;case n:a=(e-t)/c+2;break;case e:a=(t-n)/c+4}a*=60}return[Math.round(a),Math.round(100*u),Math.round(100*l)]},hexToRgb:function(r){if(3===(r=r.replace(/^#/,"")).length&&(r=r.split("").map((function(r){return r+r})).join("")),6!==r.length)throw new Error("Invalid hex color format. Use #RRGGBB or #RGB.");return[parseInt(r.slice(0,2),16),parseInt(r.slice(2,4),16),parseInt(r.slice(4,6),16)]},hslToRgb:b,hslToRgbString:function(r,t,n){var e=p(b(r,t,n),3),o=e[0],i=e[1],a=e[2];return"rgb(".concat(o,", ").concat(i,", ").concat(a,")")},randomHSL:j,randomHSLString:function(r){var t=p(j(r),3),n=t[0],e=t[1],o=t[2];return"hsl(".concat(n,", ").concat(e,"%, ").concat(o,"%)")},randomHex:function(){var r=Math.floor(16777215*Math.random()).toString(16).padStart(6,"0");return"#".concat(r.toUpperCase())}}),S=function(r){return JSON.parse(JSON.stringify(r))},P=function(t){return r(t)?[Object.keys(t)]:[]},x=function(r,t){return r.reduce((function(r,n){var e=n[t];return f(f({},r),{},l({},e,n))}),{})};function A(r,t){return r<=t[1]&&r>=t[0]}var I=function(){for(var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],n=[],e=0;e<r;e++)n[e]=8===e||13===e||18===e||23===e?"-":t[Math.ceil(Math.random()*t.length-1)];return n.join("")},M=function(){return u((function r(){!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),l(this,"handler",[])}),[{key:"use",value:function(r,t){return this.handler.push({fulfilled:r,rejected:t}),this.handler.length-1}},{key:"eject",value:function(r){this.handler[r]&&(this.handler[r]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(r){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];t(this.handler,(function(t){t&&r(t)}),n)}},{key:"run",value:function(r){var t=arguments;return new Promise(function(n,e){var o=t.length>1&&void 0!==t[1]&&t[1],i=Promise.resolve(r());return this.forEach((function(r){i=i.then(r.fulfilled,r.rejected)}),o),n(i)}.bind(this))}}])}(),E=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),T=d(/\?([^#]*)/,{query:1}),R=d(/#(.*)/,{hash:1}),k=d(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),_=function(r,t){var n,e,o,i,a,u=null==t?void 0:t.maxWait,l=null!==(n=null==t?void 0:t.wait)&&void 0!==n?n:500,c=null===(e=null==t?void 0:t.leading)||void 0===e||e,f=null===(o=null==t?void 0:t.trailing)||void 0===o||o,s=!1,p=0,v=u&&u>l,y=function(){clearTimeout(i),i=null},d=function(){s=!1,v&&(p=Date.now()),r.apply(void 0,h(a))},b=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return d(),void b();y()}),l)},m=function(){s=!0;for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];a=t,i||(c?d():v&&(p=Date.now())),v&&Date.now()-p>=u&&(d(),b()),b()};return m.cancel=y,m.flush=function(){i&&s&&(d(),b())},m.fun=r,m},q=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(n(r))return new Promise((function(t){return setTimeout(t,r)}))},C=function(r,t){var n,e,o,i,a,u=null!==(n=null==t?void 0:t.wait)&&void 0!==n?n:500,l=null===(e=null==t?void 0:t.leading)||void 0===e||e,c=null===(o=null==t?void 0:t.trailing)||void 0===o||o,f=!1,s=function(){clearTimeout(i),i=null,f=!1},p=function(){f=!1,r.apply(void 0,h(a))},v=function(){clearTimeout(i),i=setTimeout((function(){if(f&&c)return p(),void v();s()}),u)},y=function(){f=!0;for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];a=t,i||(l&&p(),v())};return y.cancel=s,y.flush=function(){i&&f&&(p(),v())},y.fun=r,y},U=function(r){var t=r.protocol,n=r.auth,e=r.host,o=r.hostname,i=r.port,a=r.pathname,u=r.query,l=r.search,c=r.hash,f=t?"".concat(t,"//"):"",s=n?"".concat(n,"@"):"",p=e||"".concat(o||"").concat(i?":".concat(i):""),h=u?"?".concat(u):l||"",v=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(a).concat(h).concat(v)},D=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(R,""):""},z=function(r){if(!r)return{};var t=D(r);return t?t.split("&").reduce((function(r,t){var n=t.indexOf("="),e=(-1!==n?[t.substring(0,n),t.substring(n+1)]:[t]).map((function(r){return decodeURIComponent(r.replace("+"," "))}));return r[e[0]]=e[1],r}),{}):{}};function N(r){var t=r.match(E),n=e(t,"groups",{}),o=n.protocol,i=n.auth,a=n.host,u=n.pathname,l=n.query,c=n.hash,f=null,s=null;if(a){var h=p(a.split(":"),2);f=h[0],s=h[1]||null}return{href:r,protocol:o||null,slashes:r.includes("//")||null,auth:i?i.slice(0,-1):null,host:a||null,hostname:f||null,port:s||null,pathname:u||null,search:l?"?".concat(l):null,query:l||null,hash:c||null}}var $=function(r){var t=[];for(var n in r){var e=r[n];o(e)?t.push(encodeURIComponent(n)+"="):t.push(encodeURIComponent(n)+"="+encodeURIComponent(e))}return t.join("&")},B=["queryObj"],H=function(r,t){var n=t.queryObj,e=function(r,t){if(null==r)return{};var n,e,o=function(r,t){if(null==r)return{};var n={};for(var e in r)if({}.hasOwnProperty.call(r,e)){if(-1!==t.indexOf(e))continue;n[e]=r[e]}return n}(r,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(r);for(e=0;e<i.length;e++)n=i[e],-1===t.indexOf(n)&&{}.propertyIsEnumerable.call(r,n)&&(o[n]=r[n])}return o}(t,B),o=f(f({},N(r)),e),i=f(f({},z(o.search||"")),n);return U(f(f({},o),{},{search:"",query:$(i)}))};function Q(r){var t,n=r.match(k);if(n)return(null===(t=n.groups)||void 0===t?void 0:t.pathname)||""}var Z={parseUrl:N,getPathArr:function(r){var t=Q(r);if(!i(t))return t.split("/").filter(Boolean)},getPathStr:Q,getQuery:D,getQueryObj:z,toQueryString:$,change:H,addQuery:function(r,t){return H(r,{queryObj:t})},combine:U};export{w as Color,R as HASH_REGEX,M as Interceptor,O as Num,k as PATHNAME_REGEX,T as QUERY_REGEX,E as URL_REGEX,_ as debounce,S as deepClone,P as enumToArray,x as listToMap,A as numInRange,g as randomInt,q as sleep,C as throttle,m as toFixed,Z as uri,I as uuid};
@@ -1,6 +1,86 @@
1
1
  import * as _cclr_lang from '@cclr/lang';
2
2
  import { TAny, TPlainObject, TPlainFunction } from '@cclr/lang';
3
3
 
4
+ /**
5
+ * hex 转 HSL
6
+ * @param hex 十六进制颜色字符串,格式为 #RRGGBB 或 #RGB
7
+ * @returns [h, s, l],色相 0-360,饱和度 0-100,亮度 0-100
8
+ * @throws {Error} 如果 hex 格式不正确
9
+ */
10
+ declare function hexToHsl(hex: string): [number, number, number];
11
+
12
+ /**
13
+ * hex 转 RGB
14
+ * @param hex 十六进制颜色字符串,格式为 #RRGGBB 或 #RGB
15
+ * @returns [r, g, b],每个分量 0-255
16
+ * @throws {Error} 如果 hex 格式不正确
17
+ */
18
+ declare function hexToRgb(hex: string): [number, number, number];
19
+
20
+ /**
21
+ * HSL 转 RGB
22
+ * @param h 色相 0-360
23
+ * @param s 饱和度 0-100
24
+ * @param l 亮度 0-100
25
+ * @returns [r, g, b],每个分量 0-255
26
+ */
27
+ declare function hslToRgb(h: number, s: number, l: number): [number, number, number];
28
+ declare const hslToRgbString: (h: number, s: number, l: number) => string;
29
+
30
+ /**
31
+ * 随机生成一个十六进制颜色字符串
32
+ * @returns {string} 例如 "#A1B2C3"
33
+ */
34
+ declare function randomHex(): string;
35
+
36
+ interface IRandomRange {
37
+ h?: [number, number];
38
+ s?: [number, number];
39
+ l?: [number, number];
40
+ }
41
+ /**
42
+ * 随机生成一个 HSL
43
+ * @returns {number[]} 返回一个包含色相、饱和度和亮度的数组
44
+ */
45
+ declare function randomHSL(params?: IRandomRange): [number, number, number];
46
+ /**
47
+ * 随机生成一个 HSL 字符串
48
+ * @returns {string} 例如 "hsl(120, 100%, 50%)"
49
+ */
50
+ declare function randomHSLString(params?: IRandomRange): string;
51
+
52
+ declare const index$1_hexToHsl: typeof hexToHsl;
53
+ declare const index$1_hexToRgb: typeof hexToRgb;
54
+ declare const index$1_hslToRgb: typeof hslToRgb;
55
+ declare const index$1_hslToRgbString: typeof hslToRgbString;
56
+ declare const index$1_randomHSL: typeof randomHSL;
57
+ declare const index$1_randomHSLString: typeof randomHSLString;
58
+ declare const index$1_randomHex: typeof randomHex;
59
+ declare namespace index$1 {
60
+ export { index$1_hexToHsl as hexToHsl, index$1_hexToRgb as hexToRgb, index$1_hslToRgb as hslToRgb, index$1_hslToRgbString as hslToRgbString, index$1_randomHSL as randomHSL, index$1_randomHSLString as randomHSLString, index$1_randomHex as randomHex };
61
+ }
62
+
63
+ /**
64
+ * Generates a random integer between the specified start and end values.
65
+ * @param start
66
+ * @param end
67
+ * @returns
68
+ */
69
+ declare const randomInt: (start?: number, end?: number) => number;
70
+
71
+ /**
72
+ * 浮点数保留指定位数
73
+ * @param num - 需要处理的数字
74
+ * @param fix - 保留的小数位数
75
+ */
76
+ declare function toFixed(num: number, fix?: number): number;
77
+
78
+ declare const index_randomInt: typeof randomInt;
79
+ declare const index_toFixed: typeof toFixed;
80
+ declare namespace index {
81
+ export { index_randomInt as randomInt, index_toFixed as toFixed };
82
+ }
83
+
4
84
  /**
5
85
  * 深拷贝 JSON 方式
6
86
  * @param Obj
@@ -172,4 +252,4 @@ declare const uri: {
172
252
  combine: (urlParams: IUrl) => string;
173
253
  };
174
254
 
175
- export { HASH_REGEX, type IUrl, Interceptor, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, debounce, deepClone, enumToArray, listToMap, numInRange, sleep, throttle, uri, uuid };
255
+ export { index$1 as Color, HASH_REGEX, type IUrl, Interceptor, index as Num, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, debounce, deepClone, enumToArray, listToMap, numInRange, randomInt, sleep, throttle, toFixed, uri, uuid };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cclr/utils",
3
- "version": "0.1.23",
3
+ "version": "0.1.25",
4
4
  "description": "> TODO: description",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -30,8 +30,8 @@
30
30
  "g:test": "vitest run",
31
31
  "g:build": "ccf build"
32
32
  },
33
- "gitHead": "56865ee648e597654303fb82c018c63a30c5baf8",
33
+ "gitHead": "fd46a3260e1a4cbdc70bc7fc456c15649425aa03",
34
34
  "dependencies": {
35
- "@cclr/lang": "0.1.23"
35
+ "@cclr/lang": "0.1.25"
36
36
  }
37
37
  }