@cclr/utils 0.1.25 → 0.1.27
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 +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/type/index.d.ts +16 -2
- package/package.json +3 -3
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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("")};
|
|
1
|
+
"use strict";var r=require("@cclr/lang");function t(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 n(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,l(e.key),e)}}(r.prototype,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function e(r,t,n){return(t=l(t))in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function o(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 i(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?o(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):o(Object(n)).forEach((function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,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 n=null==r?null:"undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(null!=n){var e,o,i,u,a=[],c=!0,l=!1;try{if(i=(n=n.call(r)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(e=i.call(n)).done)&&(a.push(e.value),a.length!==t);c=!0);}catch(r){l=!0,o=r}finally{try{if(!c&&null!=n.return&&(u=n.return(),Object(u)!==u))return}finally{if(l)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 c(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 l(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 f(r,n){if(r){if("string"==typeof r)return t(r,n);var e={}.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?t(r,n):void 0}}function s(){s=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)),u(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&&u(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 u=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,u)),o.apply(this,r)}))}return r[Symbol.replace].call(this,n,o)},s.apply(this,arguments)}function p(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,u=0,a=0,c=0;return r<60?(u=e,a=o,c=0):r<120?(u=o,a=e,c=0):r<180?(u=0,a=e,c=o):r<240?(u=0,a=o,c=e):r<300?(u=o,a=0,c=e):(u=e,a=0,c=o),[Math.round(255*(u+i)),Math.round(255*(a+i)),Math.round(255*(c+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 n=[t,r];r=n[0],t=n[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||{},n=t.h,e=t.l,o=t.s;return[v(n?n[0]:0,n?n[1]:359),v(e?e[0]:50,e?e[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,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),u=0,a=0,c=(o+i)/2;if(o!==i){var l=o-i;switch(a=c>.5?l/(2-o-i):l/(o+i),o){case t:u=(n-e)/l+(n<e?6:0);break;case n:u=(e-t)/l+2;break;case e:u=(t-n)/l+4}u*=60}return[Math.round(u),Math.round(100*a),Math.round(100*c)]},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,n){var e=a(p(r,t,n),3),o=e[0],i=e[1],u=e[2];return"rgb(".concat(o,", ").concat(i,", ").concat(u,")")},randomHSL:y,randomHSLString:function(r){var t=a(y(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())}});var m=function(){return n((function r(){!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),e(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 n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];r.forEach(this.handler,(function(r){r&&t(r)}),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))}}])}();function g(){for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];return 0===t.length?function(r){return r}:1===t.length?t[0]:t.reduce((function(r,t){return function(){return r(t.apply(void 0,arguments))}}))}var O=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),j=s(/\?([^#]*)/,{query:1}),w=s(/#(.*)/,{hash:1}),x=s(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),S=function(r){var t=r.protocol,n=r.auth,e=r.host,o=r.hostname,i=r.port,u=r.pathname,a=r.query,c=r.search,l=r.hash,f=t?"".concat(t,"//"):"",s=n?"".concat(n,"@"):"",p=e||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):c||"",v=l?"#".concat(l):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(v)},E=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(w,""):""},P=function(r){if(!r)return{};var t=E(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 A(t){var n=t.match(O),e=r.get(n,"groups",{}),o=e.protocol,i=e.auth,u=e.host,c=e.pathname,l=e.query,f=e.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:c||null,search:l?"?".concat(l):null,query:l||null,hash:f||null}}var I=function(t){var n=[];for(var e in t){var o=t[e];r.isUndefinedOrNull(o)?n.push(encodeURIComponent(e)+"="):n.push(encodeURIComponent(e)+"="+encodeURIComponent(o))}return n.join("&")},R=["queryObj"],M=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,R),o=i(i({},A(r)),e),u=i(i({},P(o.search||"")),n);return S(i(i({},o),{},{search:"",query:I(u)}))};function T(r){var t,n=r.match(x);if(n)return(null===(t=n.groups)||void 0===t?void 0:t.pathname)||""}var _={parseUrl:A,getPathArr:function(t){var n=T(t);if(!r.isUndefined(n))return n.split("/").filter(Boolean)},getPathStr:T,getQuery:E,getQueryObj:P,toQueryString:I,change:M,addQuery:function(r,t){return M(r,{queryObj:t})},combine:S};exports.Color=b,exports.HASH_REGEX=w,exports.Interceptor=m,exports.Num=d,exports.PATHNAME_REGEX=x,exports.QUERY_REGEX=j,exports.URL_REGEX=O,exports.compose=g,exports.debounce=function(r,t){var n,e,o,i,u,a=null==t?void 0:t.maxWait,l=null!==(n=null==t?void 0:t.wait)&&void 0!==n?n:500,f=null===(e=null==t?void 0:t.leading)||void 0===e||e,s=null===(o=null==t?void 0:t.trailing)||void 0===o||o,p=!1,h=0,v=a&&a>l,d=function(){clearTimeout(i),i=null},y=function(){p=!1,v&&(h=Date.now()),r.apply(void 0,c(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(p&&s)return y(),void b();d()}),l)},m=function(){p=!0;for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];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.getOnionFun=function(r,t){return g.apply(void 0,c(t.map((function(t){return t(r)}))))},exports.listToMap=function(r,t){return r.reduce((function(r,n){var o=n[t];return i(i({},r),{},e({},o,n))}),{})},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 n,e,o,i,u,a=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,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,c(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),n=0;n<r;n++)t[n]=arguments[n];u=t,i||(l&&h(),v())};return d.cancel=p,d.flush=function(){i&&s&&(h(),v())},d.fun=r,d},exports.toFixed=h,exports.uri=_,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"],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("")};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
+
import{isPlainObject as n,forEach as r,isNumber as t,get as e,isUndefinedOrNull as o,isUndefined as i}from"@cclr/lang";function u(n,r){(null==r||r>n.length)&&(r=n.length);for(var t=0,e=Array(r);t<r;t++)e[t]=n[t];return e}function a(n,r,t){return r&&function(n,r){for(var t=0;t<r.length;t++){var e=r[t];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(n,v(e.key),e)}}(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n}function c(n,r,t){return(r=v(r))in n?Object.defineProperty(n,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[r]=t,n}function l(n,r){var t=Object.keys(n);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(n);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(n,r).enumerable}))),t.push.apply(t,e)}return t}function f(n){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?l(Object(t),!0).forEach((function(r){c(n,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):l(Object(t)).forEach((function(r){Object.defineProperty(n,r,Object.getOwnPropertyDescriptor(t,r))}))}return n}function s(n,r){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,r){return n.__proto__=r,n},s(n,r)}function p(n,r){return function(n){if(Array.isArray(n))return n}(n)||function(n,r){var t=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=t){var e,o,i,u,a=[],c=!0,l=!1;try{if(i=(t=t.call(n)).next,0===r){if(Object(t)!==t)return;c=!1}else for(;!(c=(e=i.call(t)).done)&&(a.push(e.value),a.length!==r);c=!0);}catch(n){l=!0,o=n}finally{try{if(!c&&null!=t.return&&(u=t.return(),Object(u)!==u))return}finally{if(l)throw o}}return a}}(n,r)||y(n,r)||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(n){return function(n){if(Array.isArray(n))return u(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||y(n)||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(n){var r=function(n,r){if("object"!=typeof n||!n)return n;var t=n[Symbol.toPrimitive];if(void 0!==t){var e=t.call(n,r);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(n)}(n,"string");return"symbol"==typeof r?r:r+""}function y(n,r){if(n){if("string"==typeof n)return u(n,r);var t={}.toString.call(n).slice(8,-1);return"Object"===t&&n.constructor&&(t=n.constructor.name),"Map"===t||"Set"===t?Array.from(n):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?u(n,r):void 0}}function d(){d=function(n,r){return new t(n,void 0,r)};var n=RegExp.prototype,r=new WeakMap;function t(n,e,o){var i=RegExp(n,e);return r.set(i,o||r.get(n)),s(i,t.prototype)}function e(n,t){var e=r.get(t);return Object.keys(e).reduce((function(r,t){var o=e[t];if("number"==typeof o)r[t]=n[o];else{for(var i=0;void 0===n[o[i]]&&i+1<o.length;)i++;r[t]=n[o[i]]}return r}),Object.create(null))}return function(n,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");n.prototype=Object.create(r&&r.prototype,{constructor:{value:n,writable:!0,configurable:!0}}),Object.defineProperty(n,"prototype",{writable:!1}),r&&s(n,r)}(t,RegExp),t.prototype.exec=function(r){var t=n.exec.call(this,r);if(t){t.groups=e(t,this);var o=t.indices;o&&(o.groups=e(o,this))}return t},t.prototype[Symbol.replace]=function(t,o){if("string"==typeof o){var i=r.get(this);return n[Symbol.replace].call(this,t,o.replace(/\$<([^>]+)>/g,(function(n,r){var t=i[r];return"$"+(Array.isArray(t)?t.join("$"):t)})))}if("function"==typeof o){var u=this;return n[Symbol.replace].call(this,t,(function(){var n=arguments;return"object"!=typeof n[n.length-1]&&(n=[].slice.call(n)).push(e(n,u)),o.apply(this,n)}))}return n[Symbol.replace].call(this,t,o)},d.apply(this,arguments)}function b(n,r,t){r/=100,t/=100;var e=(1-Math.abs(2*t-1))*r,o=e*(1-Math.abs(n/60%2-1)),i=t-e/2,u=0,a=0,c=0;return n<60?(u=e,a=o,c=0):n<120?(u=o,a=e,c=0):n<180?(u=0,a=e,c=o):n<240?(u=0,a=o,c=e):n<300?(u=o,a=0,c=e):(u=e,a=0,c=o),[Math.round(255*(u+i)),Math.round(255*(a+i)),Math.round(255*(c+i))]}function m(n){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return n?(r<0&&(r=0),Number(n.toFixed(r))):0}var g=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;if(n>r){var t=[r,n];n=t[0],r=t[1]}else if(n===r)return m(n);return Math.floor(Math.random()*(r-n+1)+n)},O=Object.freeze({__proto__:null,randomInt:g,toFixed:m});function j(n){var r=n||{},t=r.h,e=r.l,o=r.s;return[g(t?t[0]:0,t?t[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(n){if(3===(n=n.replace(/^#/,"")).length&&(n=n.split("").map((function(n){return n+n})).join("")),!/^([0-9a-fA-F]{6})$/.test(n))throw new Error("Invalid hex color");var r=parseInt(n.slice(0,2),16)/255,t=parseInt(n.slice(2,4),16)/255,e=parseInt(n.slice(4,6),16)/255,o=Math.max(r,t,e),i=Math.min(r,t,e),u=0,a=0,c=(o+i)/2;if(o!==i){var l=o-i;switch(a=c>.5?l/(2-o-i):l/(o+i),o){case r:u=(t-e)/l+(t<e?6:0);break;case t:u=(e-r)/l+2;break;case e:u=(r-t)/l+4}u*=60}return[Math.round(u),Math.round(100*a),Math.round(100*c)]},hexToRgb:function(n){if(3===(n=n.replace(/^#/,"")).length&&(n=n.split("").map((function(n){return n+n})).join("")),6!==n.length)throw new Error("Invalid hex color format. Use #RRGGBB or #RGB.");return[parseInt(n.slice(0,2),16),parseInt(n.slice(2,4),16),parseInt(n.slice(4,6),16)]},hslToRgb:b,hslToRgbString:function(n,r,t){var e=p(b(n,r,t),3),o=e[0],i=e[1],u=e[2];return"rgb(".concat(o,", ").concat(i,", ").concat(u,")")},randomHSL:j,randomHSLString:function(n){var r=p(j(n),3),t=r[0],e=r[1],o=r[2];return"hsl(".concat(t,", ").concat(e,"%, ").concat(o,"%)")},randomHex:function(){var n=Math.floor(16777215*Math.random()).toString(16).padStart(6,"0");return"#".concat(n.toUpperCase())}}),S=function(n){return JSON.parse(JSON.stringify(n))},P=function(r){return n(r)?[Object.keys(r)]:[]},x=function(n,r){return n.reduce((function(n,t){var e=t[r];return f(f({},n),{},c({},e,t))}),{})};function A(n,r){return n<=r[1]&&n>=r[0]}var I=function(){for(var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,r=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],t=[],e=0;e<n;e++)t[e]=8===e||13===e||18===e||23===e?"-":r[Math.ceil(Math.random()*r.length-1)];return t.join("")},M=function(){return a((function n(){!function(n,r){if(!(n instanceof r))throw new TypeError("Cannot call a class as a function")}(this,n),c(this,"handler",[])}),[{key:"use",value:function(n,r){return this.handler.push({fulfilled:n,rejected:r}),this.handler.length-1}},{key:"eject",value:function(n){this.handler[n]&&(this.handler[n]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(n){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];r(this.handler,(function(r){r&&n(r)}),t)}},{key:"run",value:function(n){var r=arguments;return new Promise(function(t,e){var o=r.length>1&&void 0!==r[1]&&r[1],i=Promise.resolve(n());return this.forEach((function(n){i=i.then(n.fulfilled,n.rejected)}),o),t(i)}.bind(this))}}])}();function E(){for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];return 0===r.length?function(n){return n}:1===r.length?r[0]:r.reduce((function(n,r){return function(){return n(r.apply(void 0,arguments))}}))}var T=function(n,r){return E.apply(void 0,h(r.map((function(r){return r(n)}))))},R=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),k=d(/\?([^#]*)/,{query:1}),_=d(/#(.*)/,{hash:1}),q=d(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),C=function(n,r){var t,e,o,i,u,a=null==r?void 0:r.maxWait,c=null!==(t=null==r?void 0:r.wait)&&void 0!==t?t:500,l=null===(e=null==r?void 0:r.leading)||void 0===e||e,f=null===(o=null==r?void 0:r.trailing)||void 0===o||o,s=!1,p=0,v=a&&a>c,y=function(){clearTimeout(i),i=null},d=function(){s=!1,v&&(p=Date.now()),n.apply(void 0,h(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return d(),void b();y()}),c)},m=function(){s=!0;for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];u=r,i||(l?d():v&&(p=Date.now())),v&&Date.now()-p>=a&&(d(),b()),b()};return m.cancel=y,m.flush=function(){i&&s&&(d(),b())},m.fun=n,m},U=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(t(n))return new Promise((function(r){return setTimeout(r,n)}))},D=function(n,r){var t,e,o,i,u,a=null!==(t=null==r?void 0:r.wait)&&void 0!==t?t:500,c=null===(e=null==r?void 0:r.leading)||void 0===e||e,l=null===(o=null==r?void 0:r.trailing)||void 0===o||o,f=!1,s=function(){clearTimeout(i),i=null,f=!1},p=function(){f=!1,n.apply(void 0,h(u))},v=function(){clearTimeout(i),i=setTimeout((function(){if(f&&l)return p(),void v();s()}),a)},y=function(){f=!0;for(var n=arguments.length,r=new Array(n),t=0;t<n;t++)r[t]=arguments[t];u=r,i||(c&&p(),v())};return y.cancel=s,y.flush=function(){i&&f&&(p(),v())},y.fun=n,y},z=function(n){var r=n.protocol,t=n.auth,e=n.host,o=n.hostname,i=n.port,u=n.pathname,a=n.query,c=n.search,l=n.hash,f=r?"".concat(r,"//"):"",s=t?"".concat(t,"@"):"",p=e||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):c||"",v=l?"#".concat(l):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(v)},N=function(n){if(!n)return"";var r=n.split("?")[1];return r?r.replace(_,""):""},$=function(n){if(!n)return{};var r=N(n);return r?r.split("&").reduce((function(n,r){var t=r.indexOf("="),e=(-1!==t?[r.substring(0,t),r.substring(t+1)]:[r]).map((function(n){return decodeURIComponent(n.replace("+"," "))}));return n[e[0]]=e[1],n}),{}):{}};function B(n){var r=n.match(R),t=e(r,"groups",{}),o=t.protocol,i=t.auth,u=t.host,a=t.pathname,c=t.query,l=t.hash,f=null,s=null;if(u){var h=p(u.split(":"),2);f=h[0],s=h[1]||null}return{href:n,protocol:o||null,slashes:n.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:f||null,port:s||null,pathname:a||null,search:c?"?".concat(c):null,query:c||null,hash:l||null}}var H=function(n){var r=[];for(var t in n){var e=n[t];o(e)?r.push(encodeURIComponent(t)+"="):r.push(encodeURIComponent(t)+"="+encodeURIComponent(e))}return r.join("&")},Q=["queryObj"],Z=function(n,r){var t=r.queryObj,e=function(n,r){if(null==n)return{};var t,e,o=function(n,r){if(null==n)return{};var t={};for(var e in n)if({}.hasOwnProperty.call(n,e)){if(-1!==r.indexOf(e))continue;t[e]=n[e]}return t}(n,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(n);for(e=0;e<i.length;e++)t=i[e],-1===r.indexOf(t)&&{}.propertyIsEnumerable.call(n,t)&&(o[t]=n[t])}return o}(r,Q),o=f(f({},B(n)),e),i=f(f({},$(o.search||"")),t);return z(f(f({},o),{},{search:"",query:H(i)}))};function F(n){var r,t=n.match(q);if(t)return(null===(r=t.groups)||void 0===r?void 0:r.pathname)||""}var G={parseUrl:B,getPathArr:function(n){var r=F(n);if(!i(r))return r.split("/").filter(Boolean)},getPathStr:F,getQuery:N,getQueryObj:$,toQueryString:H,change:Z,addQuery:function(n,r){return Z(n,{queryObj:r})},combine:z};export{w as Color,_ as HASH_REGEX,M as Interceptor,O as Num,q as PATHNAME_REGEX,k as QUERY_REGEX,R as URL_REGEX,E as compose,C as debounce,S as deepClone,P as enumToArray,T as getOnionFun,x as listToMap,A as numInRange,g as randomInt,U as sleep,D as throttle,m as toFixed,G as uri,I as uuid};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _cclr_lang from '@cclr/lang';
|
|
2
|
-
import { TAny, TPlainObject, TPlainFunction } from '@cclr/lang';
|
|
2
|
+
import { TAny, TPlainObject, TPlainFunction, TNoop } from '@cclr/lang';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* hex 转 HSL
|
|
@@ -145,6 +145,20 @@ declare class Interceptor<T> {
|
|
|
145
145
|
run(fun: () => T | PromiseLike<T>, reverse?: boolean): Promise<T>;
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
declare function compose(...funcs: TPlainFunction[]): TPlainFunction;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* 洋葱函数类型
|
|
152
|
+
*/
|
|
153
|
+
type TOnionFun<T extends TAny> = (ctx: T) => (next: TNoop) => () => Promise<unknown> | unknown;
|
|
154
|
+
/**
|
|
155
|
+
* 获取洋葱函数
|
|
156
|
+
* @param ctx 上下文
|
|
157
|
+
* @param funs 洋葱函数数组
|
|
158
|
+
* @returns 返回组合后的函数
|
|
159
|
+
*/
|
|
160
|
+
declare const getOnionFun: <T>(ctx: T, funs: TOnionFun<T>[]) => _cclr_lang.TPlainFunction;
|
|
161
|
+
|
|
148
162
|
declare const URL_REGEX: RegExp;
|
|
149
163
|
declare const QUERY_REGEX: RegExp;
|
|
150
164
|
declare const HASH_REGEX: RegExp;
|
|
@@ -252,4 +266,4 @@ declare const uri: {
|
|
|
252
266
|
combine: (urlParams: IUrl) => string;
|
|
253
267
|
};
|
|
254
268
|
|
|
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 };
|
|
269
|
+
export { index$1 as Color, HASH_REGEX, type IUrl, Interceptor, index as Num, PATHNAME_REGEX, QUERY_REGEX, type TOnionFun, URL_REGEX, compose, debounce, deepClone, enumToArray, getOnionFun, 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.
|
|
3
|
+
"version": "0.1.27",
|
|
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": "
|
|
33
|
+
"gitHead": "2b6756ab4c870ab07003c6111026d6d89e73415f",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cclr/lang": "0.1.
|
|
35
|
+
"@cclr/lang": "0.1.27"
|
|
36
36
|
}
|
|
37
37
|
}
|