@cclr/utils 0.1.27 → 0.1.29

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,3 @@
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("")};
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,e,o,i,u){try{var a=r[i](u),c=a.value}catch(r){return void n(r)}a.done?t(c):Promise.resolve(c).then(e,o)}function e(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,p(e.key),e)}}(r.prototype,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function o(r,t,n){return(t=p(t))in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function i(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 u(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach(function(t){o(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))})}return r}function a(){
2
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
+ var r,t,n="function"==typeof Symbol?Symbol:{},e=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,e,o,i){var a=e&&e.prototype instanceof l?e:l,f=Object.create(a.prototype);return c(f,"_invoke",function(n,e,o){var i,a,c,l=0,f=o||[],s=!1,p={p:0,n:0,v:r,a:h,f:h.bind(r,4),d:function(t,n){return i=t,a=0,c=r,p.n=n,u}};function h(n,e){for(a=n,c=e,t=0;!s&&l&&!o&&t<f.length;t++){var o,i=f[t],h=p.p,v=i[2];n>3?(o=v===e)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=r):i[0]<=h&&((o=n<2&&h<i[1])?(a=0,p.v=e,p.n=i[1]):h<v&&(o=n<3||i[0]>e||e>v)&&(i[4]=n,i[5]=e,p.n=v,a=0))}if(o||n>1)return u;throw s=!0,e}return function(o,f,v){if(l>1)throw TypeError("Generator is already running");for(s&&1===f&&h(f,v),a=f,c=v;(t=a<2?r:c)||!s;){i||(a?a<3?(a>1&&(p.n=-1),h(a,c)):p.n=c:p.v=c);try{if(l=2,i){if(a||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=r}else if((t=(s=p.n<0)?c:n.call(e,p))!==u)break}catch(t){i=r,a=1,c=t}finally{l=1}}return{value:t,done:s}}}(n,o,i),!0),f}var u={};function l(){}function f(){}function s(){}t=Object.getPrototypeOf;var p=[][e]?t(t([][e]())):(c(t={},e,function(){return this}),t),h=s.prototype=l.prototype=Object.create(p);function v(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,s):(r.__proto__=s,c(r,o,"GeneratorFunction")),r.prototype=Object.create(h),r}return f.prototype=s,c(h,"constructor",s),c(s,"constructor",f),f.displayName="GeneratorFunction",c(s,o,"GeneratorFunction"),c(h),c(h,o,"Generator"),c(h,e,function(){return this}),c(h,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:v}})()}function c(r,t,n,e){var o=Object.defineProperty;try{o({},"",{})}catch(r){o=0}c=function(r,t,n,e){function i(t,n){c(r,t,function(r){return this._invoke(t,n,r)})}t?o?o(r,t,{value:n,enumerable:!e,configurable:!e,writable:!e}):r[t]=n:(i("next",0),i("throw",1),i("return",2))},c(r,t,n,e)}function l(r,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},l(r,t)}function f(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)||h(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 s(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)||h(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 p(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 h(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 v(){v=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)),l(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&&l(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,n){if(""===n)return r;var e=i[t];return Array.isArray(e)?"$"+e.join("$"):"number"==typeof e?"$"+e:""}))}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)},v.apply(this,arguments)}function y(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 d(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 b=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 d(r);return Math.floor(Math.random()*(t-r+1)+r)},m=Object.freeze({__proto__:null,randomInt:b,toFixed:d});function g(r){var t=r||{},n=t.h,e=t.l,o=t.s;return[b(n?n[0]:0,n?n[1]:359),b(e?e[0]:50,e?e[1]:100),b(o?o[0]:50,o?o[1]:50)]}var O=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:y,hslToRgbString:function(r,t,n){var e=f(y(r,t,n),3),o=e[0],i=e[1],u=e[2];return"rgb(".concat(o,", ").concat(i,", ").concat(u,")")},randomHSL:g,randomHSLString:function(r){var t=f(g(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())}}),j=function(t,n){if(r.isUndefinedOrNull(n))return t;return function(t,n){if(r.isUndefinedOrNull(t))return n;if(!r.isPlainObject(t))return n;if(!r.isPlainObject(n))return n;var e=u({},t);for(var o in n){var i=t[o],a=n[o];e[o]=j(i,a)}return e}(t,n)};var w=function(){return e(function r(){!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),o(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:(t=a().m(function r(t){var n,e,o=arguments;return a().w(function(r){for(;;)if(0===r.n)return n=o.length>1&&void 0!==o[1]&&o[1],e=Promise.resolve(t()),this.forEach(function(r){e=e.then(r.fulfilled,r.rejected)},n),r.a(2,e)},r,this)}),i=function(){var r=this,e=arguments;return new Promise(function(o,i){var u=t.apply(r,e);function a(r){n(u,o,i,a,c,"next",r)}function c(r){n(u,o,i,a,c,"throw",r)}a(void 0)})},function(r){return i.apply(this,arguments)})}]);var t,i}();function x(){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 P=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),S=v(/\?([^#]*)/,{query:1}),E=v(/#(.*)/,{hash:1}),A=v(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),T=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)},I=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(E,""):""},R=function(r){if(!r)return{};var t=I(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 _(t){var n=t.match(P),e=r.get(n,"groups",{}),o=e.protocol,i=e.auth,u=e.host,a=e.pathname,c=e.query,l=e.hash,s=null,p=null;if(u){var h=f(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:a||null,search:c?"?".concat(c):null,query:c||null,hash:l||null}}var M=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("&")},U=["queryObj"],k=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,U),o=u(u({},_(r)),e),i=u(u({},R(o.search||"")),n);return T(u(u({},o),{},{search:"",query:M(i)}))};function N(r){var t,n=r.match(A);if(n)return(null===(t=n.groups)||void 0===t?void 0:t.pathname)||""}var G={parseUrl:_,getPathArr:function(t){var n=N(t);if(!r.isUndefined(n))return n.split("/").filter(Boolean)},getPathStr:N,getQuery:I,getQueryObj:R,toQueryString:M,change:k,addQuery:function(r,t){return k(r,{queryObj:t})},combine:T};exports.Color=O,exports.HASH_REGEX=E,exports.Interceptor=w,exports.Num=m,exports.PATHNAME_REGEX=A,exports.QUERY_REGEX=S,exports.URL_REGEX=P,exports.compose=x,exports.debounce=function(r,t){var n,e,o,i,u,a=null==t?void 0:t.maxWait,c=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,p=!1,h=0,v=a&&a>c,y=function(){clearTimeout(i),i=null},d=function(){p=!1,v&&(h=Date.now()),r.apply(void 0,s(u))},b=function(){clearTimeout(i),i=setTimeout(function(){if(p&&f)return d(),void b();y()},c)},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||(l?d():v&&(h=Date.now())),v&&Date.now()-h>=a&&(d(),b()),b()};return m.cancel=y,m.flush=function(){i&&p&&(d(),b())},m.fun=r,m},exports.deepClone=function(r){return JSON.parse(JSON.stringify(r))},exports.deepFilterNil=function(t){if(!r.isPlainObject(t)&&!r.isArray(t))return t;return function t(n){if(!r.isPlainObject(n)&&!r.isArray(n))return n;if(r.isArray(n))for(var e=0;e<n.length;e++){var o=n[e];r.isUndefinedOrNull(o)?(n.splice(e,1),e--):r.isObject(o)&&(n[e]=t(o))}else for(var i in n){var u=n[i];r.isUndefinedOrNull(u)?Reflect.deleteProperty(n,i):r.isObject(u)&&(n[i]=t(u))}return n}(t)},exports.deepMergeObj=j,exports.enumToArray=function(t){return r.isPlainObject(t)?[Object.keys(t)]:[]},exports.getOnionFun=function(r,t){return x.apply(void 0,s(t.map(function(t){return t(r)})))},exports.listToMap=function(r,t){return r.reduce(function(r,n){var e=n[t];return u(u({},r),{},o({},e,n))},{})},exports.numInRange=function(r,t){return r<=t[1]&&r>=t[0]},exports.randomInt=b,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,c=null===(e=null==t?void 0:t.leading)||void 0===e||e,l=null===(o=null==t?void 0:t.trailing)||void 0===o||o,f=!1,p=function(){clearTimeout(i),i=null,f=!1},h=function(){f=!1,r.apply(void 0,s(u))},v=function(){clearTimeout(i),i=setTimeout(function(){if(f&&l)return h(),void v();p()},a)},y=function(){f=!0;for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];u=t,i||(c&&h(),v())};return y.cancel=p,y.flush=function(){i&&f&&(h(),v())},y.fun=r,y},exports.toFixed=d,exports.uri=G,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,3 @@
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};
1
+ import{isPlainObject as r,isArray as t,isUndefinedOrNull as n,isObject as e,forEach as o,isNumber as i,get as u,isUndefined as a}from"@cclr/lang";function c(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 l(r,t,n,e,o,i,u){try{var a=r[i](u),c=a.value}catch(r){return void n(r)}a.done?t(c):Promise.resolve(c).then(e,o)}function f(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,g(e.key),e)}}(r.prototype,t),Object.defineProperty(r,"prototype",{writable:!1}),r}function p(r,t,n){return(t=g(t))in r?Object.defineProperty(r,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):r[t]=n,r}function s(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 h(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach(function(t){p(r,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach(function(t){Object.defineProperty(r,t,Object.getOwnPropertyDescriptor(n,t))})}return r}function v(){
2
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
+ var r,t,n="function"==typeof Symbol?Symbol:{},e=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,e,o,i){var c=e&&e.prototype instanceof a?e:a,l=Object.create(c.prototype);return y(l,"_invoke",function(n,e,o){var i,a,c,l=0,f=o||[],p=!1,s={p:0,n:0,v:r,a:h,f:h.bind(r,4),d:function(t,n){return i=t,a=0,c=r,s.n=n,u}};function h(n,e){for(a=n,c=e,t=0;!p&&l&&!o&&t<f.length;t++){var o,i=f[t],h=s.p,v=i[2];n>3?(o=v===e)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=r):i[0]<=h&&((o=n<2&&h<i[1])?(a=0,s.v=e,s.n=i[1]):h<v&&(o=n<3||i[0]>e||e>v)&&(i[4]=n,i[5]=e,s.n=v,a=0))}if(o||n>1)return u;throw p=!0,e}return function(o,f,v){if(l>1)throw TypeError("Generator is already running");for(p&&1===f&&h(f,v),a=f,c=v;(t=a<2?r:c)||!p;){i||(a?a<3?(a>1&&(s.n=-1),h(a,c)):s.n=c:s.v=c);try{if(l=2,i){if(a||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=r}else if((t=(p=s.n<0)?c:n.call(e,s))!==u)break}catch(t){i=r,a=1,c=t}finally{l=1}}return{value:t,done:p}}}(n,o,i),!0),l}var u={};function a(){}function c(){}function l(){}t=Object.getPrototypeOf;var f=[][e]?t(t([][e]())):(y(t={},e,function(){return this}),t),p=l.prototype=a.prototype=Object.create(f);function s(r){return Object.setPrototypeOf?Object.setPrototypeOf(r,l):(r.__proto__=l,y(r,o,"GeneratorFunction")),r.prototype=Object.create(p),r}return c.prototype=l,y(p,"constructor",l),y(l,"constructor",c),c.displayName="GeneratorFunction",y(l,o,"GeneratorFunction"),y(p),y(p,o,"Generator"),y(p,e,function(){return this}),y(p,"toString",function(){return"[object Generator]"}),(v=function(){return{w:i,m:s}})()}function y(r,t,n,e){var o=Object.defineProperty;try{o({},"",{})}catch(r){o=0}y=function(r,t,n,e){function i(t,n){y(r,t,function(r){return this._invoke(t,n,r)})}t?o?o(r,t,{value:n,enumerable:!e,configurable:!e,writable:!e}):r[t]=n:(i("next",0),i("throw",1),i("return",2))},y(r,t,n,e)}function d(r,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,t){return r.__proto__=t,r},d(r,t)}function b(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)||O(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 m(r){return function(r){if(Array.isArray(r))return c(r)}(r)||function(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}(r)||O(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 g(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 O(r,t){if(r){if("string"==typeof r)return c(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)?c(r,t):void 0}}function j(){j=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)),d(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&&d(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,n){if(""===n)return r;var e=i[t];return Array.isArray(e)?"$"+e.join("$"):"number"==typeof e?"$"+e:""}))}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)},j.apply(this,arguments)}function w(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 S(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 P=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 S(r);return Math.floor(Math.random()*(t-r+1)+r)},x=Object.freeze({__proto__:null,randomInt:P,toFixed:S});function T(r){var t=r||{},n=t.h,e=t.l,o=t.s;return[P(n?n[0]:0,n?n[1]:359),P(e?e[0]:50,e?e[1]:100),P(o?o[0]:50,o?o[1]:50)]}var A=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:w,hslToRgbString:function(r,t,n){var e=b(w(r,t,n),3),o=e[0],i=e[1],u=e[2];return"rgb(".concat(o,", ").concat(i,", ").concat(u,")")},randomHSL:T,randomHSLString:function(r){var t=b(T(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())}}),E=function(r){return JSON.parse(JSON.stringify(r))},I=function(o){if(!r(o)&&!t(o))return o;return function o(i){if(!r(i)&&!t(i))return i;if(t(i))for(var u=0;u<i.length;u++){var a=i[u];n(a)?(i.splice(u,1),u--):e(a)&&(i[u]=o(a))}else for(var c in i){var l=i[c];n(l)?Reflect.deleteProperty(i,c):e(l)&&(i[c]=o(l))}return i}(o)},M=function(t){return r(t)?[Object.keys(t)]:[]},_=function(r,t){return r.reduce(function(r,n){var e=n[t];return h(h({},r),{},p({},e,n))},{})},k=function(t,e){if(n(e))return t;return function(t,e){if(n(t))return e;if(!r(t))return e;if(!r(e))return e;var o=h({},t);for(var i in e){var u=t[i],a=e[i];o[i]=k(u,a)}return o}(t,e)};function R(r,t){return r<=t[1]&&r>=t[0]}var q=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("")},G=function(){return f(function r(){!function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}(this,r),p(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 t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];o(this.handler,function(t){t&&r(t)},t)}},{key:"run",value:(r=v().m(function r(t){var n,e,o=arguments;return v().w(function(r){for(;;)if(0===r.n)return n=o.length>1&&void 0!==o[1]&&o[1],e=Promise.resolve(t()),this.forEach(function(r){e=e.then(r.fulfilled,r.rejected)},n),r.a(2,e)},r,this)}),t=function(){var t=this,n=arguments;return new Promise(function(e,o){var i=r.apply(t,n);function u(r){l(i,e,o,u,a,"next",r)}function a(r){l(i,e,o,u,a,"throw",r)}u(void 0)})},function(r){return t.apply(this,arguments)})}]);var r,t}();function C(){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 U=function(r,t){return C.apply(void 0,m(t.map(function(t){return t(r)})))},D=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),$=j(/\?([^#]*)/,{query:1}),z=j(/#(.*)/,{hash:1}),F=j(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),N=function(r,t){var n,e,o,i,u,a=null==t?void 0:t.maxWait,c=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,p=!1,s=0,h=a&&a>c,v=function(){clearTimeout(i),i=null},y=function(){p=!1,h&&(s=Date.now()),r.apply(void 0,m(u))},d=function(){clearTimeout(i),i=setTimeout(function(){if(p&&f)return y(),void d();v()},c)},b=function(){p=!0;for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];u=t,i||(l?y():h&&(s=Date.now())),h&&Date.now()-s>=a&&(y(),d()),d()};return b.cancel=v,b.flush=function(){i&&p&&(y(),d())},b.fun=r,b},B=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(i(r))return new Promise(function(t){return setTimeout(t,r)})},H=function(r,t){var n,e,o,i,u,a=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,l=null===(o=null==t?void 0:t.trailing)||void 0===o||o,f=!1,p=function(){clearTimeout(i),i=null,f=!1},s=function(){f=!1,r.apply(void 0,m(u))},h=function(){clearTimeout(i),i=setTimeout(function(){if(f&&l)return s(),void h();p()},a)},v=function(){f=!0;for(var r=arguments.length,t=new Array(r),n=0;n<r;n++)t[n]=arguments[n];u=t,i||(c&&s(),h())};return v.cancel=p,v.flush=function(){i&&f&&(s(),h())},v.fun=r,v},Q=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,"//"):"",p=n?"".concat(n,"@"):"",s=e||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):c||"",v=l?"#".concat(l):"";return"".concat(f).concat(p).concat(s).concat(u).concat(h).concat(v)},Z=function(r){if(!r)return"";var t=r.split("?")[1];return t?t.replace(z,""):""},J=function(r){if(!r)return{};var t=Z(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 L(r){var t=r.match(D),n=u(t,"groups",{}),e=n.protocol,o=n.auth,i=n.host,a=n.pathname,c=n.query,l=n.hash,f=null,p=null;if(i){var s=b(i.split(":"),2);f=s[0],p=s[1]||null}return{href:r,protocol:e||null,slashes:r.includes("//")||null,auth:o?o.slice(0,-1):null,host:i||null,hostname:f||null,port:p||null,pathname:a||null,search:c?"?".concat(c):null,query:c||null,hash:l||null}}var W=function(r){var t=[];for(var e in r){var o=r[e];n(o)?t.push(encodeURIComponent(e)+"="):t.push(encodeURIComponent(e)+"="+encodeURIComponent(o))}return t.join("&")},K=["queryObj"],V=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,K),o=h(h({},L(r)),e),i=h(h({},J(o.search||"")),n);return Q(h(h({},o),{},{search:"",query:W(i)}))};function X(r){var t,n=r.match(F);if(n)return(null===(t=n.groups)||void 0===t?void 0:t.pathname)||""}var Y={parseUrl:L,getPathArr:function(r){var t=X(r);if(!a(t))return t.split("/").filter(Boolean)},getPathStr:X,getQuery:Z,getQueryObj:J,toQueryString:W,change:V,addQuery:function(r,t){return V(r,{queryObj:t})},combine:Q};export{A as Color,z as HASH_REGEX,G as Interceptor,x as Num,F as PATHNAME_REGEX,$ as QUERY_REGEX,D as URL_REGEX,C as compose,N as debounce,E as deepClone,I as deepFilterNil,k as deepMergeObj,M as enumToArray,U as getOnionFun,_ as listToMap,R as numInRange,P as randomInt,B as sleep,H as throttle,S as toFixed,Y as uri,q as uuid};
@@ -1,5 +1,5 @@
1
1
  import * as _cclr_lang from '@cclr/lang';
2
- import { TAny, TPlainObject, TPlainFunction, TNoop } from '@cclr/lang';
2
+ import { TAny, TPlainObject, TUndefinedOrNull, TPlainFunction, TNoop } from '@cclr/lang';
3
3
 
4
4
  /**
5
5
  * hex 转 HSL
@@ -57,7 +57,15 @@ declare const index$1_randomHSL: typeof randomHSL;
57
57
  declare const index$1_randomHSLString: typeof randomHSLString;
58
58
  declare const index$1_randomHex: typeof randomHex;
59
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 };
60
+ export {
61
+ index$1_hexToHsl as hexToHsl,
62
+ index$1_hexToRgb as hexToRgb,
63
+ index$1_hslToRgb as hslToRgb,
64
+ index$1_hslToRgbString as hslToRgbString,
65
+ index$1_randomHSL as randomHSL,
66
+ index$1_randomHSLString as randomHSLString,
67
+ index$1_randomHex as randomHex,
68
+ };
61
69
  }
62
70
 
63
71
  /**
@@ -78,7 +86,10 @@ declare function toFixed(num: number, fix?: number): number;
78
86
  declare const index_randomInt: typeof randomInt;
79
87
  declare const index_toFixed: typeof toFixed;
80
88
  declare namespace index {
81
- export { index_randomInt as randomInt, index_toFixed as toFixed };
89
+ export {
90
+ index_randomInt as randomInt,
91
+ index_toFixed as toFixed,
92
+ };
82
93
  }
83
94
 
84
95
  /**
@@ -88,6 +99,13 @@ declare namespace index {
88
99
  */
89
100
  declare const deepClone: <T extends object | TAny[]>(Obj: T) => T;
90
101
 
102
+ /**
103
+ * 深度过滤对象中的 null 和 undefined
104
+ * @description 数组也会被处理
105
+ * @param object
106
+ */
107
+ declare const deepFilterNil: <T extends TAny>(object: T) => TPlainObject | T;
108
+
91
109
  /**
92
110
  * 枚举key变成数组
93
111
  * @param e
@@ -97,6 +115,21 @@ declare const enumToArray: (e: TPlainObject) => string[][];
97
115
 
98
116
  declare const listToMap: <T extends TPlainObject, K extends keyof T>(list: T[], key: K) => Record<T[K], T>;
99
117
 
118
+ /**
119
+ * 深度合并两个对象,将 orange 的属性合并到 target 上,返回一个新的对象。
120
+ * @description 对比规则:
121
+ * - 1. 只要target只要有相同属性,就会覆盖 orange 的属性;
122
+ * - 2. object 会递归比对
123
+ * @example
124
+ * - '123' {} => {}
125
+ * - {} undefined => {}
126
+ *
127
+ * @param orange 原始对象 | undefined | null
128
+ * @param target 目标对象 | undefined | null
129
+ * @returns 合并后的新对象
130
+ */
131
+ declare const deepMergeObj: <T extends TPlainObject>(orange: T | TUndefinedOrNull, target: unknown) => T;
132
+
100
133
  declare function numInRange(num: number, range: [number, number]): boolean;
101
134
 
102
135
  /**
@@ -266,4 +299,5 @@ declare const uri: {
266
299
  combine: (urlParams: IUrl) => string;
267
300
  };
268
301
 
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 };
302
+ export { index$1 as Color, HASH_REGEX, Interceptor, index as Num, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, compose, debounce, deepClone, deepFilterNil, deepMergeObj, enumToArray, getOnionFun, listToMap, numInRange, randomInt, sleep, throttle, toFixed, uri, uuid };
303
+ export type { IUrl, TOnionFun };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cclr/utils",
3
- "version": "0.1.27",
3
+ "version": "0.1.29",
4
4
  "description": "> TODO: description",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -26,12 +26,12 @@
26
26
  "scripts": {
27
27
  "test": "vitest",
28
28
  "relese": "npm run test && npm publish",
29
- "build": "ccf build",
29
+ "build": "drr build",
30
30
  "g:test": "vitest run",
31
- "g:build": "ccf build"
31
+ "g:build": "drr build"
32
32
  },
33
- "gitHead": "2b6756ab4c870ab07003c6111026d6d89e73415f",
33
+ "gitHead": "1d49762197a47eb6aa9b2bd012fead57e38c7ad1",
34
34
  "dependencies": {
35
- "@cclr/lang": "0.1.27"
35
+ "@cclr/lang": "0.1.29"
36
36
  }
37
37
  }