@jiakun-zhao/utils 1.1.2 → 1.2.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/README.md CHANGED
@@ -7,4 +7,3 @@ Extends [@antfu/utils](https://github.com/antfu/utils) and add some utils.
7
7
  ```bash
8
8
  pnpm i -D @jiakun-zhao/utils
9
9
  ```
10
-
package/dist/index.cjs CHANGED
@@ -1,34 +1,14 @@
1
1
  'use strict';
2
2
 
3
- const isFunction = (val) => typeof val === "function";
4
- const isBoolean = (val) => typeof val === "boolean";
5
- const isNumber = (val) => typeof val === "number";
6
- const isString = (val) => typeof val === "string";
7
- const toString = (value) => Object.prototype.toString.call(value);
8
- const isObject = (val) => toString(val) === "[object Object]";
9
- const isUndefined = (val) => toString(val) === "[object Undefined]";
10
- const isNull = (val) => toString(val) === "[object Null]";
11
- const isRegExp = (val) => toString(val) === "[object RegExp]";
12
- const isDate = (val) => toString(val) === "[object Date]";
13
- const isArray = Array.isArray;
14
- const notNullish = (v) => v != null;
15
- const notNull = (v) => v !== null;
16
- const notUndefined = (v) => v !== void 0;
3
+ const utils = require('@antfu/utils');
17
4
 
18
5
  function singleOrNull(arr) {
19
6
  return arr.length === 1 ? arr[0] : null;
20
7
  }
21
- function toArray(array) {
22
- array = array ?? [];
23
- return isArray(array) ? array : [array];
24
- }
25
8
 
26
- function take(value, fn) {
9
+ function transform(value, fn) {
27
10
  return fn(value);
28
11
  }
29
- function takeIf(value, predicate, defaultValue) {
30
- return predicate(value) ? value : notUndefined(defaultValue) ? defaultValue : null;
31
- }
32
12
  function safe(fn) {
33
13
  try {
34
14
  return fn();
@@ -36,10 +16,6 @@ function safe(fn) {
36
16
  }
37
17
  }
38
18
 
39
- function random(max, min = 0) {
40
- return Math.floor(Math.random() * max) + min;
41
- }
42
-
43
19
  const colors = {
44
20
  /** 重置颜色 */
45
21
  reset: "\x1B[0m",
@@ -102,26 +78,26 @@ function print(msg, type) {
102
78
  }
103
79
 
104
80
  const timestamp = () => +Date.now();
81
+ const isArray = Array.isArray;
82
+ function getValueOrUndefined(condition, value) {
83
+ return condition ? value : void 0;
84
+ }
85
+ function cleanString(str, regexp) {
86
+ return str.replace(regexp, "");
87
+ }
88
+ function random(max, min = 0) {
89
+ return Math.floor(Math.random() * max) + min;
90
+ }
105
91
 
106
- exports.colors = colors;
92
+ exports.cleanString = cleanString;
93
+ exports.getValueOrUndefined = getValueOrUndefined;
107
94
  exports.isArray = isArray;
108
- exports.isBoolean = isBoolean;
109
- exports.isDate = isDate;
110
- exports.isFunction = isFunction;
111
- exports.isNull = isNull;
112
- exports.isNumber = isNumber;
113
- exports.isObject = isObject;
114
- exports.isRegExp = isRegExp;
115
- exports.isString = isString;
116
- exports.isUndefined = isUndefined;
117
- exports.notNull = notNull;
118
- exports.notNullish = notNullish;
119
- exports.notUndefined = notUndefined;
120
95
  exports.print = print;
121
96
  exports.random = random;
122
97
  exports.safe = safe;
123
98
  exports.singleOrNull = singleOrNull;
124
- exports.take = take;
125
- exports.takeIf = takeIf;
126
99
  exports.timestamp = timestamp;
127
- exports.toArray = toArray;
100
+ exports.transform = transform;
101
+ Object.keys(utils).forEach(function (k) {
102
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = utils[k];
103
+ });
package/dist/index.d.cts CHANGED
@@ -1,86 +1,10 @@
1
- type Nullable<T> = T | null | undefined;
2
- type NotNullable<T> = Exclude<T, null | undefined>;
3
- type NotNull<T> = Exclude<T, null>;
4
- type NotUndefined<T> = Exclude<T, undefined>;
5
- type Arrayable<T> = T | Array<T>;
6
- type ElementOf<T> = T extends Array<infer Element> ? Element : never;
7
- type Fn<R = void> = (...args: any[]) => R;
1
+ export * from '@antfu/utils';
8
2
 
9
3
  declare function singleOrNull<T>(arr: T[]): T | null;
10
- declare function toArray<T>(array?: T | Array<T>): Array<T>;
11
4
 
12
- declare function take<T, R = void>(value: T, fn: (it: T) => R): R;
13
- declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
14
- declare function takeIf<T>(value: T, predicate: (it: T) => boolean, defaultValue: T): T;
5
+ declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
15
6
  declare function safe<R>(fn: () => R): R | undefined;
16
7
 
17
- declare const isFunction: (val: any) => val is Fn;
18
- declare const isBoolean: (val: any) => val is boolean;
19
- declare const isNumber: (val: any) => val is number;
20
- declare const isString: (val: unknown) => val is string;
21
- declare const isObject: (val: any) => val is object;
22
- declare const isUndefined: (val: any) => val is undefined;
23
- declare const isNull: (val: any) => val is null;
24
- declare const isRegExp: (val: any) => val is RegExp;
25
- declare const isDate: (val: any) => val is Date;
26
- declare const isArray: (arg: any) => arg is any[];
27
- declare const notNullish: <T>(v: T | null | undefined) => v is NonNullable<T>;
28
- declare const notNull: <T>(v: T | null) => v is Exclude<T, null>;
29
- declare const notUndefined: <T>(v: T | undefined) => v is Exclude<T, undefined>;
30
-
31
- /**
32
- * @description min <= result < max
33
- */
34
- declare function random(max: number, min?: number): number;
35
-
36
- declare const colors: {
37
- /** 重置颜色 */
38
- reset: string;
39
- /** 亮色(加粗) */
40
- bright: string;
41
- /** 斜体 */
42
- italic: string;
43
- /** 下划线 */
44
- underline: string;
45
- /** 反向 */
46
- reverse: string;
47
- /** 隐藏 */
48
- hidden: string;
49
- /** 灰色 */
50
- grey: string;
51
- /** 黑色 */
52
- black: string;
53
- /** 红色 */
54
- red: string;
55
- /** 绿色 */
56
- green: string;
57
- /** 黄色 */
58
- yellow: string;
59
- /** 蓝色 */
60
- blue: string;
61
- /** 品红 */
62
- magenta: string;
63
- /** 青色 */
64
- cyan: string;
65
- /** 白色 */
66
- white: string;
67
- /** 背景黑色 */
68
- bgBlack: string;
69
- /** 背景红色 */
70
- bgRed: string;
71
- /** 背景绿色 */
72
- bgGreen: string;
73
- /** 背景黄色 */
74
- bgYellow: string;
75
- /** 背景蓝色 */
76
- bgBlue: string;
77
- /** 背景品红 */
78
- bgMagenta: string;
79
- /** 背景青色 */
80
- bgCyan: string;
81
- /** 背景白色 */
82
- bgWhite: string;
83
- };
84
8
  declare const map: {
85
9
  info: {
86
10
  color: string;
@@ -106,5 +30,12 @@ declare const map: {
106
30
  declare function print(msg: any, type?: keyof typeof map): void;
107
31
 
108
32
  declare const timestamp: () => number;
33
+ declare const isArray: (arg: any) => arg is any[];
34
+ declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
35
+ declare function cleanString(str: string, regexp: RegExp): string;
36
+ /**
37
+ * @description min <= result < max
38
+ */
39
+ declare function random(max: number, min?: number): number;
109
40
 
110
- export { type Arrayable, type ElementOf, type Fn, type NotNull, type NotNullable, type NotUndefined, type Nullable, colors, isArray, isBoolean, isDate, isFunction, isNull, isNumber, isObject, isRegExp, isString, isUndefined, notNull, notNullish, notUndefined, print, random, safe, singleOrNull, take, takeIf, timestamp, toArray };
41
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/dist/index.d.mts CHANGED
@@ -1,86 +1,10 @@
1
- type Nullable<T> = T | null | undefined;
2
- type NotNullable<T> = Exclude<T, null | undefined>;
3
- type NotNull<T> = Exclude<T, null>;
4
- type NotUndefined<T> = Exclude<T, undefined>;
5
- type Arrayable<T> = T | Array<T>;
6
- type ElementOf<T> = T extends Array<infer Element> ? Element : never;
7
- type Fn<R = void> = (...args: any[]) => R;
1
+ export * from '@antfu/utils';
8
2
 
9
3
  declare function singleOrNull<T>(arr: T[]): T | null;
10
- declare function toArray<T>(array?: T | Array<T>): Array<T>;
11
4
 
12
- declare function take<T, R = void>(value: T, fn: (it: T) => R): R;
13
- declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
14
- declare function takeIf<T>(value: T, predicate: (it: T) => boolean, defaultValue: T): T;
5
+ declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
15
6
  declare function safe<R>(fn: () => R): R | undefined;
16
7
 
17
- declare const isFunction: (val: any) => val is Fn;
18
- declare const isBoolean: (val: any) => val is boolean;
19
- declare const isNumber: (val: any) => val is number;
20
- declare const isString: (val: unknown) => val is string;
21
- declare const isObject: (val: any) => val is object;
22
- declare const isUndefined: (val: any) => val is undefined;
23
- declare const isNull: (val: any) => val is null;
24
- declare const isRegExp: (val: any) => val is RegExp;
25
- declare const isDate: (val: any) => val is Date;
26
- declare const isArray: (arg: any) => arg is any[];
27
- declare const notNullish: <T>(v: T | null | undefined) => v is NonNullable<T>;
28
- declare const notNull: <T>(v: T | null) => v is Exclude<T, null>;
29
- declare const notUndefined: <T>(v: T | undefined) => v is Exclude<T, undefined>;
30
-
31
- /**
32
- * @description min <= result < max
33
- */
34
- declare function random(max: number, min?: number): number;
35
-
36
- declare const colors: {
37
- /** 重置颜色 */
38
- reset: string;
39
- /** 亮色(加粗) */
40
- bright: string;
41
- /** 斜体 */
42
- italic: string;
43
- /** 下划线 */
44
- underline: string;
45
- /** 反向 */
46
- reverse: string;
47
- /** 隐藏 */
48
- hidden: string;
49
- /** 灰色 */
50
- grey: string;
51
- /** 黑色 */
52
- black: string;
53
- /** 红色 */
54
- red: string;
55
- /** 绿色 */
56
- green: string;
57
- /** 黄色 */
58
- yellow: string;
59
- /** 蓝色 */
60
- blue: string;
61
- /** 品红 */
62
- magenta: string;
63
- /** 青色 */
64
- cyan: string;
65
- /** 白色 */
66
- white: string;
67
- /** 背景黑色 */
68
- bgBlack: string;
69
- /** 背景红色 */
70
- bgRed: string;
71
- /** 背景绿色 */
72
- bgGreen: string;
73
- /** 背景黄色 */
74
- bgYellow: string;
75
- /** 背景蓝色 */
76
- bgBlue: string;
77
- /** 背景品红 */
78
- bgMagenta: string;
79
- /** 背景青色 */
80
- bgCyan: string;
81
- /** 背景白色 */
82
- bgWhite: string;
83
- };
84
8
  declare const map: {
85
9
  info: {
86
10
  color: string;
@@ -106,5 +30,12 @@ declare const map: {
106
30
  declare function print(msg: any, type?: keyof typeof map): void;
107
31
 
108
32
  declare const timestamp: () => number;
33
+ declare const isArray: (arg: any) => arg is any[];
34
+ declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
35
+ declare function cleanString(str: string, regexp: RegExp): string;
36
+ /**
37
+ * @description min <= result < max
38
+ */
39
+ declare function random(max: number, min?: number): number;
109
40
 
110
- export { type Arrayable, type ElementOf, type Fn, type NotNull, type NotNullable, type NotUndefined, type Nullable, colors, isArray, isBoolean, isDate, isFunction, isNull, isNumber, isObject, isRegExp, isString, isUndefined, notNull, notNullish, notUndefined, print, random, safe, singleOrNull, take, takeIf, timestamp, toArray };
41
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/dist/index.d.ts CHANGED
@@ -1,86 +1,10 @@
1
- type Nullable<T> = T | null | undefined;
2
- type NotNullable<T> = Exclude<T, null | undefined>;
3
- type NotNull<T> = Exclude<T, null>;
4
- type NotUndefined<T> = Exclude<T, undefined>;
5
- type Arrayable<T> = T | Array<T>;
6
- type ElementOf<T> = T extends Array<infer Element> ? Element : never;
7
- type Fn<R = void> = (...args: any[]) => R;
1
+ export * from '@antfu/utils';
8
2
 
9
3
  declare function singleOrNull<T>(arr: T[]): T | null;
10
- declare function toArray<T>(array?: T | Array<T>): Array<T>;
11
4
 
12
- declare function take<T, R = void>(value: T, fn: (it: T) => R): R;
13
- declare function takeIf<T>(value: T, predicate: (it: T) => boolean): T | null;
14
- declare function takeIf<T>(value: T, predicate: (it: T) => boolean, defaultValue: T): T;
5
+ declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
15
6
  declare function safe<R>(fn: () => R): R | undefined;
16
7
 
17
- declare const isFunction: (val: any) => val is Fn;
18
- declare const isBoolean: (val: any) => val is boolean;
19
- declare const isNumber: (val: any) => val is number;
20
- declare const isString: (val: unknown) => val is string;
21
- declare const isObject: (val: any) => val is object;
22
- declare const isUndefined: (val: any) => val is undefined;
23
- declare const isNull: (val: any) => val is null;
24
- declare const isRegExp: (val: any) => val is RegExp;
25
- declare const isDate: (val: any) => val is Date;
26
- declare const isArray: (arg: any) => arg is any[];
27
- declare const notNullish: <T>(v: T | null | undefined) => v is NonNullable<T>;
28
- declare const notNull: <T>(v: T | null) => v is Exclude<T, null>;
29
- declare const notUndefined: <T>(v: T | undefined) => v is Exclude<T, undefined>;
30
-
31
- /**
32
- * @description min <= result < max
33
- */
34
- declare function random(max: number, min?: number): number;
35
-
36
- declare const colors: {
37
- /** 重置颜色 */
38
- reset: string;
39
- /** 亮色(加粗) */
40
- bright: string;
41
- /** 斜体 */
42
- italic: string;
43
- /** 下划线 */
44
- underline: string;
45
- /** 反向 */
46
- reverse: string;
47
- /** 隐藏 */
48
- hidden: string;
49
- /** 灰色 */
50
- grey: string;
51
- /** 黑色 */
52
- black: string;
53
- /** 红色 */
54
- red: string;
55
- /** 绿色 */
56
- green: string;
57
- /** 黄色 */
58
- yellow: string;
59
- /** 蓝色 */
60
- blue: string;
61
- /** 品红 */
62
- magenta: string;
63
- /** 青色 */
64
- cyan: string;
65
- /** 白色 */
66
- white: string;
67
- /** 背景黑色 */
68
- bgBlack: string;
69
- /** 背景红色 */
70
- bgRed: string;
71
- /** 背景绿色 */
72
- bgGreen: string;
73
- /** 背景黄色 */
74
- bgYellow: string;
75
- /** 背景蓝色 */
76
- bgBlue: string;
77
- /** 背景品红 */
78
- bgMagenta: string;
79
- /** 背景青色 */
80
- bgCyan: string;
81
- /** 背景白色 */
82
- bgWhite: string;
83
- };
84
8
  declare const map: {
85
9
  info: {
86
10
  color: string;
@@ -106,5 +30,12 @@ declare const map: {
106
30
  declare function print(msg: any, type?: keyof typeof map): void;
107
31
 
108
32
  declare const timestamp: () => number;
33
+ declare const isArray: (arg: any) => arg is any[];
34
+ declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
35
+ declare function cleanString(str: string, regexp: RegExp): string;
36
+ /**
37
+ * @description min <= result < max
38
+ */
39
+ declare function random(max: number, min?: number): number;
109
40
 
110
- export { type Arrayable, type ElementOf, type Fn, type NotNull, type NotNullable, type NotUndefined, type Nullable, colors, isArray, isBoolean, isDate, isFunction, isNull, isNumber, isObject, isRegExp, isString, isUndefined, notNull, notNullish, notUndefined, print, random, safe, singleOrNull, take, takeIf, timestamp, toArray };
41
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/dist/index.mjs CHANGED
@@ -1,32 +1,12 @@
1
- const isFunction = (val) => typeof val === "function";
2
- const isBoolean = (val) => typeof val === "boolean";
3
- const isNumber = (val) => typeof val === "number";
4
- const isString = (val) => typeof val === "string";
5
- const toString = (value) => Object.prototype.toString.call(value);
6
- const isObject = (val) => toString(val) === "[object Object]";
7
- const isUndefined = (val) => toString(val) === "[object Undefined]";
8
- const isNull = (val) => toString(val) === "[object Null]";
9
- const isRegExp = (val) => toString(val) === "[object RegExp]";
10
- const isDate = (val) => toString(val) === "[object Date]";
11
- const isArray = Array.isArray;
12
- const notNullish = (v) => v != null;
13
- const notNull = (v) => v !== null;
14
- const notUndefined = (v) => v !== void 0;
1
+ export * from '@antfu/utils';
15
2
 
16
3
  function singleOrNull(arr) {
17
4
  return arr.length === 1 ? arr[0] : null;
18
5
  }
19
- function toArray(array) {
20
- array = array ?? [];
21
- return isArray(array) ? array : [array];
22
- }
23
6
 
24
- function take(value, fn) {
7
+ function transform(value, fn) {
25
8
  return fn(value);
26
9
  }
27
- function takeIf(value, predicate, defaultValue) {
28
- return predicate(value) ? value : notUndefined(defaultValue) ? defaultValue : null;
29
- }
30
10
  function safe(fn) {
31
11
  try {
32
12
  return fn();
@@ -34,10 +14,6 @@ function safe(fn) {
34
14
  }
35
15
  }
36
16
 
37
- function random(max, min = 0) {
38
- return Math.floor(Math.random() * max) + min;
39
- }
40
-
41
17
  const colors = {
42
18
  /** 重置颜色 */
43
19
  reset: "\x1B[0m",
@@ -100,5 +76,15 @@ function print(msg, type) {
100
76
  }
101
77
 
102
78
  const timestamp = () => +Date.now();
79
+ const isArray = Array.isArray;
80
+ function getValueOrUndefined(condition, value) {
81
+ return condition ? value : void 0;
82
+ }
83
+ function cleanString(str, regexp) {
84
+ return str.replace(regexp, "");
85
+ }
86
+ function random(max, min = 0) {
87
+ return Math.floor(Math.random() * max) + min;
88
+ }
103
89
 
104
- export { colors, isArray, isBoolean, isDate, isFunction, isNull, isNumber, isObject, isRegExp, isString, isUndefined, notNull, notNullish, notUndefined, print, random, safe, singleOrNull, take, takeIf, timestamp, toArray };
90
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jiakun-zhao/utils",
3
3
  "type": "module",
4
- "version": "1.1.2",
4
+ "version": "1.2.1",
5
5
  "description": "Utils.",
6
6
  "author": "Jiakun Zhao <hi@zhaojiakun.com>",
7
7
  "license": "MIT",
@@ -18,36 +18,25 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "import": "./dist/index.mjs",
20
20
  "require": "./dist/index.cjs"
21
- },
22
- "./fs": {
23
- "types": "./dist/fs.d.ts",
24
- "import": "./dist/fs.mjs",
25
- "require": "./dist/fs.cjs"
26
21
  }
27
22
  },
28
23
  "main": "./dist/index.cjs",
29
24
  "module": "./dist/index.mjs",
30
25
  "types": "./dist/index.d.ts",
31
26
  "files": [
32
- "dist",
33
- "index.d.ts",
34
- "fs.d.ts"
27
+ "dist"
35
28
  ],
36
29
  "dependencies": {
37
- "fast-glob": "^3.3.2"
30
+ "@antfu/utils": "^0.7.8"
38
31
  },
39
32
  "devDependencies": {
40
- "@jiakun-zhao/eslint-config": "^1.3.1",
41
- "@types/node": "^20.10.0",
42
- "bumpp": "^9.2.0",
43
- "eslint": "^8.54.0",
44
- "esno": "^4.0.0",
45
- "typescript": "^5.3.2",
33
+ "@antfu/eslint-config": "^2.19.0",
34
+ "@types/node": "^20.12.12",
35
+ "bumpp": "^9.4.1",
36
+ "eslint": "^9.3.0",
37
+ "typescript": "^5.4.5",
46
38
  "unbuild": "^2.0.0",
47
- "vitest": "^0.34.6"
48
- },
49
- "eslintConfig": {
50
- "extends": "@jiakun-zhao"
39
+ "vitest": "^1.6.0"
51
40
  },
52
41
  "scripts": {
53
42
  "build": "unbuild",
package/dist/fs.cjs DELETED
@@ -1,45 +0,0 @@
1
- 'use strict';
2
-
3
- const node_crypto = require('node:crypto');
4
- const node_fs = require('node:fs');
5
- const promises = require('node:fs/promises');
6
- const node_path = require('node:path');
7
- const fastGlob = require('fast-glob');
8
-
9
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
-
11
- const fastGlob__default = /*#__PURE__*/_interopDefaultCompat(fastGlob);
12
-
13
- async function exists(...path) {
14
- return await promises.access(node_path.join(...path), promises.constants.F_OK).then(() => true, () => false);
15
- }
16
- async function readText(...path) {
17
- return await promises.readFile(node_path.join(...path), "utf-8");
18
- }
19
- async function readJson(...path) {
20
- return JSON.parse(await readText(...path));
21
- }
22
- async function writeText(content, ...path) {
23
- await promises.writeFile(node_path.join(...path), content, "utf-8");
24
- }
25
- async function writeJson(content, ...path) {
26
- await writeText(`${JSON.stringify(content, null, 2)}
27
- `, ...path);
28
- }
29
- async function toMD5(...path) {
30
- const hash = node_crypto.createHash("md5");
31
- const stream = node_fs.createReadStream(node_path.join(...path));
32
- return new Promise((resolve, reject) => {
33
- stream.on("data", (chunk) => hash.update(chunk));
34
- stream.on("end", () => resolve(hash.digest("base64url")));
35
- stream.on("error", reject);
36
- });
37
- }
38
-
39
- exports.glob = fastGlob__default;
40
- exports.exists = exists;
41
- exports.readJson = readJson;
42
- exports.readText = readText;
43
- exports.toMD5 = toMD5;
44
- exports.writeJson = writeJson;
45
- exports.writeText = writeText;
package/dist/fs.d.cts DELETED
@@ -1,10 +0,0 @@
1
- export { default as glob } from 'fast-glob';
2
-
3
- declare function exists(...path: string[]): Promise<boolean>;
4
- declare function readText(...path: string[]): Promise<string>;
5
- declare function readJson<T>(...path: string[]): Promise<T>;
6
- declare function writeText(content: string, ...path: string[]): Promise<void>;
7
- declare function writeJson(content: object, ...path: string[]): Promise<void>;
8
- declare function toMD5(...path: string[]): Promise<string>;
9
-
10
- export { exists, readJson, readText, toMD5, writeJson, writeText };
package/dist/fs.d.mts DELETED
@@ -1,10 +0,0 @@
1
- export { default as glob } from 'fast-glob';
2
-
3
- declare function exists(...path: string[]): Promise<boolean>;
4
- declare function readText(...path: string[]): Promise<string>;
5
- declare function readJson<T>(...path: string[]): Promise<T>;
6
- declare function writeText(content: string, ...path: string[]): Promise<void>;
7
- declare function writeJson(content: object, ...path: string[]): Promise<void>;
8
- declare function toMD5(...path: string[]): Promise<string>;
9
-
10
- export { exists, readJson, readText, toMD5, writeJson, writeText };
package/dist/fs.d.ts DELETED
@@ -1,10 +0,0 @@
1
- export { default as glob } from 'fast-glob';
2
-
3
- declare function exists(...path: string[]): Promise<boolean>;
4
- declare function readText(...path: string[]): Promise<string>;
5
- declare function readJson<T>(...path: string[]): Promise<T>;
6
- declare function writeText(content: string, ...path: string[]): Promise<void>;
7
- declare function writeJson(content: object, ...path: string[]): Promise<void>;
8
- declare function toMD5(...path: string[]): Promise<string>;
9
-
10
- export { exists, readJson, readText, toMD5, writeJson, writeText };
package/dist/fs.mjs DELETED
@@ -1,33 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { createReadStream } from 'node:fs';
3
- import { access, constants, readFile, writeFile } from 'node:fs/promises';
4
- import { join } from 'node:path';
5
- export { default as glob } from 'fast-glob';
6
-
7
- async function exists(...path) {
8
- return await access(join(...path), constants.F_OK).then(() => true, () => false);
9
- }
10
- async function readText(...path) {
11
- return await readFile(join(...path), "utf-8");
12
- }
13
- async function readJson(...path) {
14
- return JSON.parse(await readText(...path));
15
- }
16
- async function writeText(content, ...path) {
17
- await writeFile(join(...path), content, "utf-8");
18
- }
19
- async function writeJson(content, ...path) {
20
- await writeText(`${JSON.stringify(content, null, 2)}
21
- `, ...path);
22
- }
23
- async function toMD5(...path) {
24
- const hash = createHash("md5");
25
- const stream = createReadStream(join(...path));
26
- return new Promise((resolve, reject) => {
27
- stream.on("data", (chunk) => hash.update(chunk));
28
- stream.on("end", () => resolve(hash.digest("base64url")));
29
- stream.on("error", reject);
30
- });
31
- }
32
-
33
- export { exists, readJson, readText, toMD5, writeJson, writeText };
package/fs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './dist/fs'
2
- export { default } from './dist/fs'
package/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './dist/index'
2
- export { default } from './dist/index'