wjk-util 0.0.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.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/dist/f-util.es.js +1 -0
- package/dist/f-util.umd.js +1 -0
- package/dist/vite.svg +1 -0
- package/package.json +41 -0
- package/types/array.d.ts +48 -0
- package/types/date.d.ts +34 -0
- package/types/demo.d.ts +1 -0
- package/types/format.d.ts +1 -0
- package/types/index.d.ts +7 -0
- package/types/main.d.ts +1 -0
- package/types/math.d.ts +47 -0
- package/types/object.d.ts +31 -0
- package/types/storage.d.ts +25 -0
- package/types/string.d.ts +32 -0
- package/types/type.d.ts +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(t){return Object.prototype.toString.call(t).slice(8,-1).toLowerCase()}function e(t){return Array.isArray(t)}function r(e){return"object"===t(e)}function n(t){return"function"==typeof t}function o(t){return"string"==typeof t}function a(t){return"number"==typeof t&&!isNaN(t)}function c(t){return"boolean"==typeof t}function u(t){return null===t}function i(t){return void 0===t}function s(t){return!(!u(t)&&!i(t))||(o(t)||e(t)?0===t.length:!!r(t)&&0===Object.keys(t).length)}function f(t){if(!Array.isArray(t))throw new Error("参数必须是数组");return[...new Set(t)]}function l(t,e=1){if(!Array.isArray(t))throw new Error("参数必须是数组");return e<=0?t.slice():t.reduce((t,r)=>t.concat(Array.isArray(r)?l(r,e-1):[r]),[])}function g(t,e=1){if(!Array.isArray(t))throw new Error("参数必须是数组");if(e<=0)return[];const r=[];for(let n=0;n<t.length;n+=e)r.push(t.slice(n,n+e));return r}function y(t){if(Array.isArray(t)&&0!==t.length)return Math.max(...t)}function h(t){if(Array.isArray(t)&&0!==t.length)return Math.min(...t)}function p(t){if(!Array.isArray(t))throw new Error("参数必须是数组");return t.reduce((t,e)=>t+e,0)}function M(t){if(Array.isArray(t)&&0!==t.length)return p(t)/t.length}function S(t){return"string"!=typeof t?"":t.charAt(0).toUpperCase()+t.slice(1)}function m(t){return"string"!=typeof t?"":t.replace(/[-_\s]+(.)?/g,(t,e)=>e?e.toUpperCase():"")}function b(t=16){const e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let r="";for(let n=0;n<t;n++)r+=e.charAt(Math.floor(62*Math.random()));return r}function d(t,e,r="..."){return"string"!=typeof t||t.length<=e?t:t.substring(0,e)+r}function A(t){return"string"!=typeof t?"":t.split("").reverse().join("")}function w(t){if(null===t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array)return t.map(t=>w(t));if(t instanceof Object){const e={};for(let r in t)t.hasOwnProperty(r)&&(e[r]=w(t[r]));return e}return t}function D(...t){const e={};return t.forEach(t=>{t&&"object"==typeof t&&Object.keys(t).forEach(r=>{const n=r;void 0!==t[n]&&(e[n]=t[n])})}),e}function j(t){return"object"!=typeof t||null===t?[]:Object.keys(t)}function Y(t){return"object"!=typeof t||null===t?[]:Object.values(t)}function O(t,e){return"object"==typeof t&&null!==t&&t.hasOwnProperty(e)}function k(t,e="YYYY-MM-DD HH:mm:ss"){t instanceof Date||(t=new Date(t));const r=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),o=String(t.getDate()).padStart(2,"0"),a=String(t.getHours()).padStart(2,"0"),c=String(t.getMinutes()).padStart(2,"0"),u=String(t.getSeconds()).padStart(2,"0");return e.replace("YYYY",String(r)).replace("MM",n).replace("DD",o).replace("HH",a).replace("mm",c).replace("ss",u)}function E(t,e){t instanceof Date||(t=new Date(t)),e instanceof Date||(e=new Date(e));const r=e.getTime()-t.getTime();return{days:Math.floor(r/864e5),hours:Math.floor(r%864e5/36e5),minutes:Math.floor(r%36e5/6e4),seconds:Math.floor(r%6e4/1e3),milliseconds:r}}function H(t,e,r){const n=new Date(t);switch(r){case"years":n.setFullYear(n.getFullYear()+e);break;case"months":n.setMonth(n.getMonth()+e);break;case"days":n.setDate(n.getDate()+e);break;case"hours":n.setHours(n.getHours()+e);break;case"minutes":n.setMinutes(n.getMinutes()+e);break;case"seconds":n.setSeconds(n.getSeconds()+e);break;default:throw new Error("不支持的时间单位")}return n}function v(t){return t instanceof Date&&(t=t.getFullYear()),t%4==0&&t%100!=0||t%400==0}function x(t,e){return Math.floor(Math.random()*(e-t+1))+t}function F(t,e,r){return Math.min(Math.max(t,e),r)}function I(t){return t*(Math.PI/180)}function N(t){return t*(180/Math.PI)}function P(t,e){const r=e.x-t.x,n=e.y-t.y;return Math.sqrt(r*r+n*n)}function C(t,e){return Number(Math.round(parseFloat(t+"e"+e))+"e-"+e)}function T(t,e,r=!1){try{(r?sessionStorage:localStorage).setItem(t,JSON.stringify(e))}catch(n){console.error("存储失败:",n)}}function J(t,e=!1){try{const r=(e?sessionStorage:localStorage).getItem(t);return r?JSON.parse(r):null}catch(r){return console.error("获取存储失败:",r),null}}function U(t,e=!1){try{(e?sessionStorage:localStorage).removeItem(t)}catch(r){console.error("删除存储失败:",r)}}function q(t=!1){try{(t?sessionStorage:localStorage).clear()}catch(e){console.error("清空存储失败:",e)}}export{H as add,M as average,m as camelCase,S as capitalize,g as chunk,F as clamp,q as clearStorage,w as deepClone,I as degreesToRadians,E as diff,P as distance,l as flatten,k as format,J as getStorage,t as getType,O as hasKey,e as isArray,c as isBoolean,s as isEmpty,n as isFunction,v as isLeapYear,u as isNull,a as isNumber,r as isObject,o as isString,i as isUndefined,j as keys,y as max,D as merge,h as min,N as radiansToDegrees,x as randomInt,b as randomString,U as removeStorage,A as reverse,C as round,T as setStorage,p as sum,d as truncate,f as unique,Y as values};
|
|
@@ -0,0 +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).FUtil={})}(this,function(e){"use strict";function t(e){return Object.prototype.toString.call(e).slice(8,-1).toLowerCase()}function r(e){return Array.isArray(e)}function n(e){return"object"===t(e)}function o(e){return"string"==typeof e}function a(e){return null===e}function i(e){return void 0===e}function s(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return e.reduce((e,t)=>e+t,0)}e.add=function(e,t,r){const n=new Date(e);switch(r){case"years":n.setFullYear(n.getFullYear()+t);break;case"months":n.setMonth(n.getMonth()+t);break;case"days":n.setDate(n.getDate()+t);break;case"hours":n.setHours(n.getHours()+t);break;case"minutes":n.setMinutes(n.getMinutes()+t);break;case"seconds":n.setSeconds(n.getSeconds()+t);break;default:throw new Error("不支持的时间单位")}return n},e.average=function(e){if(Array.isArray(e)&&0!==e.length)return s(e)/e.length},e.camelCase=function(e){return"string"!=typeof e?"":e.replace(/[-_\s]+(.)?/g,(e,t)=>t?t.toUpperCase():"")},e.capitalize=function(e){return"string"!=typeof e?"":e.charAt(0).toUpperCase()+e.slice(1)},e.chunk=function(e,t=1){if(!Array.isArray(e))throw new Error("参数必须是数组");if(t<=0)return[];const r=[];for(let n=0;n<e.length;n+=t)r.push(e.slice(n,n+t));return r},e.clamp=function(e,t,r){return Math.min(Math.max(e,t),r)},e.clearStorage=function(e=!1){try{(e?sessionStorage:localStorage).clear()}catch(t){console.error("清空存储失败:",t)}},e.deepClone=function e(t){if(null===t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof Array)return t.map(t=>e(t));if(t instanceof Object){const r={};for(let n in t)t.hasOwnProperty(n)&&(r[n]=e(t[n]));return r}return t},e.degreesToRadians=function(e){return e*(Math.PI/180)},e.diff=function(e,t){e instanceof Date||(e=new Date(e)),t instanceof Date||(t=new Date(t));const r=t.getTime()-e.getTime();return{days:Math.floor(r/864e5),hours:Math.floor(r%864e5/36e5),minutes:Math.floor(r%36e5/6e4),seconds:Math.floor(r%6e4/1e3),milliseconds:r}},e.distance=function(e,t){const r=t.x-e.x,n=t.y-e.y;return Math.sqrt(r*r+n*n)},e.flatten=function e(t,r=1){if(!Array.isArray(t))throw new Error("参数必须是数组");return r<=0?t.slice():t.reduce((t,n)=>t.concat(Array.isArray(n)?e(n,r-1):[n]),[])},e.format=function(e,t="YYYY-MM-DD HH:mm:ss"){e instanceof Date||(e=new Date(e));const r=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),o=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),i=String(e.getMinutes()).padStart(2,"0"),s=String(e.getSeconds()).padStart(2,"0");return t.replace("YYYY",String(r)).replace("MM",n).replace("DD",o).replace("HH",a).replace("mm",i).replace("ss",s)},e.getStorage=function(e,t=!1){try{const r=(t?sessionStorage:localStorage).getItem(e);return r?JSON.parse(r):null}catch(r){return console.error("获取存储失败:",r),null}},e.getType=t,e.hasKey=function(e,t){return"object"==typeof e&&null!==e&&e.hasOwnProperty(t)},e.isArray=r,e.isBoolean=function(e){return"boolean"==typeof e},e.isEmpty=function(e){return!(!a(e)&&!i(e))||(o(e)||r(e)?0===e.length:!!n(e)&&0===Object.keys(e).length)},e.isFunction=function(e){return"function"==typeof e},e.isLeapYear=function(e){return e instanceof Date&&(e=e.getFullYear()),e%4==0&&e%100!=0||e%400==0},e.isNull=a,e.isNumber=function(e){return"number"==typeof e&&!isNaN(e)},e.isObject=n,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(r=>{const n=r;void 0!==e[n]&&(t[n]=e[n])})}),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.randomString=function(e=16){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let r="";for(let n=0;n<e;n++)r+=t.charAt(Math.floor(62*Math.random()));return r},e.removeStorage=function(e,t=!1){try{(t?sessionStorage:localStorage).removeItem(e)}catch(r){console.error("删除存储失败:",r)}},e.reverse=function(e){return"string"!=typeof e?"":e.split("").reverse().join("")},e.round=function(e,t){return Number(Math.round(parseFloat(e+"e"+t))+"e-"+t)},e.setStorage=function(e,t,r=!1){try{(r?sessionStorage:localStorage).setItem(e,JSON.stringify(t))}catch(n){console.error("存储失败:",n)}},e.sum=s,e.truncate=function(e,t,r="..."){return"string"!=typeof e||e.length<=t?e:e.substring(0,t)+r},e.unique=function(e){if(!Array.isArray(e))throw new Error("参数必须是数组");return[...new Set(e)]},e.values=function(e){return"object"!=typeof e||null===e?[]:Object.values(e)},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
|
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="77" height="47" fill="none" aria-labelledby="vite-logo-title" viewBox="0 0 77 47"><title id="vite-logo-title">Vite</title><style>.parenthesis{fill:#000}@media (prefers-color-scheme:dark){.parenthesis{fill:#fff}}</style><path fill="#9135ff" d="M40.151 45.71c-.663.844-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.493c-.92 0-1.457-1.04-.92-1.788l7.479-10.471c1.07-1.498 0-3.578-1.842-3.578H15.443c-.92 0-1.456-1.04-.92-1.788l9.696-13.576c.213-.297.556-.474.92-.474h28.894c.92 0 1.456 1.04.92 1.788l-7.48 10.472c-1.07 1.497 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.087.89 1.83L40.153 45.712z"/><mask id="a" width="48" height="47" x="14" y="0" maskUnits="userSpaceOnUse" style="mask-type:alpha"><path fill="#000" d="M40.047 45.71c-.663.843-2.02.374-2.02-.699V34.708a2.26 2.26 0 0 0-2.262-2.262H24.389c-.92 0-1.457-1.04-.92-1.788l7.479-10.472c1.07-1.497 0-3.578-1.842-3.578H15.34c-.92 0-1.456-1.04-.92-1.788l9.696-13.575c.213-.297.556-.474.92-.474H53.93c.92 0 1.456 1.04.92 1.788L47.37 13.03c-1.07 1.498 0 3.578 1.842 3.578h11.376c.944 0 1.474 1.088.89 1.831L40.049 45.712z"/></mask><g mask="url(#a)"><g filter="url(#b)"><ellipse cx="5.508" cy="14.704" fill="#eee6ff" rx="5.508" ry="14.704" transform="rotate(269.814 20.96 11.29)scale(-1 1)"/></g><g filter="url(#c)"><ellipse cx="10.399" cy="29.851" fill="#eee6ff" rx="10.399" ry="29.851" transform="rotate(89.814 -16.902 -8.275)scale(1 -1)"/></g><g filter="url(#d)"><ellipse cx="5.508" cy="30.487" fill="#8900ff" rx="5.508" ry="30.487" transform="rotate(89.814 -19.197 -7.127)scale(1 -1)"/></g><g filter="url(#e)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.928 4.177)scale(1 -1)"/></g><g filter="url(#f)"><ellipse cx="5.508" cy="30.599" fill="#8900ff" rx="5.508" ry="30.599" transform="rotate(89.814 -25.738 5.52)scale(1 -1)"/></g><g filter="url(#g)"><ellipse cx="14.072" cy="22.078" fill="#eee6ff" rx="14.072" ry="22.078" transform="rotate(93.35 31.245 55.578)scale(-1 1)"/></g><g filter="url(#h)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#i)"><ellipse cx="3.47" cy="21.501" fill="#8900ff" rx="3.47" ry="21.501" transform="rotate(89.009 35.419 55.202)scale(-1 1)"/></g><g filter="url(#j)"><ellipse cx="14.592" cy="9.743" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(39.51 14.592 9.743)"/></g><g filter="url(#k)"><ellipse cx="61.728" cy="-5.321" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 61.728 -5.32)"/></g><g filter="url(#l)"><ellipse cx="55.618" cy="7.104" fill="#00c2ff" rx="5.971" ry="9.665" transform="rotate(37.892 55.618 7.104)"/></g><g filter="url(#m)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#n)"><ellipse cx="12.326" cy="39.103" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 12.326 39.103)"/></g><g filter="url(#o)"><ellipse cx="49.857" cy="30.678" fill="#8900ff" rx="4.407" ry="29.108" transform="rotate(37.892 49.857 30.678)"/></g><g filter="url(#p)"><ellipse cx="52.623" cy="33.171" fill="#00c2ff" rx="5.971" ry="15.297" transform="rotate(37.892 52.623 33.17)"/></g></g><path d="M6.919 0c-9.198 13.166-9.252 33.575 0 46.789h6.215c-9.25-13.214-9.196-33.623 0-46.789zm62.424 0h-6.215c9.198 13.166 9.252 33.575 0 46.789h6.215c9.25-13.214 9.196-33.623 0-46.789" class="parenthesis"/><defs><filter id="b" width="60.045" height="41.654" x="-5.564" y="16.92" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="c" width="90.34" height="51.437" x="-40.407" y="-6.762" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="d" width="79.355" height="29.4" x="-35.435" y="2.801" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="e" width="79.579" height="29.4" x="-30.84" y="20.8" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="f" width="79.579" height="29.4" x="-29.307" y="21.949" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="g" width="74.749" height="58.852" x="29.961" y="-17.13" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="7.659"/></filter><filter id="h" width="61.377" height="25.362" x="37.754" y="3.055" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="i" width="61.377" height="25.362" x="37.754" y="3.055" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="j" width="56.045" height="63.649" x="-13.43" y="-22.082" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="k" width="54.814" height="64.646" x="34.321" y="-37.644" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="l" width="33.541" height="35.313" x="38.847" y="-10.552" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="m" width="54.814" height="64.646" x="-15.081" y="6.78" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="n" width="54.814" height="64.646" x="-15.081" y="6.78" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="o" width="54.814" height="64.646" x="22.45" y="-1.645" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter><filter id="p" width="39.409" height="43.623" x="32.919" y="11.36" color-interpolation-filters="sRGB" filterUnits="userSpaceOnUse"><feFlood flood-opacity="0" result="BackgroundImageFix"/><feBlend in="SourceGraphic" in2="BackgroundImageFix" result="shape"/><feGaussianBlur result="effect1_foregroundBlur_2002_17286" stdDeviation="4.596"/></filter></defs></svg>
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wjk-util",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "一个包含常见 JavaScript 函数的实用库",
|
|
6
|
+
"author": "wjk",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "gitee",
|
|
10
|
+
"url": "https://gitee.com/wjkfree/f-util.git"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://gitee.com/wjkfree/f-util#readme",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"utility",
|
|
15
|
+
"functions",
|
|
16
|
+
"typescript"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"types"
|
|
21
|
+
],
|
|
22
|
+
"main": "./dist/f-util.umd.js",
|
|
23
|
+
"module": "./dist/f-util.es.js",
|
|
24
|
+
"types": "./types/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"types": "./types/index.d.ts",
|
|
27
|
+
"import": "./dist/f-util.es.js",
|
|
28
|
+
"require": "./dist/f-util.umd.js"
|
|
29
|
+
},
|
|
30
|
+
"sideEffects": false,
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vite",
|
|
33
|
+
"build": "vite build"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"terser": "^5.46.0",
|
|
37
|
+
"typescript": "~5.9.3",
|
|
38
|
+
"vite": "^7.3.1",
|
|
39
|
+
"vite-plugin-dts": "^4.5.4"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/types/array.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数组去重
|
|
3
|
+
* @param array 待去重数组
|
|
4
|
+
* @returns 去重后的数组
|
|
5
|
+
* @example
|
|
6
|
+
* unique([1, 2, 2, 3, 4, 4, 5]) // [1, 2, 3, 4, 5]
|
|
7
|
+
*/
|
|
8
|
+
export declare function unique<T>(array: T[]): T[];
|
|
9
|
+
/**
|
|
10
|
+
* 数组扁平化
|
|
11
|
+
* @param array 待扁平化数组
|
|
12
|
+
* @param depth 扁平化深度,默认为1
|
|
13
|
+
* @returns 扁平化后的数组
|
|
14
|
+
* @example
|
|
15
|
+
* flatten([1, [2, [3, [4, [5]]]]]) // [1, 2, [3, [4, [5]]]]
|
|
16
|
+
*/
|
|
17
|
+
export declare function flatten<T>(array: (T | T[])[], depth?: number): T[];
|
|
18
|
+
/**
|
|
19
|
+
* 数组分块
|
|
20
|
+
* @param array 待分块数组
|
|
21
|
+
* @param size 每块大小
|
|
22
|
+
* @returns 分块后的二维数组
|
|
23
|
+
*/
|
|
24
|
+
export declare function chunk<T>(array: T[], size?: number): T[][];
|
|
25
|
+
/**
|
|
26
|
+
* 获取数组中的最大值
|
|
27
|
+
* @param array 数字数组
|
|
28
|
+
* @returns 最大值
|
|
29
|
+
*/
|
|
30
|
+
export declare function max(array: number[]): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* 获取数组中的最小值
|
|
33
|
+
* @param array 数字数组
|
|
34
|
+
* @returns 最小值
|
|
35
|
+
*/
|
|
36
|
+
export declare function min(array: number[]): number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* 数组求和
|
|
39
|
+
* @param array 数字数组
|
|
40
|
+
* @returns 求和结果
|
|
41
|
+
*/
|
|
42
|
+
export declare function sum(array: number[]): number;
|
|
43
|
+
/**
|
|
44
|
+
* 数组平均值
|
|
45
|
+
* @param array 数字数组
|
|
46
|
+
* @returns 平均值
|
|
47
|
+
*/
|
|
48
|
+
export declare function average(array: number[]): number | undefined;
|
package/types/date.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 格式化日期
|
|
3
|
+
* @param date 日期对象
|
|
4
|
+
* @param format 格式字符串
|
|
5
|
+
* @returns 格式化后的日期字符串
|
|
6
|
+
*/
|
|
7
|
+
export declare function format(date: Date | string | number, format?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* 获取时间差
|
|
10
|
+
* @param startDate 开始日期
|
|
11
|
+
* @param endDate 结束日期
|
|
12
|
+
* @returns 时间差对象
|
|
13
|
+
*/
|
|
14
|
+
export declare function diff(startDate: Date | string | number, endDate: Date | string | number): {
|
|
15
|
+
days: number;
|
|
16
|
+
hours: number;
|
|
17
|
+
minutes: number;
|
|
18
|
+
seconds: number;
|
|
19
|
+
milliseconds: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* 添加时间
|
|
23
|
+
* @param date 日期
|
|
24
|
+
* @param amount 数量
|
|
25
|
+
* @param unit 单位 (years, months, days, hours, minutes, seconds)
|
|
26
|
+
* @returns 新日期
|
|
27
|
+
*/
|
|
28
|
+
export declare function add(date: Date | string | number, amount: number, unit: 'years' | 'months' | 'days' | 'hours' | 'minutes' | 'seconds'): Date;
|
|
29
|
+
/**
|
|
30
|
+
* 判断是否为闰年
|
|
31
|
+
* @param year 年份或日期对象
|
|
32
|
+
* @returns 是否为闰年
|
|
33
|
+
*/
|
|
34
|
+
export declare function isLeapYear(year: number | Date): boolean;
|
package/types/demo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function formatDate(timestamp: number): string;
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { getType, isArray, isObject, isFunction, isString, isNumber, isBoolean, isNull, isUndefined, isEmpty } from './type';
|
|
2
|
+
export { unique, flatten, chunk, max, min, sum, average } from './array';
|
|
3
|
+
export { capitalize, camelCase, randomString, truncate, reverse } from './string';
|
|
4
|
+
export { deepClone, merge, keys, values, hasKey } from './object';
|
|
5
|
+
export { format, diff, add, isLeapYear } from './date';
|
|
6
|
+
export { randomInt, clamp, degreesToRadians, radiansToDegrees, distance, round } from './math';
|
|
7
|
+
export { setStorage, getStorage, removeStorage, clearStorage } from './storage';
|
package/types/main.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function setupCounter(element: HTMLButtonElement): void;
|
package/types/math.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 生成范围内的随机整数
|
|
3
|
+
* @param min 最小值
|
|
4
|
+
* @param max 最大值
|
|
5
|
+
* @returns 随机整数
|
|
6
|
+
*/
|
|
7
|
+
export declare function randomInt(min: number, max: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* 限制数值在指定范围内
|
|
10
|
+
* @param value 数值
|
|
11
|
+
* @param min 最小值
|
|
12
|
+
* @param max 最大值
|
|
13
|
+
* @returns 限制后的数值
|
|
14
|
+
*/
|
|
15
|
+
export declare function clamp(value: number, min: number, max: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* 将角度转换为弧度
|
|
18
|
+
* @param degrees 角度
|
|
19
|
+
* @returns 弧度
|
|
20
|
+
*/
|
|
21
|
+
export declare function degreesToRadians(degrees: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* 将弧度转换为角度
|
|
24
|
+
* @param radians 弧度
|
|
25
|
+
* @returns 角度
|
|
26
|
+
*/
|
|
27
|
+
export declare function radiansToDegrees(radians: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* 计算两点间距离
|
|
30
|
+
* @param point1 点1 {x, y}
|
|
31
|
+
* @param point2 点2 {x, y}
|
|
32
|
+
* @returns 距离
|
|
33
|
+
*/
|
|
34
|
+
export declare function distance(point1: {
|
|
35
|
+
x: number;
|
|
36
|
+
y: number;
|
|
37
|
+
}, point2: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
}): number;
|
|
41
|
+
/**
|
|
42
|
+
* 四舍五入到指定小数位
|
|
43
|
+
* @param value 数值
|
|
44
|
+
* @param decimals 小数位数
|
|
45
|
+
* @returns 四舍五入后的数值
|
|
46
|
+
*/
|
|
47
|
+
export declare function round(value: number, decimals: number): number;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 深拷贝对象
|
|
3
|
+
* @param obj 待拷贝对象
|
|
4
|
+
* @returns 拷贝后的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare function deepClone<T>(obj: T): T;
|
|
7
|
+
/**
|
|
8
|
+
* 合并对象
|
|
9
|
+
* @param objects 待合并的对象
|
|
10
|
+
* @returns 合并后的对象
|
|
11
|
+
*/
|
|
12
|
+
export declare function merge<T extends Record<string, any>>(...objects: Partial<T>[]): T;
|
|
13
|
+
/**
|
|
14
|
+
* 获取对象的所有键
|
|
15
|
+
* @param obj 对象
|
|
16
|
+
* @returns 键数组
|
|
17
|
+
*/
|
|
18
|
+
export declare function keys<T extends Record<string, any>>(obj: T): (keyof T)[];
|
|
19
|
+
/**
|
|
20
|
+
* 获取对象的所有值
|
|
21
|
+
* @param obj 对象
|
|
22
|
+
* @returns 值数组
|
|
23
|
+
*/
|
|
24
|
+
export declare function values<T extends Record<string, any>>(obj: T): T[keyof T][];
|
|
25
|
+
/**
|
|
26
|
+
* 检查对象是否包含某个键
|
|
27
|
+
* @param obj 对象
|
|
28
|
+
* @param key 键名
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasKey<T extends Record<string, any>>(obj: T, key: PropertyKey): key is keyof T;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 设置本地存储
|
|
3
|
+
* @param key 键
|
|
4
|
+
* @param value 值
|
|
5
|
+
* @param isSession 是否使用sessionStorage,默认false
|
|
6
|
+
*/
|
|
7
|
+
export declare function setStorage<T>(key: string, value: T, isSession?: boolean): void;
|
|
8
|
+
/**
|
|
9
|
+
* 获取本地存储
|
|
10
|
+
* @param key 键
|
|
11
|
+
* @param isSession 是否使用sessionStorage,默认false
|
|
12
|
+
* @returns 存储的值
|
|
13
|
+
*/
|
|
14
|
+
export declare function getStorage<T>(key: string, isSession?: boolean): T | null;
|
|
15
|
+
/**
|
|
16
|
+
* 删除本地存储
|
|
17
|
+
* @param key 键
|
|
18
|
+
* @param isSession 是否使用sessionStorage,默认false
|
|
19
|
+
*/
|
|
20
|
+
export declare function removeStorage(key: string, isSession?: boolean): void;
|
|
21
|
+
/**
|
|
22
|
+
* 清空本地存储
|
|
23
|
+
* @param isSession 是否使用sessionStorage,默认false
|
|
24
|
+
*/
|
|
25
|
+
export declare function clearStorage(isSession?: boolean): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 首字母大写
|
|
3
|
+
* @param str 字符串
|
|
4
|
+
* @returns 首字母大写后的字符串
|
|
5
|
+
*/
|
|
6
|
+
export declare function capitalize(str: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* 驼峰命名转换
|
|
9
|
+
* @param str 字符串
|
|
10
|
+
* @returns 驼峰命名字符串
|
|
11
|
+
*/
|
|
12
|
+
export declare function camelCase(str: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 生成随机字符串
|
|
15
|
+
* @param length 字符串长度
|
|
16
|
+
* @returns 随机字符串
|
|
17
|
+
*/
|
|
18
|
+
export declare function randomString(length?: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* 截取字符串并添加省略号
|
|
21
|
+
* @param str 原始字符串
|
|
22
|
+
* @param length 截取长度
|
|
23
|
+
* @param suffix 后缀,默认为...
|
|
24
|
+
* @returns 处理后的字符串
|
|
25
|
+
*/
|
|
26
|
+
export declare function truncate(str: string, length: number, suffix?: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* 字符串反转
|
|
29
|
+
* @param str 字符串
|
|
30
|
+
* @returns 反转后的字符串
|
|
31
|
+
*/
|
|
32
|
+
export declare function reverse(str: string): string;
|
package/types/type.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检测变量类型
|
|
3
|
+
* @param value 待检测的值
|
|
4
|
+
* @returns 类型字符串
|
|
5
|
+
*/
|
|
6
|
+
export declare function getType(value: unknown): string;
|
|
7
|
+
/**
|
|
8
|
+
* 判断是否为数组
|
|
9
|
+
* @param value 待检测的值
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare function isArray(value: unknown): value is unknown[];
|
|
13
|
+
/**
|
|
14
|
+
* 判断是否为对象
|
|
15
|
+
* @param value 待检测的值
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* 判断是否为函数
|
|
21
|
+
* @param value 待检测的值
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare function isFunction(value: unknown): value is Function;
|
|
25
|
+
/**
|
|
26
|
+
* 判断是否为字符串
|
|
27
|
+
* @param value 待检测的值
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function isString(value: unknown): value is string;
|
|
31
|
+
/**
|
|
32
|
+
* 判断是否为数字
|
|
33
|
+
* @param value 待检测的值
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function isNumber(value: unknown): value is number;
|
|
37
|
+
/**
|
|
38
|
+
* 判断是否为布尔值
|
|
39
|
+
* @param value 待检测的值
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export declare function isBoolean(value: unknown): value is boolean;
|
|
43
|
+
/**
|
|
44
|
+
* 判断是否为null
|
|
45
|
+
* @param value 待检测的值
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function isNull(value: unknown): value is null;
|
|
49
|
+
/**
|
|
50
|
+
* 判断是否为undefined
|
|
51
|
+
* @param value 待检测的值
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
export declare function isUndefined(value: unknown): value is undefined;
|
|
55
|
+
/**
|
|
56
|
+
* 判断是否为空(null, undefined, 空字符串, 空数组, 空对象)
|
|
57
|
+
* @param value 待检测的值
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export declare function isEmpty(value: unknown): boolean;
|