@cclr/utils 0.1.17 → 0.1.19
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 +6 -2
- package/package.json +3 -3
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("@cclr/lang");function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r){return t&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,c(n.key),n)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function n(e,t,r){return(t=c(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t);else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,t)||f(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||f(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function f(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}function s(){s=function(e,t){return new r(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function r(e,n,o){var i=RegExp(e,n);return t.set(i,o||t.get(e)),u(i,r.prototype)}function n(e,r){var n=t.get(r);return Object.keys(n).reduce((function(t,r){var o=n[r];if("number"==typeof o)t[r]=e[o];else{for(var i=0;void 0===e[o[i]]&&i+1<o.length;)i++;t[r]=e[o[i]]}return t}),Object.create(null))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(r,RegExp),r.prototype.exec=function(t){var r=e.exec.call(this,t);if(r){r.groups=n(r,this);var o=r.indices;o&&(o.groups=n(o,this))}return r},r.prototype[Symbol.replace]=function(r,o){if("string"==typeof o){var i=t.get(this);return e[Symbol.replace].call(this,r,o.replace(/\$<([^>]+)>/g,(function(e,t){var r=i[t];return"$"+(Array.isArray(r)?r.join("$"):r)})))}if("function"==typeof o){var u=this;return e[Symbol.replace].call(this,r,(function(){var e=arguments;return"object"!=typeof e[e.length-1]&&(e=[].slice.call(e)).push(n(e,u)),o.apply(this,e)}))}return e[Symbol.replace].call(this,r,o)},s.apply(this,arguments)}var p=function(){return r((function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),n(this,"handler",[])}),[{key:"use",value:function(e,t){return this.handler.push({fulfilled:e,rejected:t}),this.handler.length-1}},{key:"eject",value:function(e){this.handler[e]&&(this.handler[e]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.forEach(this.handler,(function(e){e&&t(e)}),r)}},{key:"run",value:function(e){var t=arguments;return new Promise(function(r,n){var o=t.length>1&&void 0!==t[1]&&t[1],i=Promise.resolve(e());return this.forEach((function(e){i=i.then(e.fulfilled,e.rejected)}),o),r(i)}.bind(this))}}])}(),h=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),y=s(/\?([^#]*)/,{query:1}),v=s(/#(.*)/,{hash:1}),d=s(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),b=function(e){var t=e.protocol,r=e.auth,n=e.host,o=e.hostname,i=e.port,u=e.pathname,a=e.query,l=e.search,c=e.hash,f=t?"".concat(t,"//"):"",s=r?"".concat(r,"@"):"",p=n||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):l||"",y=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(y)},m=function(e){if(!e)return"";var t=e.split("?")[1];return t?t.replace(v,""):""},g=function(e){if(!e)return{};var t=m(e);return t?t.split("&").reduce((function(e,t){var r=t.indexOf("="),n=(-1!==r?[t.substring(0,r),t.substring(r+1)]:[t]).map((function(e){return decodeURIComponent(e.replace("+"," "))}));return e[n[0]]=n[1],e}),{}):{}};function O(t){var r=t.match(h),n=e.get(r,"groups",{}),o=n.protocol,i=n.auth,u=n.host,l=n.pathname,c=n.query,f=n.hash,s=null,p=null;if(u){var y=a(u.split(":"),2);s=y[0],p=y[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:s||null,port:p||null,pathname:l||null,search:c?"?".concat(c):null,query:c||null,hash:f||null}}var j=function(t){var r=[];for(var n in t){var o=t[n];e.isUndefinedOrNull(o)?r.push(encodeURIComponent(n)+"="):r.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return r.join("&")},w=["queryObj"],
|
|
1
|
+
"use strict";var e=require("@cclr/lang");function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r){return t&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,c(n.key),n)}}(e.prototype,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function n(e,t,r){return(t=c(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function u(e,t){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},u(e,t)}function a(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,u,a=[],l=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t);else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(e,t)||f(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function l(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||f(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function c(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}function f(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}function s(){s=function(e,t){return new r(e,void 0,t)};var e=RegExp.prototype,t=new WeakMap;function r(e,n,o){var i=RegExp(e,n);return t.set(i,o||t.get(e)),u(i,r.prototype)}function n(e,r){var n=t.get(r);return Object.keys(n).reduce((function(t,r){var o=n[r];if("number"==typeof o)t[r]=e[o];else{for(var i=0;void 0===e[o[i]]&&i+1<o.length;)i++;t[r]=e[o[i]]}return t}),Object.create(null))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&u(e,t)}(r,RegExp),r.prototype.exec=function(t){var r=e.exec.call(this,t);if(r){r.groups=n(r,this);var o=r.indices;o&&(o.groups=n(o,this))}return r},r.prototype[Symbol.replace]=function(r,o){if("string"==typeof o){var i=t.get(this);return e[Symbol.replace].call(this,r,o.replace(/\$<([^>]+)>/g,(function(e,t){var r=i[t];return"$"+(Array.isArray(r)?r.join("$"):r)})))}if("function"==typeof o){var u=this;return e[Symbol.replace].call(this,r,(function(){var e=arguments;return"object"!=typeof e[e.length-1]&&(e=[].slice.call(e)).push(n(e,u)),o.apply(this,e)}))}return e[Symbol.replace].call(this,r,o)},s.apply(this,arguments)}var p=function(){return r((function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),n(this,"handler",[])}),[{key:"use",value:function(e,t){return this.handler.push({fulfilled:e,rejected:t}),this.handler.length-1}},{key:"eject",value:function(e){this.handler[e]&&(this.handler[e]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.forEach(this.handler,(function(e){e&&t(e)}),r)}},{key:"run",value:function(e){var t=arguments;return new Promise(function(r,n){var o=t.length>1&&void 0!==t[1]&&t[1],i=Promise.resolve(e());return this.forEach((function(e){i=i.then(e.fulfilled,e.rejected)}),o),r(i)}.bind(this))}}])}(),h=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),y=s(/\?([^#]*)/,{query:1}),v=s(/#(.*)/,{hash:1}),d=s(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),b=function(e){var t=e.protocol,r=e.auth,n=e.host,o=e.hostname,i=e.port,u=e.pathname,a=e.query,l=e.search,c=e.hash,f=t?"".concat(t,"//"):"",s=r?"".concat(r,"@"):"",p=n||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):l||"",y=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(y)},m=function(e){if(!e)return"";var t=e.split("?")[1];return t?t.replace(v,""):""},g=function(e){if(!e)return{};var t=m(e);return t?t.split("&").reduce((function(e,t){var r=t.indexOf("="),n=(-1!==r?[t.substring(0,r),t.substring(r+1)]:[t]).map((function(e){return decodeURIComponent(e.replace("+"," "))}));return e[n[0]]=n[1],e}),{}):{}};function O(t){var r=t.match(h),n=e.get(r,"groups",{}),o=n.protocol,i=n.auth,u=n.host,l=n.pathname,c=n.query,f=n.hash,s=null,p=null;if(u){var y=a(u.split(":"),2);s=y[0],p=y[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:s||null,port:p||null,pathname:l||null,search:c?"?".concat(c):null,query:c||null,hash:f||null}}var j=function(t){var r=[];for(var n in t){var o=t[n];e.isUndefinedOrNull(o)?r.push(encodeURIComponent(n)+"="):r.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return r.join("&")},w=["queryObj"],x=function(e,t){var r=t.queryObj,n=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,w),o=i(i({},O(e)),n),u=i(i({},g(o.search||"")),r);return b(i(i({},o),{},{search:"",query:j(u)}))};function P(e){var t,r=e.match(d);if(r)return(null===(t=r.groups)||void 0===t?void 0:t.pathname)||""}var E={parseUrl:O,getPathArr:function(t){var r=P(t);if(!e.isUndefined(r))return r.split("/").filter(Boolean)},getPathStr:P,getQuery:m,getQueryObj:g,toQueryString:j,change:x,addQuery:function(e,t){return x(e,{queryObj:t})},combine:b};exports.HASH_REGEX=v,exports.Interceptor=p,exports.PATHNAME_REGEX=d,exports.QUERY_REGEX=y,exports.URL_REGEX=h,exports.debounce=function(e,t){var r,n,o,i,u,a=null==t?void 0:t.maxWait,c=null!==(r=null==t?void 0:t.wait)&&void 0!==r?r:500,f=null===(n=null==t?void 0:t.leading)||void 0===n||n,s=null===(o=null==t?void 0:t.trailing)||void 0===o||o,p=!1,h=0,y=a&&a>c,v=function(){clearTimeout(i),i=null},d=function(){p=!1,y&&(h=Date.now()),e.apply(void 0,l(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(p&&s)return d(),void b();v()}),c)},m=function(){p=!0;for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];u=t,i||(f?d():y&&(h=Date.now())),y&&Date.now()-h>=a&&(d(),b()),b()};return m.cancel=v,m.flush=function(){i&&p&&(d(),b())},m.fun=e,m},exports.deepClone=function(e){return JSON.parse(JSON.stringify(e))},exports.enumToArray=function(t){return e.isPlainObject(t)?[Object.keys(t)]:[]},exports.listToMap=function(e,t){return e.reduce((function(e,r){var o=r[t];return i(i({},e),{},n({},o,r))}),{})},exports.numInRange=function(e,t){return e<=t[1]&&e>=t[0]},exports.sleep=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(e.isNumber(t))return new Promise((function(e){return setTimeout(e,t)}))},exports.throttle=function(e,t){var r,n,o,i,u,a=null!==(r=null==t?void 0:t.wait)&&void 0!==r?r:500,c=null===(n=null==t?void 0:t.leading)||void 0===n||n,f=null===(o=null==t?void 0:t.trailing)||void 0===o||o,s=!1,p=function(){clearTimeout(i),i=null,s=!1},h=function(){s=!1,e.apply(void 0,l(u))},y=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return h(),void y();p()}),a)},v=function(){s=!0;for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];u=t,i||(c&&h(),y())};return v.cancel=p,v.flush=function(){i&&s&&(h(),y())},v.fun=e,v},exports.uri=E,exports.uuid=function(){for(var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],r=[],n=0;n<e;n++)r[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return r.join("")};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isPlainObject as t,forEach as
|
|
1
|
+
import{isPlainObject as t,forEach as n,isNumber as r,get as e,isUndefinedOrNull as o,isUndefined as i}from"@cclr/lang";var u=function(t){return JSON.parse(JSON.stringify(t))},a=function(n){return t(n)?[Object.keys(n)]:[]};function l(t,n){(null==n||n>t.length)&&(n=t.length);for(var r=0,e=Array(n);r<n;r++)e[r]=t[r];return e}function c(t,n,r){return n&&function(t,n){for(var r=0;r<n.length;r++){var e=n[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,d(e.key),e)}}(t.prototype,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,n,r){return(n=d(n))in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}function s(t,n){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);n&&(e=e.filter((function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable}))),r.push.apply(r,e)}return r}function p(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?s(Object(r),!0).forEach((function(n){f(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):s(Object(r)).forEach((function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(r,n))}))}return t}function h(t,n){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},h(t,n)}function y(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var e,o,i,u,a=[],l=!0,c=!1;try{if(i=(r=r.call(t)).next,0===n);else for(;!(l=(e=i.call(r)).done)&&(a.push(e.value),a.length!==n);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=r.return&&(u=r.return(),Object(u)!==u))return}finally{if(c)throw o}}return a}}(t,n)||b(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function v(t){return function(t){if(Array.isArray(t))return l(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||b(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(t){var n=function(t,n){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var e=r.call(t,n);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}(t,"string");return"symbol"==typeof n?n:n+""}function b(t,n){if(t){if("string"==typeof t)return l(t,n);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(t,n):void 0}}function m(){m=function(t,n){return new r(t,void 0,n)};var t=RegExp.prototype,n=new WeakMap;function r(t,e,o){var i=RegExp(t,e);return n.set(i,o||n.get(t)),h(i,r.prototype)}function e(t,r){var e=n.get(r);return Object.keys(e).reduce((function(n,r){var o=e[r];if("number"==typeof o)n[r]=t[o];else{for(var i=0;void 0===t[o[i]]&&i+1<o.length;)i++;n[r]=t[o[i]]}return n}),Object.create(null))}return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(n&&n.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),n&&h(t,n)}(r,RegExp),r.prototype.exec=function(n){var r=t.exec.call(this,n);if(r){r.groups=e(r,this);var o=r.indices;o&&(o.groups=e(o,this))}return r},r.prototype[Symbol.replace]=function(r,o){if("string"==typeof o){var i=n.get(this);return t[Symbol.replace].call(this,r,o.replace(/\$<([^>]+)>/g,(function(t,n){var r=i[n];return"$"+(Array.isArray(r)?r.join("$"):r)})))}if("function"==typeof o){var u=this;return t[Symbol.replace].call(this,r,(function(){var t=arguments;return"object"!=typeof t[t.length-1]&&(t=[].slice.call(t)).push(e(t,u)),o.apply(this,t)}))}return t[Symbol.replace].call(this,r,o)},m.apply(this,arguments)}var g=function(t,n){return t.reduce((function(t,r){var e=r[n];return p(p({},t),{},f({},e,r))}),{})};function O(t,n){return t<=n[1]&&t>=n[0]}var j=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:36,n=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],r=[],e=0;e<t;e++)r[e]=8===e||13===e||18===e||23===e?"-":n[Math.ceil(Math.random()*n.length-1)];return r.join("")},w=function(){return c((function t(){!function(t,n){if(!(t instanceof n))throw new TypeError("Cannot call a class as a function")}(this,t),f(this,"handler",[])}),[{key:"use",value:function(t,n){return this.handler.push({fulfilled:t,rejected:n}),this.handler.length-1}},{key:"eject",value:function(t){this.handler[t]&&(this.handler[t]=null)}},{key:"clear",value:function(){this.handler=[]}},{key:"forEach",value:function(t){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];n(this.handler,(function(n){n&&t(n)}),r)}},{key:"run",value:function(t){var n=arguments;return new Promise(function(r,e){var o=n.length>1&&void 0!==n[1]&&n[1],i=Promise.resolve(t());return this.forEach((function(t){i=i.then(t.fulfilled,t.rejected)}),o),r(i)}.bind(this))}}])}(),P=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),S=m(/\?([^#]*)/,{query:1}),A=m(/#(.*)/,{hash:1}),E=m(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),x=function(t,n){var r,e,o,i,u,a=null==n?void 0:n.maxWait,l=null!==(r=null==n?void 0:n.wait)&&void 0!==r?r:500,c=null===(e=null==n?void 0:n.leading)||void 0===e||e,f=null===(o=null==n?void 0:n.trailing)||void 0===o||o,s=!1,p=0,h=a&&a>l,y=function(){clearTimeout(i),i=null},d=function(){s=!1,h&&(p=Date.now()),t.apply(void 0,v(u))},b=function(){clearTimeout(i),i=setTimeout((function(){if(s&&f)return d(),void b();y()}),l)},m=function(){s=!0;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];u=n,i||(c?d():h&&(p=Date.now())),h&&Date.now()-p>=a&&(d(),b()),b()};return m.cancel=y,m.flush=function(){i&&s&&(d(),b())},m.fun=t,m},T=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(r(t))return new Promise((function(n){return setTimeout(n,t)}))},k=function(t,n){var r,e,o,i,u,a=null!==(r=null==n?void 0:n.wait)&&void 0!==r?r:500,l=null===(e=null==n?void 0:n.leading)||void 0===e||e,c=null===(o=null==n?void 0:n.trailing)||void 0===o||o,f=!1,s=function(){clearTimeout(i),i=null,f=!1},p=function(){f=!1,t.apply(void 0,v(u))},h=function(){clearTimeout(i),i=setTimeout((function(){if(f&&c)return p(),void h();s()}),a)},y=function(){f=!0;for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];u=n,i||(l&&p(),h())};return y.cancel=s,y.flush=function(){i&&f&&(p(),h())},y.fun=t,y},I=function(t){var n=t.protocol,r=t.auth,e=t.host,o=t.hostname,i=t.port,u=t.pathname,a=t.query,l=t.search,c=t.hash,f=n?"".concat(n,"//"):"",s=r?"".concat(r,"@"):"",p=e||"".concat(o||"").concat(i?":".concat(i):""),h=a?"?".concat(a):l||"",y=c?"#".concat(c):"";return"".concat(f).concat(s).concat(p).concat(u).concat(h).concat(y)},q=function(t){if(!t)return"";var n=t.split("?")[1];return n?n.replace(A,""):""},R=function(t){if(!t)return{};var n=q(t);return n?n.split("&").reduce((function(t,n){var r=n.indexOf("="),e=(-1!==r?[n.substring(0,r),n.substring(r+1)]:[n]).map((function(t){return decodeURIComponent(t.replace("+"," "))}));return t[e[0]]=e[1],t}),{}):{}};function D(t){var n=t.match(P),r=e(n,"groups",{}),o=r.protocol,i=r.auth,u=r.host,a=r.pathname,l=r.query,c=r.hash,f=null,s=null;if(u){var p=y(u.split(":"),2);f=p[0],s=p[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:i?i.slice(0,-1):null,host:u||null,hostname:f||null,port:s||null,pathname:a||null,search:l?"?".concat(l):null,query:l||null,hash:c||null}}var C=function(t){var n=[];for(var r in t){var e=t[r];o(e)?n.push(encodeURIComponent(r)+"="):n.push(encodeURIComponent(r)+"="+encodeURIComponent(e))}return n.join("&")},U=["queryObj"],z=function(t,n){var r=n.queryObj,e=function(t,n){if(null==t)return{};var r,e,o=function(t,n){if(null==t)return{};var r={};for(var e in t)if({}.hasOwnProperty.call(t,e)){if(-1!==n.indexOf(e))continue;r[e]=t[e]}return r}(t,n);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(e=0;e<i.length;e++)r=i[e],-1===n.indexOf(r)&&{}.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}(n,U),o=p(p({},D(t)),e),i=p(p({},R(o.search||"")),r);return I(p(p({},o),{},{search:"",query:C(i)}))};function M(t){var n,r=t.match(E);if(r)return(null===(n=r.groups)||void 0===n?void 0:n.pathname)||""}var Q={parseUrl:D,getPathArr:function(t){var n=M(t);if(!i(n))return n.split("/").filter(Boolean)},getPathStr:M,getQuery:q,getQueryObj:R,toQueryString:C,change:z,addQuery:function(t,n){return z(t,{queryObj:n})},combine:I};export{A as HASH_REGEX,w as Interceptor,E as PATHNAME_REGEX,S as QUERY_REGEX,P as URL_REGEX,x as debounce,u as deepClone,a as enumToArray,g as listToMap,O as numInRange,T as sleep,k as throttle,Q as uri,j as uuid};
|
package/lib/type/index.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ declare const deepClone: <T extends object | TAny[]>(Obj: T) => T;
|
|
|
15
15
|
*/
|
|
16
16
|
declare const enumToArray: (e: TPlainObject) => string[][];
|
|
17
17
|
|
|
18
|
+
declare const listToMap: <T extends TPlainObject, K extends keyof T>(list: T[], key: K) => Record<T[K], T>;
|
|
19
|
+
|
|
18
20
|
declare function numInRange(num: number, range: [number, number]): boolean;
|
|
19
21
|
|
|
20
22
|
/**
|
|
@@ -23,7 +25,7 @@ declare function numInRange(num: number, range: [number, number]): boolean;
|
|
|
23
25
|
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
24
26
|
* @returns `string` : 32 character uuid (see example)
|
|
25
27
|
*/
|
|
26
|
-
declare const uuid: () => string;
|
|
28
|
+
declare const uuid: (length?: 8 | 13 | 18 | 23 | 36) => string;
|
|
27
29
|
|
|
28
30
|
type OnFulfilled<T> = ((value: T) => T | PromiseLike<T>) | undefined | null;
|
|
29
31
|
type OnRejected<T> = ((reason: T) => T | PromiseLike<T>) | undefined | null;
|
|
@@ -80,6 +82,7 @@ declare const debounce: <T extends TPlainFunction>(cb: T, options?: {
|
|
|
80
82
|
}) => T & {
|
|
81
83
|
cancel: () => void;
|
|
82
84
|
flush: () => void;
|
|
85
|
+
fun: T;
|
|
83
86
|
};
|
|
84
87
|
|
|
85
88
|
/**
|
|
@@ -105,6 +108,7 @@ declare const throttle: <T extends TPlainFunction>(cb: T, options?: {
|
|
|
105
108
|
}) => T & {
|
|
106
109
|
cancel: () => void;
|
|
107
110
|
flush: () => void;
|
|
111
|
+
fun: T;
|
|
108
112
|
};
|
|
109
113
|
|
|
110
114
|
interface IUrl {
|
|
@@ -168,4 +172,4 @@ declare const uri: {
|
|
|
168
172
|
combine: (urlParams: IUrl) => string;
|
|
169
173
|
};
|
|
170
174
|
|
|
171
|
-
export { HASH_REGEX, type IUrl, Interceptor, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, debounce, deepClone, enumToArray, numInRange, sleep, throttle, uri, uuid };
|
|
175
|
+
export { HASH_REGEX, type IUrl, Interceptor, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, debounce, deepClone, enumToArray, listToMap, numInRange, sleep, throttle, 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.19",
|
|
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": "8f3b61a1d4597514d1fe34d639be849f717bd2c4",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cclr/lang": "0.1.
|
|
35
|
+
"@cclr/lang": "0.1.19"
|
|
36
36
|
}
|
|
37
37
|
}
|