wjk-util 0.1.0 → 0.1.1

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.
@@ -1 +1 @@
1
- function e(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function t(e){return Array.isArray(e)}function n(t){return"object"===e(t)}function r(e){return"function"==typeof e}function o(e){return"string"==typeof e}function c(e){return"number"==typeof e&&!isNaN(e)}function i(e){return"boolean"==typeof e}function u(e){return null===e}function a(e){return void 0===e}function s(e){return!(!u(e)&&!a(e))||(o(e)||t(e)?0===e.length:!!n(e)&&0===Object.keys(e).length)}function l(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return[...new Set(e)]}function f(e,t=1){if(!Array.isArray(e))throw new Error("参数必须是数组");return t<=0?e.slice():e.reduce((e,n)=>e.concat(Array.isArray(n)?f(n,t-1):[n]),[])}function y(e,t=1){if(!Array.isArray(e))throw new Error("参数必须是数组");if(t<=0)return[];const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function h(e){if(Array.isArray(e)&&0!==e.length)return Math.max(...e)}function p(e){if(Array.isArray(e)&&0!==e.length)return Math.min(...e)}function g(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return e.reduce((e,t)=>e+t,0)}function d(e){if(Array.isArray(e)&&0!==e.length)return g(e)/e.length}function m(e,t=/* @__PURE__ */new WeakMap){if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof HTMLElement)return e.cloneNode(!0);if(t.has(e))return t.get(e);if(Array.isArray(e)){const n=[];return t.set(e,n),e.forEach((e,r)=>{n[r]=m(e,t)}),n}const n={};return t.set(e,n),Object.keys(e).forEach(r=>{n[r]=m(e[r],t)}),n}function v(...e){const t={};return e.forEach(e=>{e&&"object"==typeof e&&Object.keys(e).forEach(n=>{const r=n;void 0!==e[r]&&(t[r]=e[r])})}),t}function E(e){return"object"!=typeof e||null===e?[]:Object.keys(e)}function b(e){return"object"!=typeof e||null===e?[]:Object.values(e)}function w(e,t){return"object"==typeof e&&null!==e&&e.hasOwnProperty(t)}function A(e,t){return Math.floor(Math.random()*(t-e+1))+e}function j(e){return e*(Math.PI/180)}function x(e){return e*(180/Math.PI)}function L(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)}function S(e,t){return Number(Math.round(parseFloat(e+"e"+t))+"e-"+t)}function M(e,t,n=!1){try{(n?sessionStorage:localStorage).setItem(e,JSON.stringify(t))}catch(r){console.error("存储失败:",r)}}function O(e,t=!1){try{const n=(t?sessionStorage:localStorage).getItem(e);return n?JSON.parse(n):null}catch(n){return console.error("获取存储失败:",n),null}}function k(e,t=!1){try{(t?sessionStorage:localStorage).removeItem(e)}catch(n){console.error("删除存储失败:",n)}}function N(e=!1){try{(e?sessionStorage:localStorage).clear()}catch(t){console.error("清空存储失败:",t)}}function P(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept=".xls,.xlsx,.xlsm",t.click(),t.addEventListener("change",function n(r){const o=r.target,c=o.files?.[0];if(c){const n=c.name.split("."),r=n[n.length-1];t.accept.includes(r)?e(c):(console.error("Excel文件上传格式错误"),e(void 0))}else e(void 0);t.removeEventListener("change",n)})})}function R(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept=".jpg,.png,.jpeg,.gif",t.click(),t.addEventListener("change",function n(r){const o=r.target,c=o.files?.[0];if(c){const n=c.name.split("."),r=n[n.length-1];t.accept.includes(r)?e(c):(console.error("图片上传格式错误"),e(void 0))}else e(void 0);t.removeEventListener("change",n)})})}function I(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept=".gltf,.glb",t.click(),t.addEventListener("change",function n(r){const o=r.target,c=o.files?.[0];if(c){const n=c.name.split("."),r=n[n.length-1];t.accept.includes(r)?e(c):(console.error("模型上传格式错误"),e(void 0))}else e(void 0);t.removeEventListener("change",n)})})}function U(e,t,n="application/vnd.ms-excel;charset=utf-8"){const r=document.createElement("a");r.download=t,r.style.display="none";const o=new Blob([e],{type:n});r.href=URL.createObjectURL(o),document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(r.href)}function C(e,t,n){return e*Math.pow(1+t,n)}export{d as average,y as chunk,N as clearStorage,C as compoundInterest,m as deepClone,j as degreesToRadians,L as distance,U as downloadFile,f as flatten,O as getStorage,e as getType,w as hasKey,t as isArray,i as isBoolean,s as isEmpty,r as isFunction,u as isNull,c as isNumber,n as isObject,o as isString,a as isUndefined,E as keys,h as max,v as merge,p as min,x as radiansToDegrees,A as randomInt,k as removeStorage,S as round,M as setStorage,g as sum,l as unique,P as uploadExcelFile,R as uploadImageFile,I as uploadModelFile,b as values};
1
+ function e(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function n(e){return Array.isArray(e)}function t(n){return"object"===e(n)}function r(e){return"function"==typeof e}function o(e){return"string"==typeof e}function c(e){return"number"==typeof e&&!isNaN(e)}function i(e){return"boolean"==typeof e}function u(e){return null===e}function a(e){return void 0===e}function s(e){return!(!u(e)&&!a(e))||(o(e)||n(e)?0===e.length:!!t(e)&&0===Object.keys(e).length)}function l(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return[...new Set(e)]}function f(e,n=1){if(!Array.isArray(e))throw new Error("参数必须是数组");return n<=0?e.slice():e.reduce((e,t)=>e.concat(Array.isArray(t)?f(t,n-1):[t]),[])}function y(e,n=1){if(!Array.isArray(e))throw new Error("参数必须是数组");if(n<=0)return[];const t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t}function h(e){if(Array.isArray(e)&&0!==e.length)return Math.max(...e)}function p(e){if(Array.isArray(e)&&0!==e.length)return Math.min(...e)}function d(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return e.reduce((e,n)=>e+n,0)}function g(e){if(Array.isArray(e)&&0!==e.length)return d(e)/e.length}function m(e,n=/* @__PURE__ */new WeakMap){if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof HTMLElement)return e.cloneNode(!0);if(n.has(e))return n.get(e);if(Array.isArray(e)){const t=[];return n.set(e,t),e.forEach((e,r)=>{t[r]=m(e,n)}),t}const t={};return n.set(e,t),Object.keys(e).forEach(r=>{t[r]=m(e[r],n)}),t}function w(...e){const n={};return e.forEach(e=>{e&&"object"==typeof e&&Object.keys(e).forEach(t=>{const r=t;void 0!==e[r]&&(n[r]=e[r])})}),n}function v(e){return"object"!=typeof e||null===e?[]:Object.keys(e)}function E(e){return"object"!=typeof e||null===e?[]:Object.values(e)}function b(e,n){return"object"==typeof e&&null!==e&&e.hasOwnProperty(n)}function A(e,n){return Math.floor(Math.random()*(n-e+1))+e}function j(e){return e*(Math.PI/180)}function x(e){return e*(180/Math.PI)}function L(e,n){const t=n.x-e.x,r=n.y-e.y;return Math.sqrt(t*t+r*r)}function S(e,n){return Number(Math.round(parseFloat(e+"e"+n))+"e-"+n)}function M(e,n,t=!1){try{(t?sessionStorage:localStorage).setItem(e,JSON.stringify(n))}catch(r){console.error("存储失败:",r)}}function O(e,n=!1){try{const t=(n?sessionStorage:localStorage).getItem(e);return t?JSON.parse(t):null}catch(t){return console.error("获取存储失败:",t),null}}function k(e,n=!1){try{(n?sessionStorage:localStorage).removeItem(e)}catch(t){console.error("删除存储失败:",t)}}function N(e=!1){try{(e?sessionStorage:localStorage).clear()}catch(n){console.error("清空存储失败:",n)}}function P(){return new Promise(e=>{const n=document.createElement("input");n.type="file",n.accept=".xls,.xlsx,.xlsm",n.click(),n.addEventListener("change",function t(r){const o=r.target,c=o.files?.[0];if(c){const t=c.name.split("."),r=t[t.length-1];n.accept.includes(r)?e(c):(console.error("Excel文件上传格式错误"),e(void 0))}else e(void 0);n.removeEventListener("change",t)})})}function R(){return new Promise(e=>{const n=document.createElement("input");n.type="file",n.accept=".jpg,.png,.jpeg,.gif",n.click(),n.addEventListener("change",function t(r){const o=r.target,c=o.files?.[0];if(c){const t=c.name.split("."),r=t[t.length-1];n.accept.includes(r)?e(c):(console.error("图片上传格式错误"),e(void 0))}else e(void 0);n.removeEventListener("change",t)})})}function U(){return new Promise(e=>{const n=document.createElement("input");n.type="file",n.accept=".gltf,.glb",n.click(),n.addEventListener("change",function t(r){const o=r.target,c=o.files?.[0];if(c){const t=c.name.split("."),r=t[t.length-1];n.accept.includes(r)?e(c):(console.error("模型上传格式错误"),e(void 0))}else e(void 0);n.removeEventListener("change",t)})})}function I(e,n,t="application/vnd.ms-excel;charset=utf-8"){const r=document.createElement("a");r.download=n,r.style.display="none";const o=new Blob([e],{type:t});r.href=URL.createObjectURL(o),document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(r.href)}function J(e,n,t){return e*Math.pow(1+n,t)}const C="0.1.0";"undefined"!=typeof window&&window.WJKUtil&&(window.WJKUtil.version="0.1.0");export{g as average,y as chunk,N as clearStorage,J as compoundInterest,m as deepClone,j as degreesToRadians,L as distance,I as downloadFile,f as flatten,O as getStorage,e as getType,b as hasKey,n as isArray,i as isBoolean,s as isEmpty,r as isFunction,u as isNull,c as isNumber,t as isObject,o as isString,a as isUndefined,v as keys,h as max,w as merge,p as min,x as radiansToDegrees,A as randomInt,k as removeStorage,S as round,M as setStorage,d as sum,l as unique,P as uploadExcelFile,R as uploadImageFile,U as uploadModelFile,E as values,C as version};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).WJKUtil={})}(this,function(e){"use strict";function t(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function n(e){return Array.isArray(e)}function r(e){return"object"===t(e)}function o(e){return"string"==typeof e}function c(e){return null===e}function i(e){return void 0===e}function a(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return e.reduce((e,t)=>e+t,0)}e.average=function(e){if(Array.isArray(e)&&0!==e.length)return a(e)/e.length},e.chunk=function(e,t=1){if(!Array.isArray(e))throw new Error("参数必须是数组");if(t<=0)return[];const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},e.clearStorage=function(e=!1){try{(e?sessionStorage:localStorage).clear()}catch(t){console.error("清空存储失败:",t)}},e.compoundInterest=function(e,t,n){return e*Math.pow(1+t,n)},e.deepClone=function e(t,n=new WeakMap){if(null===t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return new RegExp(t.source,t.flags);if(t instanceof HTMLElement)return t.cloneNode(!0);if(n.has(t))return n.get(t);if(Array.isArray(t)){const r=[];return n.set(t,r),t.forEach((t,o)=>{r[o]=e(t,n)}),r}const r={};return n.set(t,r),Object.keys(t).forEach(o=>{r[o]=e(t[o],n)}),r},e.degreesToRadians=function(e){return e*(Math.PI/180)},e.distance=function(e,t){const n=t.x-e.x,r=t.y-e.y;return Math.sqrt(n*n+r*r)},e.downloadFile=function(e,t,n="application/vnd.ms-excel;charset=utf-8"){const r=document.createElement("a");r.download=t,r.style.display="none";const o=new Blob([e],{type:n});r.href=URL.createObjectURL(o),document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(r.href)},e.flatten=function e(t,n=1){if(!Array.isArray(t))throw new Error("参数必须是数组");return n<=0?t.slice():t.reduce((t,r)=>t.concat(Array.isArray(r)?e(r,n-1):[r]),[])},e.getStorage=function(e,t=!1){try{const n=(t?sessionStorage:localStorage).getItem(e);return n?JSON.parse(n):null}catch(n){return console.error("获取存储失败:",n),null}},e.getType=t,e.hasKey=function(e,t){return"object"==typeof e&&null!==e&&e.hasOwnProperty(t)},e.isArray=n,e.isBoolean=function(e){return"boolean"==typeof e},e.isEmpty=function(e){return!(!c(e)&&!i(e))||(o(e)||n(e)?0===e.length:!!r(e)&&0===Object.keys(e).length)},e.isFunction=function(e){return"function"==typeof e},e.isNull=c,e.isNumber=function(e){return"number"==typeof e&&!isNaN(e)},e.isObject=r,e.isString=o,e.isUndefined=i,e.keys=function(e){return"object"!=typeof e||null===e?[]:Object.keys(e)},e.max=function(e){if(Array.isArray(e)&&0!==e.length)return Math.max(...e)},e.merge=function(...e){const t={};return e.forEach(e=>{e&&"object"==typeof e&&Object.keys(e).forEach(n=>{const r=n;void 0!==e[r]&&(t[r]=e[r])})}),t},e.min=function(e){if(Array.isArray(e)&&0!==e.length)return Math.min(...e)},e.radiansToDegrees=function(e){return e*(180/Math.PI)},e.randomInt=function(e,t){return Math.floor(Math.random()*(t-e+1))+e},e.removeStorage=function(e,t=!1){try{(t?sessionStorage:localStorage).removeItem(e)}catch(n){console.error("删除存储失败:",n)}},e.round=function(e,t){return Number(Math.round(parseFloat(e+"e"+t))+"e-"+t)},e.setStorage=function(e,t,n=!1){try{(n?sessionStorage:localStorage).setItem(e,JSON.stringify(t))}catch(r){console.error("存储失败:",r)}},e.sum=a,e.unique=function(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return[...new Set(e)]},e.uploadExcelFile=function(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept=".xls,.xlsx,.xlsm",t.click(),t.addEventListener("change",function n(r){const o=r.target,c=o.files?.[0];if(c){const n=c.name.split("."),r=n[n.length-1];t.accept.includes(r)?e(c):(console.error("Excel文件上传格式错误"),e(void 0))}else e(void 0);t.removeEventListener("change",n)})})},e.uploadImageFile=function(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept=".jpg,.png,.jpeg,.gif",t.click(),t.addEventListener("change",function n(r){const o=r.target,c=o.files?.[0];if(c){const n=c.name.split("."),r=n[n.length-1];t.accept.includes(r)?e(c):(console.error("图片上传格式错误"),e(void 0))}else e(void 0);t.removeEventListener("change",n)})})},e.uploadModelFile=function(){return new Promise(e=>{const t=document.createElement("input");t.type="file",t.accept=".gltf,.glb",t.click(),t.addEventListener("change",function n(r){const o=r.target,c=o.files?.[0];if(c){const n=c.name.split("."),r=n[n.length-1];t.accept.includes(r)?e(c):(console.error("模型上传格式错误"),e(void 0))}else e(void 0);t.removeEventListener("change",n)})})},e.values=function(e){return"object"!=typeof e||null===e?[]:Object.values(e)},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).WJKUtil=e.WJKUtil||{})}(this,function(e){"use strict";function n(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function t(e){return Array.isArray(e)}function r(e){return"object"===n(e)}function o(e){return"string"==typeof e}function i(e){return null===e}function c(e){return void 0===e}function a(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return e.reduce((e,n)=>e+n,0)}const s="0.1.0";e.average=function(e){if(Array.isArray(e)&&0!==e.length)return a(e)/e.length},e.chunk=function(e,n=1){if(!Array.isArray(e))throw new Error("参数必须是数组");if(n<=0)return[];const t=[];for(let r=0;r<e.length;r+=n)t.push(e.slice(r,r+n));return t},e.clearStorage=function(e=!1){try{(e?sessionStorage:localStorage).clear()}catch(n){console.error("清空存储失败:",n)}},e.compoundInterest=function(e,n,t){return e*Math.pow(1+n,t)},e.deepClone=function e(n,t=new WeakMap){if(null===n||"object"!=typeof n)return n;if(n instanceof Date)return new Date(n.getTime());if(n instanceof RegExp)return new RegExp(n.source,n.flags);if(n instanceof HTMLElement)return n.cloneNode(!0);if(t.has(n))return t.get(n);if(Array.isArray(n)){const r=[];return t.set(n,r),n.forEach((n,o)=>{r[o]=e(n,t)}),r}const r={};return t.set(n,r),Object.keys(n).forEach(o=>{r[o]=e(n[o],t)}),r},e.degreesToRadians=function(e){return e*(Math.PI/180)},e.distance=function(e,n){const t=n.x-e.x,r=n.y-e.y;return Math.sqrt(t*t+r*r)},e.downloadFile=function(e,n,t="application/vnd.ms-excel;charset=utf-8"){const r=document.createElement("a");r.download=n,r.style.display="none";const o=new Blob([e],{type:t});r.href=URL.createObjectURL(o),document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(r.href)},e.flatten=function e(n,t=1){if(!Array.isArray(n))throw new Error("参数必须是数组");return t<=0?n.slice():n.reduce((n,r)=>n.concat(Array.isArray(r)?e(r,t-1):[r]),[])},e.getStorage=function(e,n=!1){try{const t=(n?sessionStorage:localStorage).getItem(e);return t?JSON.parse(t):null}catch(t){return console.error("获取存储失败:",t),null}},e.getType=n,e.hasKey=function(e,n){return"object"==typeof e&&null!==e&&e.hasOwnProperty(n)},e.isArray=t,e.isBoolean=function(e){return"boolean"==typeof e},e.isEmpty=function(e){return!(!i(e)&&!c(e))||(o(e)||t(e)?0===e.length:!!r(e)&&0===Object.keys(e).length)},e.isFunction=function(e){return"function"==typeof e},e.isNull=i,e.isNumber=function(e){return"number"==typeof e&&!isNaN(e)},e.isObject=r,e.isString=o,e.isUndefined=c,e.keys=function(e){return"object"!=typeof e||null===e?[]:Object.keys(e)},e.max=function(e){if(Array.isArray(e)&&0!==e.length)return Math.max(...e)},e.merge=function(...e){const n={};return e.forEach(e=>{e&&"object"==typeof e&&Object.keys(e).forEach(t=>{const r=t;void 0!==e[r]&&(n[r]=e[r])})}),n},e.min=function(e){if(Array.isArray(e)&&0!==e.length)return Math.min(...e)},e.radiansToDegrees=function(e){return e*(180/Math.PI)},e.randomInt=function(e,n){return Math.floor(Math.random()*(n-e+1))+e},e.removeStorage=function(e,n=!1){try{(n?sessionStorage:localStorage).removeItem(e)}catch(t){console.error("删除存储失败:",t)}},e.round=function(e,n){return Number(Math.round(parseFloat(e+"e"+n))+"e-"+n)},e.setStorage=function(e,n,t=!1){try{(t?sessionStorage:localStorage).setItem(e,JSON.stringify(n))}catch(r){console.error("存储失败:",r)}},e.sum=a,e.unique=function(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return[...new Set(e)]},e.uploadExcelFile=function(){return new Promise(e=>{const n=document.createElement("input");n.type="file",n.accept=".xls,.xlsx,.xlsm",n.click(),n.addEventListener("change",function t(r){const o=r.target,i=o.files?.[0];if(i){const t=i.name.split("."),r=t[t.length-1];n.accept.includes(r)?e(i):(console.error("Excel文件上传格式错误"),e(void 0))}else e(void 0);n.removeEventListener("change",t)})})},e.uploadImageFile=function(){return new Promise(e=>{const n=document.createElement("input");n.type="file",n.accept=".jpg,.png,.jpeg,.gif",n.click(),n.addEventListener("change",function t(r){const o=r.target,i=o.files?.[0];if(i){const t=i.name.split("."),r=t[t.length-1];n.accept.includes(r)?e(i):(console.error("图片上传格式错误"),e(void 0))}else e(void 0);n.removeEventListener("change",t)})})},e.uploadModelFile=function(){return new Promise(e=>{const n=document.createElement("input");n.type="file",n.accept=".gltf,.glb",n.click(),n.addEventListener("change",function t(r){const o=r.target,i=o.files?.[0];if(i){const t=i.name.split("."),r=t[t.length-1];n.accept.includes(r)?e(i):(console.error("模型上传格式错误"),e(void 0))}else e(void 0);n.removeEventListener("change",t)})})},e.values=function(e){return"object"!=typeof e||null===e?[]:Object.values(e)},e.version=s,Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})}),"undefined"!=typeof window&&window.WJKUtil&&(window.WJKUtil.version="0.1.0");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wjk-util",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "description": "一个包含常见 JavaScript 函数的实用库",
6
6
  "author": "wjk",
@@ -0,0 +1,8 @@
1
+ export declare const version: string;
2
+ export * from './module/type';
3
+ export * from './module/array';
4
+ export * from './module/object';
5
+ export * from './module/math';
6
+ export * from './module/storage';
7
+ export * from './module/file';
8
+ export * from './module/finance';
@@ -0,0 +1,65 @@
1
+ /**
2
+ * 数组去重
3
+ * @param {array} array 待去重数组
4
+ * @returns {array} 去重后的数组
5
+ * @example
6
+ * unique([1, 2, 2, 3, 4, 4, 5]) // [1, 2, 3, 4, 5]
7
+ * @group Array
8
+ */
9
+ export declare function unique<T>(array: T[]): T[];
10
+ /**
11
+ * 数组扁平化
12
+ * @param {array} array 待扁平化数组
13
+ * @param {number} depth 扁平化深度,默认为1
14
+ * @returns {array} 扁平化后的数组
15
+ * @example
16
+ * flatten([1, [2, [3, [4, [5]]]]]) // [1, 2, [3, [4, [5]]]]
17
+ * @group Array
18
+ */
19
+ export declare function flatten<T>(array: (T | T[])[], depth?: number): T[];
20
+ /**
21
+ * 数组分块
22
+ * @param {array} array 待分块数组
23
+ * @param {number} size 每块大小
24
+ * @returns {array} 分块后的二维数组
25
+ * @example
26
+ * chunk([1, 2, 3, 4, 5, 6, 7, 8], 3) // [[1, 2, 3], [4, 5, 6], [7, 8]]
27
+ * @group Array
28
+ */
29
+ export declare function chunk<T>(array: T[], size?: number): T[][];
30
+ /**
31
+ * 获取数组中的最大值
32
+ * @param {array} array 数字数组
33
+ * @returns {number} 最大值
34
+ * @example
35
+ * max([1, 2, 3, 4, 5]) // 5
36
+ * @group Array
37
+ */
38
+ export declare function max(array: number[]): number | undefined;
39
+ /**
40
+ * 获取数组中的最小值
41
+ * @param {array} array 数字数组
42
+ * @returns {number} 最小值
43
+ * @example
44
+ * min([1, 2, 3, 4, 5]) // 1
45
+ * @group Array
46
+ */
47
+ export declare function min(array: number[]): number | undefined;
48
+ /**
49
+ * 数组求和
50
+ * @param {array} array 数字数组
51
+ * @returns {number} 求和结果
52
+ * @example
53
+ * sum([1, 2, 3, 4, 5]) // 15
54
+ * @group Array
55
+ */
56
+ export declare function sum(array: number[]): number;
57
+ /**
58
+ * 数组平均值
59
+ * @param {array} array 数字数组
60
+ * @returns {number} 平均值
61
+ * @example
62
+ * average([1, 2, 3, 4, 5]) // 3
63
+ * @group Array
64
+ */
65
+ export declare function average(array: number[]): number | undefined;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 上传Excel文件
3
+ * @returns {Promise<File | undefined>} 上传的Excel文件对象
4
+ * @example
5
+ * uploadExcelFile().then(file => {
6
+ * if (file) {
7
+ * console.log('上传成功', file);
8
+ * } else {
9
+ * console.log('上传失败');
10
+ * }
11
+ * });
12
+ * @group File
13
+ */
14
+ export declare function uploadExcelFile(): Promise<File | undefined>;
15
+ /**
16
+ * 上传图片文件
17
+ * @returns {Promise<File | undefined>} 上传的图片文件对象
18
+ * @example
19
+ * uploadImageFile().then(file => {
20
+ * if (file) {
21
+ * console.log('上传成功', file);
22
+ * } else {
23
+ * console.log('上传失败');
24
+ * }
25
+ * });
26
+ * @group File
27
+ */
28
+ export declare function uploadImageFile(): Promise<File | undefined>;
29
+ /**
30
+ * 上传模型文件
31
+ * @returns {Promise<File | undefined>} 上传的模型文件对象
32
+ * @example
33
+ * uploadModelFile().then(file => {
34
+ * if (file) {
35
+ * console.log('上传成功', file);
36
+ * } else {
37
+ * console.log('上传失败');
38
+ * }
39
+ * });
40
+ * @group File
41
+ */
42
+ export declare function uploadModelFile(): Promise<File | undefined>;
43
+ /**
44
+ * 下载文件
45
+ * @param {string | Blob | ArrayBuffer} data 文件数据
46
+ * @param {string} name 文件名
47
+ * @param {string} mimeType 文件MIME类型,默认为Excel文件类型
48
+ * @example
49
+ * downloadFile('文件内容', 'example.xlsx');
50
+ * @group File
51
+ */
52
+ export declare function downloadFile(data: string | Blob | ArrayBuffer, name: string, mimeType?: string): void;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 复利计算
3
+ * 复利公式:A = P * (1 + r)^n
4
+ * @param {number} principal 本金
5
+ * @param {number} rate 年利率
6
+ * @param {number} times 复利次数
7
+ * @returns {number} 复利金额
8
+ * @example
9
+ * compoundInterest(10000, 0.05, 5) // 12833.03
10
+ * @group Finance
11
+ */
12
+ export declare function compoundInterest(principal: number, rate: number, times: number): number;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 将 URL 参数转换为 JSON 对象
3
+ * @param {string} url 包含参数的 URL 字符串
4
+ * @returns {Record<string, string>} 转换后的 JSON 对象
5
+ * @example
6
+ * paramToJson('https://example.com?name=John&age=30') // { name: 'John', age: '30' }
7
+ * @group Link
8
+ */
9
+ export declare function paramToJson(url: string): Record<string, string>;
10
+ /**
11
+ * 将 JSON 对象转换为 URL 参数字符串
12
+ * @param {Record<string, any>} json JSON 对象
13
+ * @returns {string} 转换后的 URL 参数字符串
14
+ * @example
15
+ * jsonToParam({ name: 'John', age: 30 }) // 'name=John&age=30'
16
+ * @group Link
17
+ */
18
+ export declare function jsonToParam(json: Record<string, any>): string;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * 生成范围内的随机整数
3
+ * @param {number} min 最小值
4
+ * @param {number} max 最大值
5
+ * @returns {number} 随机整数
6
+ * @example
7
+ * randomInt(1, 10) // 5
8
+ * @group Math
9
+ */
10
+ export declare function randomInt(min: number, max: number): number;
11
+ /**
12
+ * 将角度转换为弧度
13
+ * @param {number} degrees 角度
14
+ * @returns {number} 弧度
15
+ * @example
16
+ * degreesToRadians(180) // 3.141592653589793
17
+ * @group Math
18
+ */
19
+ export declare function degreesToRadians(degrees: number): number;
20
+ /**
21
+ * 将弧度转换为角度
22
+ * @param {number} radians 弧度
23
+ * @returns {number} 角度
24
+ * @example
25
+ * radiansToDegrees(Math.PI) // 180
26
+ * @group Math
27
+ */
28
+ export declare function radiansToDegrees(radians: number): number;
29
+ /**
30
+ * 计算两点间距离
31
+ * @param {object} point1 点1 {x, y}
32
+ * @param {object} point2 点2 {x, y}
33
+ * @returns {number} 距离
34
+ * @example
35
+ * distance({ x: 0, y: 0 }, { x: 3, y: 4 }) // 5
36
+ * @group Math
37
+ */
38
+ export declare function distance(point1: {
39
+ x: number;
40
+ y: number;
41
+ }, point2: {
42
+ x: number;
43
+ y: number;
44
+ }): number;
45
+ /**
46
+ * 四舍五入到指定小数位
47
+ * @param {number} value 数值
48
+ * @param {number} decimals 小数位数
49
+ * @returns {number} 四舍五入后的数值
50
+ * @example
51
+ * round(1.2345, 2) // 1.23
52
+ * @group Math
53
+ */
54
+ export declare function round(value: number, decimals: number): number;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * 深拷贝对象
3
+ * @param {object} obj - 需要深拷贝的对象
4
+ * @param {WeakMap<object, any>} hash - 用于处理循环引用的哈希表
5
+ * @returns {object} 深拷贝后的对象
6
+ * @example
7
+ * deepClone({ a: 1, b: { c: 2 } }) // { a: 1, b: { c: 2 } }
8
+ * @group Object
9
+ */
10
+ export declare function deepClone<T>(obj: T, hash?: WeakMap<object, any>): T;
11
+ /**
12
+ * 合并对象
13
+ * @param {...object} objects 待合并的对象
14
+ * @returns 合并后的对象
15
+ * @example
16
+ * merge({ a: 1, b: 2 }, { b: 3, c: 4 }) // { a: 1, b: 3, c: 4 }
17
+ * @group Object
18
+ */
19
+ export declare function merge<T extends Record<string, any>>(...objects: Partial<T>[]): T;
20
+ /**
21
+ * 获取对象的所有键
22
+ * @param {object} obj 对象
23
+ * @returns {Array<string>} 键数组
24
+ * @example
25
+ * keys({ a: 1, b: 2 }) // ['a', 'b']
26
+ * @group Object
27
+ */
28
+ export declare function keys<T extends Record<string, any>>(obj: T): (keyof T)[];
29
+ /**
30
+ * 获取对象的所有值
31
+ * @param {object} obj 对象
32
+ * @returns {Array<T[keyof T]>} 值数组
33
+ * @example
34
+ * values({ a: 1, b: 2 }) // [1, 2]
35
+ * @group Object
36
+ */
37
+ export declare function values<T extends Record<string, any>>(obj: T): T[keyof T][];
38
+ /**
39
+ * 检查对象是否包含某个键
40
+ * @param {object} obj 对象
41
+ * @param {PropertyKey} key 键名
42
+ * @returns {boolean} 是否包含该键
43
+ * @example
44
+ * hasKey({ a: 1, b: 2 }, 'a') // true
45
+ * @group Object
46
+ */
47
+ export declare function hasKey<T extends Record<string, any>>(obj: T, key: PropertyKey): key is keyof T;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 设置本地存储
3
+ * @param {string} key 键
4
+ * @param {T} value 值
5
+ * @param {boolean} isSession 是否使用sessionStorage,默认false
6
+ * @example
7
+ * setStorage('token', '123456') // 存储token到localStorage
8
+ * setStorage('user', { id: 1, name: '张三' }, true) // 存储用户信息到sessionStorage
9
+ * @group Storage
10
+ */
11
+ export declare function setStorage<T>(key: string, value: T, isSession?: boolean): void;
12
+ /**
13
+ * 获取本地存储
14
+ * @param {string} key 键
15
+ * @param {boolean} isSession 是否使用sessionStorage,默认false
16
+ * @returns {T | null} 存储的值
17
+ * @example
18
+ * getStorage('token') // '123456'
19
+ * getStorage('user', true) // { id: 1, name: '张三' }
20
+ * @group Storage
21
+ */
22
+ export declare function getStorage<T>(key: string, isSession?: boolean): T | null;
23
+ /**
24
+ * 删除本地存储
25
+ * @param {string} key 键
26
+ * @param {boolean} isSession 是否使用sessionStorage,默认false
27
+ * @example
28
+ * removeStorage('token') // 删除localStorage中的token
29
+ * removeStorage('user', true) // 删除sessionStorage中的user
30
+ * @group Storage
31
+ */
32
+ export declare function removeStorage(key: string, isSession?: boolean): void;
33
+ /**
34
+ * 清空本地存储
35
+ * @param {boolean} isSession 是否使用sessionStorage,默认false
36
+ * @example
37
+ * clearStorage() // 清空localStorage
38
+ * clearStorage(true) // 清空sessionStorage
39
+ * @group Storage
40
+ */
41
+ export declare function clearStorage(isSession?: boolean): void;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * 检测变量类型
3
+ * @param {unknown} value 待检测的值
4
+ * @returns {string} 类型字符串
5
+ * @example
6
+ * getType({}) // 'object'
7
+ * getType([]) // 'array'
8
+ * getType('') // 'string'
9
+ * getType(0) // 'number'
10
+ * getType(true) // 'boolean'
11
+ * getType(null) // 'null'
12
+ * getType(undefined) // 'undefined'
13
+ * @group Type
14
+ */
15
+ export declare function getType(value: unknown): string;
16
+ /**
17
+ * 判断是否为数组
18
+ * @param {unknown} value 待检测的值
19
+ * @returns {boolean} 是否为数组
20
+ * @example
21
+ * isArray([]) // true
22
+ * isArray(undefined) // false
23
+ * @group Type
24
+ */
25
+ export declare function isArray(value: unknown): value is unknown[];
26
+ /**
27
+ * 判断是否为对象
28
+ * @param {unknown} value 待检测的值
29
+ * @returns {boolean} 是否为对象
30
+ * @example
31
+ * isObject({}) // true
32
+ * isObject({ a: 1, b: 2 }) // true
33
+ * isObject(undefined) // false
34
+ * @group Type
35
+ */
36
+ export declare function isObject(value: unknown): value is Record<string, unknown>;
37
+ /**
38
+ * 判断是否为函数
39
+ * @param {unknown} value 待检测的值
40
+ * @returns {boolean} 是否为函数
41
+ * @example
42
+ * isFunction(() => {}) // true
43
+ * isFunction(function () {}) // true
44
+ * isFunction(class {}) // true
45
+ * isFunction({}) // false
46
+ * @group Type
47
+ */
48
+ export declare function isFunction(value: unknown): value is Function;
49
+ /**
50
+ * 判断是否为字符串
51
+ * @param {unknown} value 待检测的值
52
+ * @returns {boolean} 是否为字符串
53
+ * @example
54
+ * isString('hello') // true
55
+ * isString(0) // false
56
+ * @group Type
57
+ */
58
+ export declare function isString(value: unknown): value is string;
59
+ /**
60
+ * 判断是否为数字
61
+ * @param {unknown} value 待检测的值
62
+ * @returns {boolean} 是否为数字
63
+ * @example
64
+ * isNumber(0) // true
65
+ * isNumber(123) // true
66
+ * isNumber('123') // false
67
+ * @group Type
68
+ */
69
+ export declare function isNumber(value: unknown): value is number;
70
+ /**
71
+ * 判断是否为布尔值
72
+ * @param {unknown} value 待检测的值
73
+ * @returns {boolean} 是否为布尔值
74
+ * @example
75
+ * isBoolean(true) // true
76
+ * isBoolean(false) // true
77
+ * isBoolean(1) // false
78
+ * @group Type
79
+ */
80
+ export declare function isBoolean(value: unknown): value is boolean;
81
+ /**
82
+ * 判断是否为null
83
+ * @param {unknown} value 待检测的值
84
+ * @returns {boolean} 是否为null
85
+ * @example
86
+ * isNull(null) // true
87
+ * isNull(undefined) // false
88
+ * @group Type
89
+ */
90
+ export declare function isNull(value: unknown): value is null;
91
+ /**
92
+ * 判断是否为undefined
93
+ * @param {unknown} value 待检测的值
94
+ * @returns {boolean} 是否为undefined
95
+ * @example
96
+ * isUndefined(undefined) // true
97
+ * isUndefined(null) // false
98
+ * isUndefined('') // false
99
+ * @group Type
100
+ */
101
+ export declare function isUndefined(value: unknown): value is undefined;
102
+ /**
103
+ * 判断是否为空(null, undefined, 空字符串, 空数组, 空对象)
104
+ * @param {unknown} value 待检测的值
105
+ * @returns {boolean} 是否为空
106
+ * @example
107
+ * isEmpty(null) // true
108
+ * isEmpty({ a: 1, b: 2 }) // false
109
+ * @group Type
110
+ */
111
+ export declare function isEmpty(value: unknown): boolean;