devix 0.0.22 → 0.0.23-beta.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/index.d.ts ADDED
@@ -0,0 +1,53 @@
1
+ interface ITimerObj {
2
+ year: string;
3
+ month: string;
4
+ day: string;
5
+ hours: string;
6
+ minutes: string;
7
+ seconds: string;
8
+ week: string;
9
+ weekNum: string;
10
+ }
11
+ type TFormatTimer = (cellValue: string | number | Date, formatType?: string) => string | ITimerObj;
12
+ type ThrottleOptions = {
13
+ leading?: boolean;
14
+ trailing?: boolean;
15
+ };
16
+ type TIsType = (type: string, target: any) => boolean;
17
+ type Tcase = 'upper' | 'lower';
18
+ type TCases = [Tcase, Tcase];
19
+ type TTransGetParams = (params: IDataObject) => string;
20
+ interface IDataObject {
21
+ [key: string]: any;
22
+ }
23
+
24
+ declare function currying(fn: Function): (this: any, ...args: any[]) => any;
25
+ declare function compose(...fns: Function[]): ((this: any, ...args: any[]) => any) | undefined;
26
+ declare function insertStr(soure: string, start: number, newStr: string): string;
27
+ declare function stringCase(soure: string, separa?: string[], cases?: TCases): string;
28
+ declare const transformGetParams: TTransGetParams;
29
+
30
+ declare const isType: TIsType;
31
+
32
+ declare function debounce<T extends (...args: any[]) => any>(callback: T, delay?: number, immediate?: boolean): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
33
+ cancel: () => void;
34
+ };
35
+ declare function throttle<T extends (...args: any[]) => any>(callback: T, interval: number, options?: ThrottleOptions): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
36
+ cancel: () => void;
37
+ };
38
+
39
+ declare function shallowClone<T = any>(source: T): T;
40
+ declare function deepClone(source: any, hash?: WeakMap<object, any>): any;
41
+
42
+ declare enum SortType {
43
+ ASC = "ASC",
44
+ DESC = "DESC"
45
+ }
46
+ declare function bubblingSort<T>(array: T[], type?: string, key?: keyof T): T[];
47
+
48
+ declare const formatTimer: TFormatTimer;
49
+ declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): Promise<{
50
+ cancel: () => void;
51
+ }>;
52
+
53
+ export { SortType, bubblingSort, compose, currying, debounce, deepClone, formatTimer, insertStr, isType, setTimer, shallowClone, stringCase, throttle, transformGetParams };
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ const isObject = (target) => target !== null && typeof target === "object";
4
+ var CacheType;
5
+ (function(CacheType2) {
6
+ CacheType2[CacheType2["Local"] = 0] = "Local";
7
+ CacheType2[CacheType2["Session"] = 1] = "Session";
8
+ })(CacheType || (CacheType = {}));
9
+
10
+ class StorageCache {
11
+ constructor(type) {
12
+ this.storage = type === CacheType.Local ? localStorage : sessionStorage;
13
+ }
14
+ getCache(key) {
15
+ const value = this.storage.getItem(key);
16
+ return value ? JSON.parse(value) : null;
17
+ }
18
+ setCache(key, value) {
19
+ this.storage.setItem(key, JSON.stringify(value));
20
+ }
21
+ updateCache(key, property, value) {
22
+ const cache = this.getCache(key);
23
+ if (!isObject(cache)) return;
24
+ cache[property] = value;
25
+ this.setCache(key, cache);
26
+ }
27
+ deleteCache(key) {
28
+ this.storage.removeItem(key);
29
+ }
30
+ clearCache() {
31
+ this.storage.clear();
32
+ }
33
+ }
34
+ const localCache = new StorageCache(CacheType.Local);
35
+ const sessionCache = new StorageCache(CacheType.Session);
36
+
37
+ exports.localCache = localCache;
38
+ exports.sessionCache = sessionCache;
@@ -0,0 +1,35 @@
1
+ const isObject = (target) => target !== null && typeof target === "object";
2
+ var CacheType;
3
+ (function(CacheType2) {
4
+ CacheType2[CacheType2["Local"] = 0] = "Local";
5
+ CacheType2[CacheType2["Session"] = 1] = "Session";
6
+ })(CacheType || (CacheType = {}));
7
+
8
+ class StorageCache {
9
+ constructor(type) {
10
+ this.storage = type === CacheType.Local ? localStorage : sessionStorage;
11
+ }
12
+ getCache(key) {
13
+ const value = this.storage.getItem(key);
14
+ return value ? JSON.parse(value) : null;
15
+ }
16
+ setCache(key, value) {
17
+ this.storage.setItem(key, JSON.stringify(value));
18
+ }
19
+ updateCache(key, property, value) {
20
+ const cache = this.getCache(key);
21
+ if (!isObject(cache)) return;
22
+ cache[property] = value;
23
+ this.setCache(key, cache);
24
+ }
25
+ deleteCache(key) {
26
+ this.storage.removeItem(key);
27
+ }
28
+ clearCache() {
29
+ this.storage.clear();
30
+ }
31
+ }
32
+ const localCache = new StorageCache(CacheType.Local);
33
+ const sessionCache = new StorageCache(CacheType.Session);
34
+
35
+ export { localCache, sessionCache };
package/package.json CHANGED
@@ -1,82 +1,75 @@
1
1
  {
2
2
  "name": "devix",
3
3
  "type": "module",
4
- "version": "0.0.22",
4
+ "version": "0.0.23-beta.1",
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",
8
8
  "homepage": "https://github.com/OpenKnights/devix#readme",
9
9
  "repository": {
10
10
  "type": "git",
11
- "url": "https://github.com/OpenKnights/devix.git"
11
+ "url": "git+https://github.com/OpenKnights/devix.git"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/OpenKnights/devix/issues"
15
15
  },
16
16
  "keywords": [
17
- "devix",
18
- "utils",
19
- "tools",
20
- "develop"
17
+ "template",
18
+ "library"
21
19
  ],
22
20
  "exports": {
23
21
  ".": {
22
+ "types": "./index.d.ts",
24
23
  "import": "./dist/index.esm.js",
25
24
  "require": "./dist/index.cjs.js"
26
25
  }
27
26
  },
27
+ "types": "./index.d.ts",
28
28
  "main": "./dist/index.cjs.js",
29
29
  "module": "./dist/index.esm.js",
30
- "umd": "./dist/index.umd.js",
31
- "types": "dist/index.d.ts",
32
30
  "files": [
33
31
  "dist/",
32
+ "lib/",
34
33
  "package.json",
35
- "README.md"
34
+ "README.md",
35
+ "index.d.ts"
36
36
  ],
37
37
  "scripts": {
38
- "build": " pnpm prettier && pnpm lint && rollup -c",
39
- "dev": "npx --yes tsx --watch example/index.ts",
38
+ "build": "rollup -c",
40
39
  "test": "jest",
41
- "lint": "eslint src/**/*.{js,jsx,ts,tsx,json}",
42
- "prettier": "prettier --config .prettierrc.json --write src/**/*.{js,jsx,ts,tsx,json}",
43
- "releases": "npx bump && tsx publish.ts",
40
+ "lint": "npx eslint src/**/*.ts && npx eslint test/**/*.ts && npx eslint types/**/*.ts",
41
+ "prettier": "npx prettier --config .prettierrc.json --write ./**/*.{ts,json}",
42
+ "releases": "pwsh publish.ps1",
44
43
  "versihint": "npx bump"
45
44
  },
46
45
  "devDependencies": {
47
- "@babel/core": "^7.24.0",
48
- "@babel/preset-env": "^7.24.0",
49
- "@babel/preset-typescript": "^7.23.3",
46
+ "@babel/core": "^7.24.5",
47
+ "@babel/preset-env": "^7.24.5",
48
+ "@babel/preset-typescript": "^7.24.1",
49
+ "@rollup/plugin-alias": "^5.1.0",
50
50
  "@rollup/plugin-babel": "^6.0.4",
51
51
  "@rollup/plugin-commonjs": "^25.0.7",
52
52
  "@rollup/plugin-json": "^6.1.0",
53
53
  "@rollup/plugin-node-resolve": "^15.2.3",
54
- "@rollup/plugin-terser": "^0.4.4",
55
54
  "@types/jest": "^29.5.12",
56
- "@types/koa": "^2.15.0",
57
- "@types/koa-bodyparser": "^4.3.12",
58
- "@types/koa-json": "^2.0.23",
59
- "@types/koa-router": "^7.4.8",
60
- "@types/node": "^20.12.7",
61
- "@typescript-eslint/eslint-plugin": "^7.3.1",
62
- "@typescript-eslint/parser": "^7.3.1",
55
+ "@typescript-eslint/eslint-plugin": "^7.8.0",
56
+ "@typescript-eslint/parser": "^7.8.0",
57
+ "esbuild": "^0.21.0",
63
58
  "eslint": "^8.57.0",
59
+ "eslint-config-airbnb-base": "^15.0.0",
60
+ "eslint-config-airbnb-typescript": "^18.0.0",
64
61
  "eslint-config-prettier": "^9.1.0",
62
+ "eslint-plugin-import": "^2.29.1",
65
63
  "eslint-plugin-prettier": "^5.1.3",
66
- "fsxx": "^0.1.0",
67
64
  "jest": "^29.7.0",
68
- "koa": "^2.15.3",
69
- "koa-bodyparser": "^4.4.1",
70
- "koa-json": "^2.0.2",
71
- "koa-router": "^12.0.1",
72
65
  "prettier": "^3.2.5",
73
- "rollup": "^4.13.0",
66
+ "rollup": "^4.17.2",
74
67
  "rollup-plugin-dts": "^6.1.0",
68
+ "rollup-plugin-esbuild": "^6.1.1",
75
69
  "rollup-plugin-typescript2": "^0.36.0",
76
70
  "ts-jest": "^29.1.2",
77
71
  "tslib": "^2.6.2",
78
- "typescript": "^5.4.2",
79
- "version-bump-prompt": "^6.1.0",
80
- "zx": "^7.2.3"
72
+ "typescript": "^5.4.5",
73
+ "version-bump-prompt": "^6.1.0"
81
74
  }
82
75
  }
package/dist/index.d.ts DELETED
@@ -1,96 +0,0 @@
1
- //! format types
2
- interface ITimerObj {
3
- year: string
4
- month: string
5
- day: string
6
- hours: string
7
- minutes: string
8
- seconds: string
9
- week: string
10
- weekNum: string
11
- }
12
-
13
- type TFormatTimer = (
14
- cellValue: string | number | Date,
15
- formatType?: string
16
- ) => string | ITimerObj
17
-
18
- //! retalimit types
19
- type ThrottleOptions = {
20
- leading?: boolean
21
- trailing?: boolean
22
- }
23
-
24
- interface TestServerOption {
25
- url: string
26
- method: string
27
- handler: (ctx: any, next: any) => any
28
- }
29
-
30
- interface ITestServerOptions {
31
- routes?: Array<TestServerOption>
32
- }
33
- type TIsType = (type: string, target: any) => boolean
34
-
35
- //! other types
36
- type Tcase = 'upper' | 'lower'
37
- type TCases = [Tcase, Tcase]
38
- type TTransGetParams = (params: IDataObject) => string
39
- interface IDataObject {
40
- [key: string]: any
41
- }
42
-
43
- declare function currying(fn: Function): (this: any, ...args: any[]) => any;
44
- declare function compose(...fns: Function[]): ((this: any, ...args: any[]) => any) | undefined;
45
- declare function insertStr(soure: string, start: number, newStr: string): string;
46
- declare function stringCase(soure: string, separa?: string[], cases?: TCases): string;
47
- declare const transformGetParams: TTransGetParams;
48
-
49
- declare const isType: TIsType;
50
-
51
- declare enum CacheType {
52
- Local = 0,
53
- Session = 1
54
- }
55
- /**
56
- * Encapsulate storage cache class
57
- *
58
- * @class StorageCache
59
- * @template T
60
- */
61
- declare class StorageCache<T = any> {
62
- private storage;
63
- constructor(type: CacheType);
64
- getCache(key: string): T;
65
- setCache(key: string, value: T): void;
66
- updateCache(key: string, property: string, value: T): void;
67
- deleteCache(key: string): void;
68
- clearCache(): void;
69
- }
70
- declare const localCache: StorageCache<any>;
71
- declare const sessionCache: StorageCache<any>;
72
-
73
- declare function debounce<T extends (...args: any[]) => any>(callback: T, delay?: number, immediate?: boolean): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
74
- cancel: () => void;
75
- };
76
- declare function throttle<T extends (...args: any[]) => any>(callback: T, interval: number, options?: ThrottleOptions): ((...args: Parameters<T>) => Promise<ReturnType<T>>) & {
77
- cancel: () => void;
78
- };
79
-
80
- declare function shallowClone<T = any>(source: T): T;
81
- declare function deepClone(source: any, hash?: WeakMap<object, any>): any;
82
-
83
- declare enum SortType {
84
- ASC = "ASC",
85
- DESC = "DESC"
86
- }
87
- declare function bubblingSort<T>(array: T[], type?: string, key?: keyof T): T[];
88
-
89
- declare const formatTimer: TFormatTimer;
90
- declare function setTimer(execute: (...args: any[]) => any, delay?: number, immediate?: boolean): Promise<{
91
- cancel: () => void;
92
- }>;
93
-
94
- declare const createTestServer: (options?: ITestServerOptions) => any;
95
-
96
- export { SortType, bubblingSort, compose, createTestServer, currying, debounce, deepClone, formatTimer, insertStr, isType, localCache, sessionCache, setTimer, shallowClone, stringCase, throttle, transformGetParams };