devix 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,36 +1,104 @@
1
1
  # devix
2
2
 
3
- > Devix is a comprehensive, powerful, and compact JavaScript utility library.
3
+ > devix 是一个全面的、强大的、紧凑的 JavaScript 实用程序库( 简体中文 | [English](README_en.md)
4
4
 
5
- ## Install
5
+ ## 安装
6
+
7
+ 请确保您在 Node.js 环境下使用 npm 或其他包管理器安装此库。
6
8
 
7
9
  ```shell
8
10
  npm install --save-dev devix
9
11
  ```
10
12
 
11
- ## Usage
13
+ 然后,利用现代的模块捆绑工具,如 Vite 或 Webpack,以模块化的语法引入此库。
12
14
 
13
15
  ```javascript
14
- // Using ES Module
16
+ // 使用 ES Module
15
17
  import { [[ModuleName]] } from 'devix'
16
18
 
17
- // Using CommonJS
18
- var { [[ModuleName]] } = require('devix')
19
+ // 使用 CommonJS
20
+ const { [[ModuleName]] } = require('devix')
21
+ ```
22
+
23
+ ## 使用
24
+
25
+ ```javascript
26
+ import { localCache, bubblingSort, isType } from 'devix'
27
+
28
+ // 使用 localCache
29
+ localCache.setCache('userInfo', { name: 'king', age: 18 })
30
+ const userInfo = localCache.get('userInfo')
31
+ console.log('userInfo', userInfo)
32
+
33
+ // 使用 bubblingSort、
34
+ const arr1 = [123, 346, 62, 2456, 56123, 1, 64, 61, 453, 72345]
35
+ const sortArr1 = bubblingSort(arr1, 'DESC')
36
+ console.log('sortArr1', sortArr1)
37
+ const arr2 = [
38
+ { name: 'zsan', age: 16 },
39
+ { name: 'lisi', age: 32 },
40
+ { name: 'wawu', age: 25 },
41
+ { name: 'king', age: 18 }
42
+ ]
43
+ const sortArr2 = bubblingSort(arr2, 'DESC', 'age')
44
+ console.log('sortArr2', sortArr2)
45
+
46
+ // 使用 isType
47
+ console.log(`isType(userInfo,'object') -> true`, isType(userInfo, 'object'))
48
+ console.log(
49
+ `isType(userInfo.name,'string') -> true`,
50
+ isType(userInfo, 'string')
51
+ )
52
+ console.log(`isType(userInfo.age,'number') -> true`, isType(userInfo, 'number'))
19
53
  ```
20
54
 
21
- ## API
55
+ ## 方法
56
+
57
+ ### 缓存相关
58
+
59
+ 提供缓存操作的相关方法。
60
+
61
+ - localCache
62
+ - sessionCache
63
+
64
+ ### 拷贝相关
65
+
66
+ 用于数据复制操作的相关方法。
67
+
68
+ - deepClone
69
+ - shallowClone
70
+
71
+ ### 限频相关
72
+
73
+ 包含控制操作触发频率的相关方法。
74
+
75
+ - throttle
76
+ - debounce
77
+
78
+ ### 排序相关
79
+
80
+ 提供各种排序操作的方法。
22
81
 
23
82
  - bubblingSort
83
+
84
+ ### 时间相关
85
+
86
+ 包括处理时间相关操作的方法。
87
+
88
+ - formatTimer
89
+ - setTimer
90
+
91
+ ### 类型相关
92
+
93
+ 用于数据类型检测的相关方法。
94
+
95
+ - isType
96
+
97
+ ### 其他方法
98
+
99
+ 包括各种其他功能性函数和方法。
100
+
24
101
  - compose
25
102
  - currying
26
- - debounce
27
- - deepClone
28
- - formatTimer
29
103
  - insertStr
30
- - isType
31
- - localCache
32
- - sessionCache
33
- - setTimer
34
- - shallowClone
35
104
  - stringCase
36
- - throttle
package/dist/index.d.ts CHANGED
@@ -2,9 +2,6 @@ declare function currying(fn: Function): (this: any, ...args: any[]) => any;
2
2
  declare function compose(...fns: Function[]): ((this: any, ...args: any[]) => any) | undefined;
3
3
  declare function insertStr(soure: string, start: number, newStr: string): string;
4
4
  declare function stringCase(soure: string, separator?: string, separate?: string): string;
5
- declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): {
6
- cancel: () => void;
7
- };
8
5
 
9
6
  declare const isType: (type: string, target: any) => boolean;
10
7
 
@@ -63,5 +60,8 @@ declare enum SortType {
63
60
  declare function bubblingSort<T>(array: T[], type?: SortType, key?: keyof T): T[];
64
61
 
65
62
  declare const formatTimer: TFormatTimer;
63
+ declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): {
64
+ cancel: () => void;
65
+ };
66
66
 
67
67
  export { bubblingSort, compose, currying, debounce, deepClone, formatTimer, insertStr, isType, localCache, sessionCache, setTimer, shallowClone, stringCase, throttle };
package/dist/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- function t(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}}function e(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}}function n(t,e,n){return t.slice(0,e)+n+t.slice(e)}function o(t,e="",n=""){const o=t.split(e);for(let t=0;t<o.length;t++)o[t]=o[t].slice(0,1).toUpperCase()+o[t].slice(1).toLowerCase();return o.join(n)}function r(t,e=0,n=!1){let o=null;const r=()=>{t(),o=setTimeout(r,e)};return n&&t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}}const c={string:t=>"string"==typeof t,number:t=>"number"==typeof t,boolean:t=>"boolean"==typeof t,null:t=>null===t,undefined:t=>void 0===t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,date:t=>t instanceof Date,regexp:t=>t instanceof RegExp},i=(t,e)=>c[t]?.(e)||!1;var s;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(s||(s={}));class a{constructor(t){this.storage=t===s.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,n){const o=this.getCache(t);i("object",o)&&(o[e]=n,this.setCache(t,o))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const u=new a(s.Local),l=new a(s.Session);function f(t,e=0,n=!1){let o=null,r=!1;function c(...c){return new Promise(((i,s)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}r=!0}}))}return c.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},c}function y(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let c=0,i=null;function s(...n){return new Promise(((s,a)=>{try{const a=Date.now();let u;o||0!==c||(c=a);const l=e-(a-c);if(l<=0)return i&&clearTimeout(i),u=t.apply(this,n),s(u),c=a,void(i=null);r&&!i&&(i=setTimeout((()=>{u=t.apply(this,n),s(u),c=Date.now(),i=null}),l))}catch(t){a(t)}}))}return s.cancel=function(){i&&clearTimeout(i),c=0,i=null},s}
1
+ function t(t){return function e(...n){return n.length>=t.length?t.apply(this,n):function(...t){return e.apply(this,n.concat(t))}}}function e(...t){const e=t.length;if(!(e<=0)){for(let n=0;n<e;n++){if("function"!=typeof t[n])throw new Error(`argument with index ${n} is not a function`)}return function(...n){let o=0,r=t[o].apply(this,n);for(;++o<e;)r=t[o].call(this,r);return r}}}function n(t,e,n){return t.slice(0,e)+n+t.slice(e)}function o(t,e="",n=""){const o=t.split(e);for(let t=0;t<o.length;t++)o[t]=o[t].slice(0,1).toUpperCase()+o[t].slice(1).toLowerCase();return o.join(n)}const r={string:t=>"string"==typeof t,number:t=>"number"==typeof t,boolean:t=>"boolean"==typeof t,null:t=>null===t,undefined:t=>void 0===t,symbol:t=>"symbol"==typeof t,bigint:t=>"bigint"==typeof t,object:t=>null!==t&&"object"==typeof t,array:t=>Array.isArray(t),function:t=>"function"==typeof t,set:t=>t instanceof Set,map:t=>t instanceof Map,date:t=>t instanceof Date,regexp:t=>t instanceof RegExp},c=(t,e)=>r[t]?.(e)||!1;var i;!function(t){t[t.Local=0]="Local",t[t.Session=1]="Session"}(i||(i={}));class s{constructor(t){this.storage=t===i.Local?localStorage:sessionStorage}getCache(t){const e=this.storage.getItem(t);return e?JSON.parse(e):null}setCache(t,e){this.storage.setItem(t,JSON.stringify(e))}updateCache(t,e,n){const o=this.getCache(t);c("object",o)&&(o[e]=n,this.setCache(t,o))}deleteCache(t){this.storage.removeItem(t)}clearCache(){this.storage.clear()}}const a=new s(i.Local),u=new s(i.Session);function l(t,e=0,n=!1){let o=null,r=!1;function c(...c){return new Promise(((i,s)=>{if(null!==o&&clearTimeout(o),!n||r)o=setTimeout((()=>{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}finally{o=null,r=!1}}),e);else{try{const e=t.apply(this,c);i(e)}catch(t){s(t)}r=!0}}))}return c.cancel=function(){null!==o&&clearTimeout(o),o=null,r=!1},c}function f(t,e,n={}){const{leading:o=!0,trailing:r=!1}=n;let c=0,i=null;function s(...n){return new Promise(((s,a)=>{try{const a=Date.now();let u;o||0!==c||(c=a);const l=e-(a-c);if(l<=0)return i&&clearTimeout(i),u=t.apply(this,n),s(u),c=a,void(i=null);r&&!i&&(i=setTimeout((()=>{u=t.apply(this,n),s(u),c=Date.now(),i=null}),l))}catch(t){a(t)}}))}return s.cancel=function(){i&&clearTimeout(i),c=0,i=null},s}
2
2
  //! Function Shallow Copy
3
- function g(t){return i("array",t)?t.slice():i("object",t)?{...t}:t}
3
+ function y(t){return c("array",t)?t.slice():c("object",t)?{...t}:t}
4
4
  //! Function Deep Copy
5
- const p=t=>i("object",t)||i("function",t);function h(t,e=new WeakMap){if(e.get(t))return e.get(t);const n=function(t,e,n){if(i("symbol",t))return Symbol(t.description);if(!p(t))return t;if(i("set",t)){const o=new Set;return t.forEach((t=>o.add(e(t,n)))),o}if(i("map",t)){const o=new Map;return t.forEach(((t,r)=>o.set(r,e(t,n)))),o}}(t,h,e);if(n)return n;const o=i("array",t),r=o?[]:{};return e.set(t,r),o?t.forEach(((t,n)=>{r[n]=h(t,e)})):(Object.keys(t).forEach((n=>{r[n]=h(t[n],e)})),Object.getOwnPropertySymbols(t).forEach((n=>{r[Symbol(n.description)]=h(t[n],e)}))),r}var m;function S(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function d(t,e,n){return n===m.ASC?t>e:t<e}function w(t,e=m.ASC,n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let c=0;c<o-1-r;c++){d(n?t[c][n]:t[c],n?t[c+1][n]:t[c+1],e)&&S(t,c,c+1)}return t}!function(t){t.ASC="ASC",t.DESC="DESC"}(m||(m={}));const b=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),C=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function M(t){return t.toString().padStart(2,"0")}const D=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const n=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:M(t.getMonth()+1),day:M(t.getDate()),hours:M(t.getHours()),minutes:M(t.getMinutes()),seconds:M(t.getSeconds()),week:(n=e,C.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(i("string",e)&&!e.trim())return n;return Array.from(b).reduce(((t,[e,o])=>t.replace(new RegExp(e,"g"),n[o])),e)};export{w as bubblingSort,e as compose,t as currying,f as debounce,h as deepClone,D as formatTimer,n as insertStr,i as isType,u as localCache,l as sessionCache,r as setTimer,g as shallowClone,o as stringCase,y as throttle};
5
+ const g=t=>c("object",t)||c("function",t);function p(t,e=new WeakMap){if(e.get(t))return e.get(t);const n=function(t,e,n){if(c("symbol",t))return Symbol(t.description);if(!g(t))return t;if(c("set",t)){const o=new Set;return t.forEach((t=>o.add(e(t,n)))),o}if(c("map",t)){const o=new Map;return t.forEach(((t,r)=>o.set(r,e(t,n)))),o}}(t,p,e);if(n)return n;const o=c("array",t),r=o?[]:{};return e.set(t,r),o?t.forEach(((t,n)=>{r[n]=p(t,e)})):(Object.keys(t).forEach((n=>{r[n]=p(t[n],e)})),Object.getOwnPropertySymbols(t).forEach((n=>{r[Symbol(n.description)]=p(t[n],e)}))),r}var h;function m(t,e,n){[t[e],t[n]]=[t[n],t[e]]}function S(t,e,n){return n===h.ASC?t>e:t<e}function d(t,e=h.ASC,n){const o=t.length;if(o<2)return t;for(let r=0;r<o-1;r++)for(let c=0;c<o-1-r;c++){S(n?t[c][n]:t[c],n?t[c+1][n]:t[c+1],e)&&m(t,c,c+1)}return t}!function(t){t.ASC="ASC",t.DESC="DESC"}(h||(h={}));const w=new Map([["yyyy","year"],["MM","month"],["dd","day"],["HH","hours"],["mm","minutes"],["ss","seconds"],["W","week"]]),b=new Map([[1,"一"],[2,"二"],[3,"三"],[4,"四"],[5,"五"],[6,"六"],[0,"日"]]);function C(t){return t.toString().padStart(2,"0")}const M=(t,e="yyyy-MM-dd HH:mm:ss")=>{if(!t)return(new Date).toISOString();const n=function(t){const e=0===t.getDay()?7:t.getDay();return{year:t.getFullYear().toString(),month:C(t.getMonth()+1),day:C(t.getDate()),hours:C(t.getHours()),minutes:C(t.getMinutes()),seconds:C(t.getSeconds()),week:(n=e,b.get(n)||""),weekNum:e.toString()};var n}(new Date(t));if(c("string",e)&&!e.trim())return n;return Array.from(w).reduce(((t,[e,o])=>t.replace(new RegExp(e,"g"),n[o])),e)};function D(t,e=0,n=!1){let o=null;const r=()=>{t(),o=setTimeout(r,e)};return n&&t(),setTimeout(r,e),{cancel:()=>{null!==o&&clearTimeout(o)}}}export{d as bubblingSort,e as compose,t as currying,l as debounce,p as deepClone,M as formatTimer,n as insertStr,c as isType,a as localCache,u as sessionCache,D as setTimer,y as shallowClone,o as stringCase,f as throttle};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "devix",
3
3
  "type": "module",
4
- "version": "0.0.17",
4
+ "version": "0.0.19",
5
5
  "description": "Devix is a comprehensive, powerful, and compact JavaScript utility library.",
6
6
  "author": "king-3 <w2196592083@gmail.com>",
7
7
  "license": "MIT",
@@ -33,11 +33,12 @@
33
33
  "dist"
34
34
  ],
35
35
  "scripts": {
36
- "build": "rollup -c",
37
- "dev": "yarn build --watch",
36
+ "build": "pnpm lint && pnpm prettier && rollup -c",
37
+ "dev": "npx --yes tsx example/index.ts",
38
38
  "test": "jest",
39
39
  "lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
40
- "prettier": "prettier --config .prettierrc.json --write ./**/**/*.{js,jsx,ts,tsx,json}"
40
+ "prettier": "prettier --config .prettierrc.json --write src/**/*.{js,jsx,ts,tsx,json}",
41
+ "releases": "npx bump && tsx publish.ts"
41
42
  },
42
43
  "devDependencies": {
43
44
  "@babel/core": "^7.24.0",
@@ -54,6 +55,7 @@
54
55
  "eslint": "^8.57.0",
55
56
  "eslint-config-prettier": "^9.1.0",
56
57
  "eslint-plugin-prettier": "^5.1.3",
58
+ "fsxx": "^0.1.0",
57
59
  "jest": "^29.7.0",
58
60
  "prettier": "^3.2.5",
59
61
  "rollup": "^4.13.0",
@@ -61,6 +63,8 @@
61
63
  "rollup-plugin-typescript2": "^0.36.0",
62
64
  "ts-jest": "^29.1.2",
63
65
  "tslib": "^2.6.2",
64
- "typescript": "^5.4.2"
66
+ "typescript": "^5.4.2",
67
+ "version-bump-prompt": "^6.1.0",
68
+ "zx": "^7.2.3"
65
69
  }
66
70
  }