wjk-util 0.0.1 → 0.0.4
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/README.md +4 -2
- package/dist/f-util.es.js +1 -1
- package/dist/f-util.umd.js +1 -1
- package/package.json +3 -2
- package/types/index.d.ts +5 -7
- package/types/date.d.ts +0 -34
- package/types/demo.d.ts +0 -1
- package/types/format.d.ts +0 -1
- package/types/main.d.ts +0 -1
- package/types/string.d.ts +0 -32
- /package/types/{array.d.ts → module/array.d.ts} +0 -0
- /package/types/{math.d.ts → module/math.d.ts} +0 -0
- /package/types/{object.d.ts → module/object.d.ts} +0 -0
- /package/types/{storage.d.ts → module/storage.d.ts} +0 -0
- /package/types/{type.d.ts → module/type.d.ts} +0 -0
package/README.md
CHANGED
package/dist/f-util.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function r(r){return Object.prototype.toString.call(r).slice(8,-1).toLowerCase()}function t(r){return Array.isArray(r)}function n(t){return"object"===r(t)}function e(r){return"function"==typeof r}function o(r){return"string"==typeof r}function u(r){return"number"==typeof r&&!isNaN(r)}function c(r){return"boolean"==typeof r}function i(r){return null===r}function a(r){return void 0===r}function f(r){return!(!i(r)&&!a(r))||(o(r)||t(r)?0===r.length:!!n(r)&&0===Object.keys(r).length)}function s(r){if(!Array.isArray(r))throw new Error("参数必须是数组");return[...new Set(r)]}function l(r,t=1){if(!Array.isArray(r))throw new Error("参数必须是数组");return t<=0?r.slice():r.reduce((r,n)=>r.concat(Array.isArray(n)?l(n,t-1):[n]),[])}function y(r,t=1){if(!Array.isArray(r))throw new Error("参数必须是数组");if(t<=0)return[];const n=[];for(let e=0;e<r.length;e+=t)n.push(r.slice(e,e+t));return n}function h(r){if(Array.isArray(r)&&0!==r.length)return Math.max(...r)}function g(r){if(Array.isArray(r)&&0!==r.length)return Math.min(...r)}function A(r){if(!Array.isArray(r))throw new Error("参数必须是数组");return r.reduce((r,t)=>r+t,0)}function p(r){if(Array.isArray(r)&&0!==r.length)return A(r)/r.length}function b(r){if(null===r||"object"!=typeof r)return r;if(r instanceof Date)return new Date(r.getTime());if(r instanceof Array)return r.map(r=>b(r));if(r instanceof Object){const t={};for(let n in r)r.hasOwnProperty(n)&&(t[n]=b(r[n]));return t}return r}function m(...r){const t={};return r.forEach(r=>{r&&"object"==typeof r&&Object.keys(r).forEach(n=>{const e=n;void 0!==r[e]&&(t[e]=r[e])})}),t}function w(r){return"object"!=typeof r||null===r?[]:Object.keys(r)}function j(r){return"object"!=typeof r||null===r?[]:Object.values(r)}function S(r,t){return"object"==typeof r&&null!==r&&r.hasOwnProperty(t)}function M(r,t){return Math.floor(Math.random()*(t-r+1))+r}function O(r,t,n){return Math.min(Math.max(r,t),n)}function d(r){return r*(Math.PI/180)}function E(r){return r*(180/Math.PI)}function x(r,t){const n=t.x-r.x,e=t.y-r.y;return Math.sqrt(n*n+e*e)}function I(r,t){return Number(Math.round(parseFloat(r+"e"+t))+"e-"+t)}function N(r,t,n=!1){try{(n?sessionStorage:localStorage).setItem(r,JSON.stringify(t))}catch(e){console.error("存储失败:",e)}}function v(r,t=!1){try{const n=(t?sessionStorage:localStorage).getItem(r);return n?JSON.parse(n):null}catch(n){return console.error("获取存储失败:",n),null}}function P(r,t=!1){try{(t?sessionStorage:localStorage).removeItem(r)}catch(n){console.error("删除存储失败:",n)}}function k(r=!1){try{(r?sessionStorage:localStorage).clear()}catch(t){console.error("清空存储失败:",t)}}export{p as average,y as chunk,O as clamp,k as clearStorage,b as deepClone,d as degreesToRadians,x as distance,l as flatten,v as getStorage,r as getType,S as hasKey,t as isArray,c as isBoolean,f as isEmpty,e as isFunction,i as isNull,u as isNumber,n as isObject,o as isString,a as isUndefined,w as keys,h as max,m as merge,g as min,E as radiansToDegrees,M as randomInt,P as removeStorage,I as round,N as setStorage,A as sum,s as unique,j as values};
|
package/dist/f-util.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e
|
|
1
|
+
!function(r,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((r="undefined"!=typeof globalThis?globalThis:r||self).FUtil={})}(this,function(r){"use strict";function e(r){return Object.prototype.toString.call(r).slice(8,-1).toLowerCase()}function t(r){return Array.isArray(r)}function n(r){return"object"===e(r)}function o(r){return"string"==typeof r}function i(r){return null===r}function u(r){return void 0===r}function a(r){if(!Array.isArray(r))throw new Error("参数必须是数组");return r.reduce((r,e)=>r+e,0)}r.average=function(r){if(Array.isArray(r)&&0!==r.length)return a(r)/r.length},r.chunk=function(r,e=1){if(!Array.isArray(r))throw new Error("参数必须是数组");if(e<=0)return[];const t=[];for(let n=0;n<r.length;n+=e)t.push(r.slice(n,n+e));return t},r.clamp=function(r,e,t){return Math.min(Math.max(r,e),t)},r.clearStorage=function(r=!1){try{(r?sessionStorage:localStorage).clear()}catch(e){console.error("清空存储失败:",e)}},r.deepClone=function r(e){if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof Array)return e.map(e=>r(e));if(e instanceof Object){const t={};for(let n in e)e.hasOwnProperty(n)&&(t[n]=r(e[n]));return t}return e},r.degreesToRadians=function(r){return r*(Math.PI/180)},r.distance=function(r,e){const t=e.x-r.x,n=e.y-r.y;return Math.sqrt(t*t+n*n)},r.flatten=function r(e,t=1){if(!Array.isArray(e))throw new Error("参数必须是数组");return t<=0?e.slice():e.reduce((e,n)=>e.concat(Array.isArray(n)?r(n,t-1):[n]),[])},r.getStorage=function(r,e=!1){try{const t=(e?sessionStorage:localStorage).getItem(r);return t?JSON.parse(t):null}catch(t){return console.error("获取存储失败:",t),null}},r.getType=e,r.hasKey=function(r,e){return"object"==typeof r&&null!==r&&r.hasOwnProperty(e)},r.isArray=t,r.isBoolean=function(r){return"boolean"==typeof r},r.isEmpty=function(r){return!(!i(r)&&!u(r))||(o(r)||t(r)?0===r.length:!!n(r)&&0===Object.keys(r).length)},r.isFunction=function(r){return"function"==typeof r},r.isNull=i,r.isNumber=function(r){return"number"==typeof r&&!isNaN(r)},r.isObject=n,r.isString=o,r.isUndefined=u,r.keys=function(r){return"object"!=typeof r||null===r?[]:Object.keys(r)},r.max=function(r){if(Array.isArray(r)&&0!==r.length)return Math.max(...r)},r.merge=function(...r){const e={};return r.forEach(r=>{r&&"object"==typeof r&&Object.keys(r).forEach(t=>{const n=t;void 0!==r[n]&&(e[n]=r[n])})}),e},r.min=function(r){if(Array.isArray(r)&&0!==r.length)return Math.min(...r)},r.radiansToDegrees=function(r){return r*(180/Math.PI)},r.randomInt=function(r,e){return Math.floor(Math.random()*(e-r+1))+r},r.removeStorage=function(r,e=!1){try{(e?sessionStorage:localStorage).removeItem(r)}catch(t){console.error("删除存储失败:",t)}},r.round=function(r,e){return Number(Math.round(parseFloat(r+"e"+e))+"e-"+e)},r.setStorage=function(r,e,t=!1){try{(t?sessionStorage:localStorage).setItem(r,JSON.stringify(e))}catch(n){console.error("存储失败:",n)}},r.sum=a,r.unique=function(r){if(!Array.isArray(r))throw new Error("参数必须是数组");return[...new Set(r)]},r.values=function(r){return"object"!=typeof r||null===r?[]:Object.values(r)},Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wjk-util",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "一个包含常见 JavaScript 函数的实用库",
|
|
6
6
|
"author": "wjk",
|
|
@@ -30,7 +30,8 @@
|
|
|
30
30
|
"sideEffects": false,
|
|
31
31
|
"scripts": {
|
|
32
32
|
"dev": "vite",
|
|
33
|
-
"build": "vite build"
|
|
33
|
+
"build": "vite build",
|
|
34
|
+
"release": "npm version patch && npm publish"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"terser": "^5.46.0",
|
package/types/index.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export { randomInt, clamp, degreesToRadians, radiansToDegrees, distance, round } from './math';
|
|
7
|
-
export { setStorage, getStorage, removeStorage, clearStorage } from './storage';
|
|
1
|
+
export * from './module/type';
|
|
2
|
+
export * from './module/array';
|
|
3
|
+
export * from './module/object';
|
|
4
|
+
export * from './module/math';
|
|
5
|
+
export * from './module/storage';
|
package/types/date.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
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
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/types/format.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function formatDate(timestamp: number): string;
|
package/types/main.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function setupCounter(element: HTMLButtonElement): void;
|
package/types/string.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
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;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|