@cclr/utils 0.1.9 → 0.1.11
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 +51 -10
- package/package.json +3 -3
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var t=require("@cclr/lang");function r(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=Array(r);e<r;e++)n[e]=t[e];return n}function e(t,r,e){return(r=function(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==typeof r?r:r+""}(r))in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function n(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function o(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach((function(r){e(t,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(o,r))}))}return t}function u(t,r){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},u(t,r)}function i(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=e){var n,o,u,i,a=[],l=!0,c=!1;try{if(u=(e=e.call(t)).next,0===r);else for(;!(l=(n=u.call(e)).done)&&(a.push(n.value),a.length!==r);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=e.return&&(i=e.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}(t,r)||l(t,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 a(t){return function(t){if(Array.isArray(t))return r(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||l(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 l(t,e){if(t){if("string"==typeof t)return r(t,e);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(t,e):void 0}}function c(){c=function(t,r){return new e(t,void 0,r)};var t=RegExp.prototype,r=new WeakMap;function e(t,n,o){var i=RegExp(t,n);return r.set(i,o||r.get(t)),u(i,e.prototype)}function n(t,e){var n=r.get(e);return Object.keys(n).reduce((function(r,e){var o=n[e];if("number"==typeof o)r[e]=t[o];else{for(var u=0;void 0===t[o[u]]&&u+1<o.length;)u++;r[e]=t[o[u]]}return r}),Object.create(null))}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&u(t,r)}(e,RegExp),e.prototype.exec=function(r){var e=t.exec.call(this,r);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 u=r.get(this);return t[Symbol.replace].call(this,e,o.replace(/\$<([^>]+)>/g,(function(t,r){var e=u[r];return"$"+(Array.isArray(e)?e.join("$"):e)})))}if("function"==typeof o){var i=this;return t[Symbol.replace].call(this,e,(function(){var t=arguments;return"object"!=typeof t[t.length-1]&&(t=[].slice.call(t)).push(n(t,i)),o.apply(this,t)}))}return t[Symbol.replace].call(this,e,o)},c.apply(this,arguments)}var f=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),p=c(/\?([^#]*)/,{query:1}),s=c(/#(.*)/,{hash:1}),y=c(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),h=function(t){var r=t.protocol,e=t.auth,n=t.host,o=t.hostname,u=t.port,i=t.pathname,a=t.query,l=t.search,c=t.hash,f=r?"".concat(r,"//"):"",p=e?"".concat(e,"@"):"",s=n||"".concat(o||"").concat(u?":".concat(u):""),y=a?"?".concat(a):l||"",h=c?"#".concat(c):"";return"".concat(f).concat(p).concat(s).concat(i).concat(y).concat(h)},v=function(t){if(!t)return"";var r=t.split("?")[1];return r?r.replace(s,""):""},b=function(t){return t?v(t).split("&").reduce((function(t,r){var e=r.indexOf("="),n=(-1!==e?[r.substring(0,e),r.substring(e+1)]:[r]).map((function(t){return decodeURIComponent(t.replace("+"," "))}));return t[n[0]]=n[1],t}),{}):{}};function d(r){var e=r.match(f),n=t.get(e,"groups",{}),o=n.protocol,u=n.auth,a=n.host,l=n.pathname,c=n.query,p=n.hash,s=null,y=null;if(a){var h=i(a.split(":"),2);s=h[0],y=h[1]||null}return{href:r,protocol:o||null,slashes:r.includes("//")||null,auth:u?u.slice(0,-1):null,host:a||null,hostname:s||null,port:y||null,pathname:l||null,search:c?"?".concat(c):null,query:c||null,hash:p||null}}var m=function(r){var e=[];for(var n in r){var o=r[n];t.isUndefinedOrNull(o)?e.push(encodeURIComponent(n)+"="):e.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return e.join("&")},g=["queryObj"],O=function(t,r){var e=r.queryObj,n=function(t,r){if(null==t)return{};var e,n,o=function(t,r){if(null==t)return{};var e={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(r.includes(n))continue;e[n]=t[n]}return e}(t,r);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(n=0;n<u.length;n++)e=u[n],r.includes(e)||{}.propertyIsEnumerable.call(t,e)&&(o[e]=t[e])}return o}(r,g),u=o(o({},d(t)),n),i=o(o({},b(u.search||"")),e);return h(o(o({},u),{},{search:"",query:m(i)}))};function j(t){var r,e=t.match(y);if(e)return(null===(r=e.groups)||void 0===r?void 0:r.pathname)||""}var w={parseUrl:d,getPathArr:function(r){var e=j(r);if(!t.isUndefined(e))return e.split("/").filter(Boolean)},getPathStr:j,getQuery:v,getQueryObj:b,toQueryString:m,change:O,addQuery:function(t,r){return O(t,{queryObj:r})},combine:h};exports.HASH_REGEX=s,exports.PATHNAME_REGEX=y,exports.QUERY_REGEX=p,exports.URL_REGEX=f,exports.debounce=function(t,r){var e,n,o,u,i,l=null==r?void 0:r.maxWait,c=null!==(e=null==r?void 0:r.wait)&&void 0!==e?e:500,f=null===(n=null==r?void 0:r.leading)||void 0===n||n,p=null===(o=null==r?void 0:r.trailing)||void 0===o||o,s=!1,y=0,h=l&&l>c,v=function(){clearTimeout(u),u=null},b=function(){s=!1,h&&(y=Date.now()),t.apply(void 0,a(i))},d=function(){clearTimeout(u),u=setTimeout((function(){if(s&&p)return b(),void d();v()}),c)},m=function(){s=!0;for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];i=r,u||(f?b():h&&(y=Date.now())),h&&Date.now()-y>=l&&(b(),d()),d()};return m.cancel=v,m.flush=function(){u&&s&&(b(),d())},m},exports.deepClone=function(t){return JSON.parse(JSON.stringify(t))},exports.enumToArray=function(r){return t.isPlainObject(r)?[Object.keys(r)]:[]},exports.numInRange=function(t,r){return t<=r[1]&&t>=r[0]},exports.sleep=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(t.isNumber(r))return new Promise((function(t){return setTimeout(t,r)}))},exports.throttle=function(t,r){var e,n,o,u,i,l=null!==(e=null==r?void 0:r.wait)&&void 0!==e?e:500,c=null===(n=null==r?void 0:r.leading)||void 0===n||n,f=null===(o=null==r?void 0:r.trailing)||void 0===o||o,p=!1,s=function(){clearTimeout(u),u=null,p=!1},y=function(){p=!1,t.apply(void 0,a(i))},h=function(){clearTimeout(u),u=setTimeout((function(){if(p&&f)return y(),void h();s()}),l)},v=function(){p=!0;for(var t=arguments.length,r=new Array(t),e=0;e<t;e++)r[e]=arguments[e];i=r,u||(c&&y(),h())};return v.cancel=s,v.flush=function(){u&&p&&(y(),h())},v},exports.uri=w,exports.uuid=function(){for(var t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],r=[],e=0;e<36;e++)r[e]=8===e||13===e||18===e||23===e?"-":t[Math.ceil(Math.random()*t.length-1)];return r.join("")};
|
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isPlainObject as r,get as
|
|
1
|
+
import{isPlainObject as t,isNumber as r,get as n,isUndefinedOrNull as e,isUndefined as o}from"@cclr/lang";var u=function(t){return JSON.parse(JSON.stringify(t))},i=function(r){return t(r)?[Object.keys(r)]:[]};function a(t,r){return t<=r[1]&&t>=r[0]}var l=function(){for(var t=["a","b","c","d","e","f","0","1","2","3","4","5","6","7","8","9"],r=[],n=0;n<36;n++)r[n]=8===n||13===n||18===n||23===n?"-":t[Math.ceil(Math.random()*t.length-1)];return r.join("")};function c(t,r){(null==r||r>t.length)&&(r=t.length);for(var n=0,e=Array(r);n<r;n++)e[n]=t[n];return e}function f(t,r,n){return(r=function(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var e=n.call(t,r||"default");if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==typeof r?r:r+""}(r))in t?Object.defineProperty(t,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[r]=n,t}function p(t,r){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var e=Object.getOwnPropertySymbols(t);r&&(e=e.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),n.push.apply(n,e)}return n}function s(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?p(Object(n),!0).forEach((function(r){f(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))}))}return t}function y(t,r){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t},y(t,r)}function v(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var e,o,u,i,a=[],l=!0,c=!1;try{if(u=(n=n.call(t)).next,0===r);else for(;!(l=(e=u.call(n)).done)&&(a.push(e.value),a.length!==r);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}(t,r)||b(t,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(t){return function(t){if(Array.isArray(t))return c(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 b(t,r){if(t){if("string"==typeof t)return c(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?c(t,r):void 0}}function m(){m=function(t,r){return new n(t,void 0,r)};var t=RegExp.prototype,r=new WeakMap;function n(t,e,o){var u=RegExp(t,e);return r.set(u,o||r.get(t)),y(u,n.prototype)}function e(t,n){var e=r.get(n);return Object.keys(e).reduce((function(r,n){var o=e[n];if("number"==typeof o)r[n]=t[o];else{for(var u=0;void 0===t[o[u]]&&u+1<o.length;)u++;r[n]=t[o[u]]}return r}),Object.create(null))}return function(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),r&&y(t,r)}(n,RegExp),n.prototype.exec=function(r){var n=t.exec.call(this,r);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 u=r.get(this);return t[Symbol.replace].call(this,n,o.replace(/\$<([^>]+)>/g,(function(t,r){var n=u[r];return"$"+(Array.isArray(n)?n.join("$"):n)})))}if("function"==typeof o){var i=this;return t[Symbol.replace].call(this,n,(function(){var t=arguments;return"object"!=typeof t[t.length-1]&&(t=[].slice.call(t)).push(e(t,i)),o.apply(this,t)}))}return t[Symbol.replace].call(this,n,o)},m.apply(this,arguments)}var d=new RegExp(["^(?<protocol>[a-zA-Z][a-zA-Zd+-.]*:)?","(?:\\/\\/(?<auth>[^@/?#]*@)?(?<host>[^/?#]*))?","(?<pathname>[^?#]*)","(?:\\?(?<query>[^#]*))?","(?:#(?<hash>.*))?"].join("")),g=m(/\?([^#]*)/,{query:1}),O=m(/#(.*)/,{hash:1}),j=m(/^(?:[a-zA-Z][a-zA-Zd+-.]*:)?(?:\/\/(?:[^@/?#]*@)?[^/?#]*)?([^?#]*)/,{pathname:1}),w=function(t,r){var n,e,o,u,i,a=null==r?void 0:r.maxWait,l=null!==(n=null==r?void 0:r.wait)&&void 0!==n?n:500,c=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,p=!1,s=0,y=a&&a>l,v=function(){clearTimeout(u),u=null},b=function(){p=!1,y&&(s=Date.now()),t.apply(void 0,h(i))},m=function(){clearTimeout(u),u=setTimeout((function(){if(p&&f)return b(),void m();v()}),l)},d=function(){p=!0;for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];i=r,u||(c?b():y&&(s=Date.now())),y&&Date.now()-s>=a&&(b(),m()),m()};return d.cancel=v,d.flush=function(){u&&p&&(b(),m())},d},S=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(r(t))return new Promise((function(r){return setTimeout(r,t)}))},P=function(t,r){var n,e,o,u,i,a=null!==(n=null==r?void 0:r.wait)&&void 0!==n?n:500,l=null===(e=null==r?void 0:r.leading)||void 0===e||e,c=null===(o=null==r?void 0:r.trailing)||void 0===o||o,f=!1,p=function(){clearTimeout(u),u=null,f=!1},s=function(){f=!1,t.apply(void 0,h(i))},y=function(){clearTimeout(u),u=setTimeout((function(){if(f&&c)return s(),void y();p()}),a)},v=function(){f=!0;for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];i=r,u||(l&&s(),y())};return v.cancel=p,v.flush=function(){u&&f&&(s(),y())},v},A=function(t){var r=t.protocol,n=t.auth,e=t.host,o=t.hostname,u=t.port,i=t.pathname,a=t.query,l=t.search,c=t.hash,f=r?"".concat(r,"//"):"",p=n?"".concat(n,"@"):"",s=e||"".concat(o||"").concat(u?":".concat(u):""),y=a?"?".concat(a):l||"",v=c?"#".concat(c):"";return"".concat(f).concat(p).concat(s).concat(i).concat(y).concat(v)},x=function(t){if(!t)return"";var r=t.split("?")[1];return r?r.replace(O,""):""},E=function(t){return t?x(t).split("&").reduce((function(t,r){var n=r.indexOf("="),e=(-1!==n?[r.substring(0,n),r.substring(n+1)]:[r]).map((function(t){return decodeURIComponent(t.replace("+"," "))}));return t[e[0]]=e[1],t}),{}):{}};function T(t){var r=t.match(d),e=n(r,"groups",{}),o=e.protocol,u=e.auth,i=e.host,a=e.pathname,l=e.query,c=e.hash,f=null,p=null;if(i){var s=v(i.split(":"),2);f=s[0],p=s[1]||null}return{href:t,protocol:o||null,slashes:t.includes("//")||null,auth:u?u.slice(0,-1):null,host:i||null,hostname:f||null,port:p||null,pathname:a||null,search:l?"?".concat(l):null,query:l||null,hash:c||null}}var I=function(t){var r=[];for(var n in t){var o=t[n];e(o)?r.push(encodeURIComponent(n)+"="):r.push(encodeURIComponent(n)+"="+encodeURIComponent(o))}return r.join("&")},q=["queryObj"],R=function(t,r){var n=r.queryObj,e=function(t,r){if(null==t)return{};var n,e,o=function(t,r){if(null==t)return{};var n={};for(var e in t)if({}.hasOwnProperty.call(t,e)){if(r.includes(e))continue;n[e]=t[e]}return n}(t,r);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(e=0;e<u.length;e++)n=u[e],r.includes(n)||{}.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}(r,q),o=s(s({},T(t)),e),u=s(s({},E(o.search||"")),n);return A(s(s({},o),{},{search:"",query:I(u)}))};function D(t){var r,n=t.match(j);if(n)return(null===(r=n.groups)||void 0===r?void 0:r.pathname)||""}var U={parseUrl:T,getPathArr:function(t){var r=D(t);if(!o(r))return r.split("/").filter(Boolean)},getPathStr:D,getQuery:x,getQueryObj:E,toQueryString:I,change:R,addQuery:function(t,r){return R(t,{queryObj:r})},combine:A};export{O as HASH_REGEX,j as PATHNAME_REGEX,g as QUERY_REGEX,d as URL_REGEX,w as debounce,u as deepClone,i as enumToArray,a as numInRange,S as sleep,P as throttle,U as uri,l 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 } from '@cclr/lang';
|
|
2
|
+
import { TAny, TPlainObject, TPlainFunction } from '@cclr/lang';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 深拷贝 JSON 方式
|
|
@@ -15,11 +15,60 @@ declare const deepClone: <T extends object | TAny[]>(Obj: T) => T;
|
|
|
15
15
|
*/
|
|
16
16
|
declare const enumToArray: (e: TPlainObject) => string[][];
|
|
17
17
|
|
|
18
|
+
declare function numInRange(num: number, range: [number, number]): boolean;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A function that returns a universally unique identifier (uuid).
|
|
22
|
+
* @example
|
|
23
|
+
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
24
|
+
* @returns `string` : 32 character uuid (see example)
|
|
25
|
+
*/
|
|
26
|
+
declare const uuid: () => string;
|
|
27
|
+
|
|
18
28
|
declare const URL_REGEX: RegExp;
|
|
19
29
|
declare const QUERY_REGEX: RegExp;
|
|
20
30
|
declare const HASH_REGEX: RegExp;
|
|
21
31
|
declare const PATHNAME_REGEX: RegExp;
|
|
22
32
|
|
|
33
|
+
declare const debounce: <T extends TPlainFunction>(cb: T, options?: {
|
|
34
|
+
/** 等待时间,单位为毫秒 default: 500 */
|
|
35
|
+
wait?: number;
|
|
36
|
+
/** 是否在延迟开始前调用函数 default: true */
|
|
37
|
+
leading?: boolean;
|
|
38
|
+
/** 是否在延迟开始后调用函数 default: true */
|
|
39
|
+
trailing?: boolean;
|
|
40
|
+
/** 最大等待时间,单位为毫秒,如果大于wait时间,则没有意义 */
|
|
41
|
+
maxWait?: number;
|
|
42
|
+
}) => T & {
|
|
43
|
+
cancel: () => void;
|
|
44
|
+
flush: () => void;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* sleep
|
|
49
|
+
* @param time - default 0
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
declare const sleep: (time?: number) => Promise<void> | undefined;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 节流函数
|
|
56
|
+
* @param cb
|
|
57
|
+
* @param options
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
declare const throttle: <T extends TPlainFunction>(cb: T, options?: {
|
|
61
|
+
/** 等待时间,单位为毫秒 default: 500 */
|
|
62
|
+
wait?: number;
|
|
63
|
+
/** 是否在延迟开始前调用函数 default: true */
|
|
64
|
+
leading?: boolean;
|
|
65
|
+
/** 是否在延迟开始后调用函数 default: true */
|
|
66
|
+
trailing?: boolean;
|
|
67
|
+
}) => T & {
|
|
68
|
+
cancel: () => void;
|
|
69
|
+
flush: () => void;
|
|
70
|
+
};
|
|
71
|
+
|
|
23
72
|
interface IUrl {
|
|
24
73
|
/** 完整的 URL 字符串,例如 https://example.com:8080/path?query#fragment */
|
|
25
74
|
href?: string | null | undefined;
|
|
@@ -81,12 +130,4 @@ declare const uri: {
|
|
|
81
130
|
combine: (urlParams: IUrl) => string;
|
|
82
131
|
};
|
|
83
132
|
|
|
84
|
-
|
|
85
|
-
* A function that returns a universally unique identifier (uuid).
|
|
86
|
-
* @example
|
|
87
|
-
* 1b83fd69-abe7-468c-bea1-306a8aa1c81d
|
|
88
|
-
* @returns `string` : 32 character uuid (see example)
|
|
89
|
-
*/
|
|
90
|
-
declare const uuid: () => string;
|
|
91
|
-
|
|
92
|
-
export { HASH_REGEX, type IUrl, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, deepClone, enumToArray, uri, uuid };
|
|
133
|
+
export { HASH_REGEX, type IUrl, PATHNAME_REGEX, QUERY_REGEX, URL_REGEX, debounce, deepClone, enumToArray, 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.11",
|
|
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": "e03c9c40bc86083ba49fe9f372375a50223191cc",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@cclr/lang": "
|
|
35
|
+
"@cclr/lang": "0.1.11"
|
|
36
36
|
}
|
|
37
37
|
}
|