@edgenets/utils 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. package/dist/index.d.ts +2 -2
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +3 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/types/logger.d.ts +2 -0
  6. package/dist/types/logger.d.ts.map +1 -1
  7. package/dist/utils/generate.util.d.ts +7 -0
  8. package/dist/utils/generate.util.d.ts.map +1 -0
  9. package/dist/utils/generate.util.js +30 -0
  10. package/dist/utils/generate.util.js.map +1 -0
  11. package/dist/utils/generate.utils.d.ts +7 -0
  12. package/dist/utils/generate.utils.d.ts.map +1 -0
  13. package/dist/utils/generate.utils.js +30 -0
  14. package/dist/utils/generate.utils.js.map +1 -0
  15. package/dist/utils/logger.util.d.ts +8 -0
  16. package/dist/utils/logger.util.d.ts.map +1 -0
  17. package/dist/utils/logger.util.js +15 -0
  18. package/dist/utils/logger.util.js.map +1 -0
  19. package/dist/utils/scheduler.util.d.ts +19 -0
  20. package/dist/utils/scheduler.util.d.ts.map +1 -0
  21. package/dist/utils/scheduler.util.js +82 -0
  22. package/dist/utils/scheduler.util.js.map +1 -0
  23. package/dist/utils/string.util.d.ts +6 -0
  24. package/dist/utils/string.util.d.ts.map +1 -0
  25. package/dist/utils/string.util.js +16 -0
  26. package/dist/utils/string.util.js.map +1 -0
  27. package/dist/utils/string.utils.d.ts +6 -0
  28. package/dist/utils/string.utils.d.ts.map +1 -0
  29. package/dist/utils/string.utils.js +16 -0
  30. package/dist/utils/string.utils.js.map +1 -0
  31. package/package.json +8 -2
  32. package/dist/string/capitalize.d.ts +0 -2
  33. package/dist/string/capitalize.d.ts.map +0 -1
  34. package/dist/string/capitalize.js +0 -6
  35. package/dist/string/capitalize.js.map +0 -1
  36. package/dist/string/trim.d.ts +0 -2
  37. package/dist/string/trim.d.ts.map +0 -1
  38. package/dist/string/trim.js +0 -4
  39. package/dist/string/trim.js.map +0 -1
  40. package/eslint.config.js +0 -16
  41. package/tsconfig.json +0 -16
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export * from "./types/user.js";
2
2
  export * from "./types/product.js";
3
3
  export * from "./types/logger.js";
4
4
  export * from "./types/order.js";
5
- export * from "./string/capitalize.js";
6
- export * from "./string/trim.js";
5
+ export { StringUtils } from "./utils/string.util.js";
6
+ export * from "./utils/generate.util.js";
7
7
  export * from "./array/unique.js";
8
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,cAAc,0BAA0B,CAAC;AAGzC,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -4,8 +4,9 @@ export * from "./types/product.js";
4
4
  export * from "./types/logger.js";
5
5
  export * from "./types/order.js";
6
6
  // 导出字符串处理函数
7
- export * from "./string/capitalize.js";
8
- export * from "./string/trim.js";
7
+ export { StringUtils } from "./utils/string.util.js";
8
+ // 导出字符串处理函数
9
+ export * from "./utils/generate.util.js";
9
10
  // 导出数组处理函数
10
11
  export * from "./array/unique.js";
11
12
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,YAAY;AACZ,cAAc,wBAAwB,CAAC;AACvC,cAAc,kBAAkB,CAAC;AAEjC,WAAW;AACX,cAAc,mBAAmB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,SAAS;AACT,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AAEjC,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,YAAY;AACZ,cAAc,0BAA0B,CAAC;AAEzC,WAAW;AACX,cAAc,mBAAmB,CAAC"}
@@ -1,5 +1,7 @@
1
1
  export interface Logger {
2
+ debug(message: string): void;
2
3
  info(message: string): void;
4
+ warn(message: string): void;
3
5
  error(message: string): void;
4
6
  }
5
7
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/types/logger.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAE9B"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/types/logger.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,MAAM;IACrB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAE9B"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 生成一个随机且安全的 orderNumber
3
+ * @param length - orderNumber 的位数
4
+ * @returns 生成的随机数字字符串
5
+ */
6
+ export declare function generateOrderNumber(orderSequence?: number): number;
7
+ //# sourceMappingURL=generate.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.util.d.ts","sourceRoot":"","sources":["../../src/utils/generate.util.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,GAAE,MAAU,GAAG,MAAM,CAqBrE"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 生成一个随机且安全的 orderNumber
3
+ * @param length - orderNumber 的位数
4
+ * @returns 生成的随机数字字符串
5
+ */
6
+ export function generateOrderNumber(orderSequence = 0) {
7
+ const now = new Date();
8
+ // 获取年份的后两位
9
+ const year = now.getFullYear().toString().slice(-2);
10
+ // 获取今年第几天
11
+ const start = new Date(now.getFullYear(), 0, 0);
12
+ const diff = now.getTime() - start.getTime();
13
+ const dayOfYear = Math.floor(diff / (1000 * 60 * 60 * 24))
14
+ .toString()
15
+ .padStart(3, "0");
16
+ // 序列号递增,并重置为三位
17
+ if (orderSequence === 0)
18
+ orderSequence = generateRandomNumber(3);
19
+ orderSequence = (orderSequence + 1) % 1000;
20
+ const sequence = orderSequence.toString().padStart(3, "0");
21
+ // 生成 8 位的随机数,保证不重复
22
+ const randomPart = Math.random().toString().slice(2, 10); // 生成8位随机数字
23
+ return Number(`${year}${dayOfYear}${sequence}${randomPart}`);
24
+ }
25
+ function generateRandomNumber(length) {
26
+ const min = Math.pow(10, length - 1); // 最小值,例如:6位数的最小值为100000
27
+ const max = Math.pow(10, length) - 1; // 最大值,例如:6位数的最大值为999999
28
+ return Math.floor(Math.random() * (max - min + 1)) + min;
29
+ }
30
+ //# sourceMappingURL=generate.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.util.js","sourceRoot":"","sources":["../../src/utils/generate.util.ts"],"names":[],"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AAG,CAAC,CAAC,CAAC,CAAC,wBAAwB;IAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,wBAAwB;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 生成一个随机且安全的 orderNumber
3
+ * @param length - orderNumber 的位数
4
+ * @returns 生成的随机数字字符串
5
+ */
6
+ export declare function generateOrderNumber(orderSequence?: number): number;
7
+ //# sourceMappingURL=generate.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.utils.d.ts","sourceRoot":"","sources":["../../src/utils/generate.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,GAAE,MAAU,GAAG,MAAM,CAqBrE"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * 生成一个随机且安全的 orderNumber
3
+ * @param length - orderNumber 的位数
4
+ * @returns 生成的随机数字字符串
5
+ */
6
+ export function generateOrderNumber(orderSequence = 0) {
7
+ const now = new Date();
8
+ // 获取年份的后两位
9
+ const year = now.getFullYear().toString().slice(-2);
10
+ // 获取今年第几天
11
+ const start = new Date(now.getFullYear(), 0, 0);
12
+ const diff = now.getTime() - start.getTime();
13
+ const dayOfYear = Math.floor(diff / (1000 * 60 * 60 * 24))
14
+ .toString()
15
+ .padStart(3, "0");
16
+ // 序列号递增,并重置为三位
17
+ if (orderSequence === 0)
18
+ orderSequence = generateRandomNumber(3);
19
+ orderSequence = (orderSequence + 1) % 1000;
20
+ const sequence = orderSequence.toString().padStart(3, "0");
21
+ // 生成 8 位的随机数,保证不重复
22
+ const randomPart = Math.random().toString().slice(2, 10); // 生成8位随机数字
23
+ return Number(`${year}${dayOfYear}${sequence}${randomPart}`);
24
+ }
25
+ function generateRandomNumber(length) {
26
+ const min = Math.pow(10, length - 1); // 最小值,例如:6位数的最小值为100000
27
+ const max = Math.pow(10, length) - 1; // 最大值,例如:6位数的最大值为999999
28
+ return Math.floor(Math.random() * (max - min + 1)) + min;
29
+ }
30
+ //# sourceMappingURL=generate.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.utils.js","sourceRoot":"","sources":["../../src/utils/generate.utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,gBAAwB,CAAC;IAC3D,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,WAAW;IACX,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAEpD,UAAU;IACV,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;IAC7C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;SACvD,QAAQ,EAAE;SACV,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAEpB,eAAe;IACf,IAAI,aAAa,KAAK,CAAC;QAAE,aAAa,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC;IACjE,aAAa,GAAG,CAAC,aAAa,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IAC3C,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAE3D,mBAAmB;IACnB,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW;IAErE,OAAO,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAc;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,wBAAwB;IAC9D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,wBAAwB;IAC9D,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Logger } from "../types/logger.js";
2
+ export declare class ConsoleLogger implements Logger {
3
+ debug(message: string): void;
4
+ warn(message: string): void;
5
+ info(message: string): void;
6
+ error(message: string): void;
7
+ }
8
+ //# sourceMappingURL=logger.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.util.d.ts","sourceRoot":"","sources":["../../src/utils/logger.util.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBAAa,aAAc,YAAW,MAAM;IAC1C,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAG5B,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAG3B,IAAI,CAAC,OAAO,EAAE,MAAM;IAGpB,KAAK,CAAC,OAAO,EAAE,MAAM;CAGtB"}
@@ -0,0 +1,15 @@
1
+ export class ConsoleLogger {
2
+ debug(message) {
3
+ console.debug(`[DEBUG] ${message}`);
4
+ }
5
+ warn(message) {
6
+ console.warn(`[WARN] ${message}`);
7
+ }
8
+ info(message) {
9
+ console.log(`[INFO] ${message}`);
10
+ }
11
+ error(message) {
12
+ console.error(`[ERROR] ${message}`);
13
+ }
14
+ }
15
+ //# sourceMappingURL=logger.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.util.js","sourceRoot":"","sources":["../../src/utils/logger.util.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,aAAa;IACxB,KAAK,CAAC,OAAe;QACnB,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,CAAC,OAAe;QAClB,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;IACpC,CAAC;IACD,IAAI,CAAC,OAAe;QAClB,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;IACnC,CAAC;IACD,KAAK,CAAC,OAAe;QACnB,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ type Task = () => Promise<boolean>;
2
+ export interface SchedulerOptions {
3
+ interval?: number;
4
+ taskTimeout?: number;
5
+ logInterval?: number;
6
+ maxRecursions: number;
7
+ maxRetries?: number;
8
+ maxTotalTime?: number;
9
+ }
10
+ export declare class Scheduler {
11
+ private tasks;
12
+ schedule(task: Task, options: SchedulerOptions): void;
13
+ private handleTaskError;
14
+ private timeout;
15
+ private delay;
16
+ cancelAll(): void;
17
+ }
18
+ export {};
19
+ //# sourceMappingURL=scheduler.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.util.d.ts","sourceRoot":"","sources":["../../src/utils/scheduler.util.ts"],"names":[],"mappings":"AAAA,KAAK,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AAEnC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,SAAS;IACpB,OAAO,CAAC,KAAK,CAA2D;IAEjE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,GAAG,IAAI;YA0D9C,eAAe;IAmB7B,OAAO,CAAC,OAAO;IAMf,OAAO,CAAC,KAAK;IAIN,SAAS,IAAI,IAAI;CAMzB"}
@@ -0,0 +1,82 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export class Scheduler {
11
+ constructor() {
12
+ this.tasks = new Map();
13
+ }
14
+ schedule(task, options) {
15
+ const { interval = 1000, // 默认 1000 毫秒
16
+ maxRecursions = 0, // 默认 不 迭代
17
+ maxRetries = 0, // 默认 不 重试
18
+ logInterval = 1, // 默认 完整输出 Log
19
+ taskTimeout = 30000, // 默认 单次执行时间30秒
20
+ maxTotalTime = 60000, // 默认 最大执行时间60秒
21
+ } = options || {};
22
+ let counter = 0;
23
+ let retries = 0;
24
+ const startTime = Date.now();
25
+ const executeTask = () => __awaiter(this, void 0, void 0, function* () {
26
+ try {
27
+ if (maxTotalTime && Date.now() - startTime > maxTotalTime) {
28
+ console.log("达到总的最大执行时间,停止任务。");
29
+ this.cancelAll();
30
+ return;
31
+ }
32
+ const shouldContinue = yield Promise.race([
33
+ task(),
34
+ this.timeout(taskTimeout),
35
+ ]);
36
+ counter++;
37
+ if (shouldContinue && counter < maxRecursions) {
38
+ if (counter % logInterval === 0) {
39
+ console.log(`递归执行, 第 ${counter} 次, 已执行 ${(Date.now() - startTime) / 1000} 秒`);
40
+ }
41
+ this.tasks.set(setTimeout(() => __awaiter(this, void 0, void 0, function* () {
42
+ yield executeTask();
43
+ }), interval), setTimeout(() => { }, interval));
44
+ }
45
+ else {
46
+ this.cancelAll();
47
+ }
48
+ }
49
+ catch (error) {
50
+ yield this.handleTaskError(error, retries, maxRetries, executeTask, interval);
51
+ retries++;
52
+ }
53
+ });
54
+ executeTask();
55
+ }
56
+ handleTaskError(error, retries, maxRetries, retryTask, interval) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (retries < maxRetries) {
59
+ console.error(`Retry attempt ${retries + 1} due to error: ${error}`);
60
+ yield this.delay(interval * (retries + 1)); // 指数退避
61
+ yield retryTask(); // 重新执行任务
62
+ }
63
+ else {
64
+ console.error("Max retries reached. Task execution stopped due to persistent errors.");
65
+ this.cancelAll();
66
+ }
67
+ });
68
+ }
69
+ timeout(ms) {
70
+ return new Promise((_, reject) => setTimeout(() => reject("Task timed out"), ms));
71
+ }
72
+ delay(ms) {
73
+ return new Promise((resolve) => setTimeout(resolve, ms));
74
+ }
75
+ cancelAll() {
76
+ this.tasks.forEach((_, taskId) => {
77
+ clearTimeout(taskId);
78
+ });
79
+ this.tasks.clear();
80
+ }
81
+ }
82
+ //# sourceMappingURL=scheduler.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.util.js","sourceRoot":"","sources":["../../src/utils/scheduler.util.ts"],"names":[],"mappings":";;;;;;;;;AAWA,MAAM,OAAO,SAAS;IAAtB;QACU,UAAK,GAAiD,IAAI,GAAG,EAAE,CAAC;IA+F1E,CAAC;IA7FQ,QAAQ,CAAC,IAAU,EAAE,OAAyB;QACn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,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;YAC/B,YAAY,CAAC,MAAM,CAAC,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export declare class StringUtils {
2
+ static capitalize(str: string): string;
3
+ static trim(str: string): string;
4
+ static toNumber(value: string): number | null;
5
+ }
6
+ //# sourceMappingURL=string.util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.util.d.ts","sourceRoot":"","sources":["../../src/utils/string.util.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IAEtB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAKtC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAKhC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAI9C"}
@@ -0,0 +1,16 @@
1
+ export class StringUtils {
2
+ // 首字母大写
3
+ static capitalize(str) {
4
+ return str.charAt(0).toUpperCase() + str.slice(1);
5
+ }
6
+ // 去除空白字符
7
+ static trim(str) {
8
+ return str.trim();
9
+ }
10
+ // 将字符串转换为数字
11
+ static toNumber(value) {
12
+ const num = Number(value);
13
+ return isNaN(num) ? null : num;
14
+ }
15
+ }
16
+ //# sourceMappingURL=string.util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.util.js","sourceRoot":"","sources":["../../src/utils/string.util.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IACtB,QAAQ;IACR,MAAM,CAAC,UAAU,CAAC,GAAW;QAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,SAAS;IACT,MAAM,CAAC,IAAI,CAAC,GAAW;QACrB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;IAED,YAAY;IACZ,MAAM,CAAC,QAAQ,CAAC,KAAa;QAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export declare class StringUtils {
2
+ static capitalize(str: string): string;
3
+ static trim(str: string): string;
4
+ static toNumber(value: string): number | null;
5
+ }
6
+ //# sourceMappingURL=string.utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.utils.d.ts","sourceRoot":"","sources":["../../src/utils/string.utils.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IAEtB,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAKtC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAKhC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;CAI9C"}
@@ -0,0 +1,16 @@
1
+ export class StringUtils {
2
+ // 首字母大写
3
+ static capitalize(str) {
4
+ return str.charAt(0).toUpperCase() + str.slice(1);
5
+ }
6
+ // 去除空白字符
7
+ static trim(str) {
8
+ return str.trim();
9
+ }
10
+ // 将字符串转换为数字
11
+ static toNumber(value) {
12
+ const num = Number(value);
13
+ return isNaN(num) ? null : num;
14
+ }
15
+ }
16
+ //# sourceMappingURL=string.utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.utils.js","sourceRoot":"","sources":["../../src/utils/string.utils.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IACtB,QAAQ;IACR,MAAM,CAAC,UAAU,CAAC,GAAW;QAC3B,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,SAAS;IACT,MAAM,CAAC,IAAI,CAAC,GAAW;QACrB,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;IACpB,CAAC;IAED,YAAY;IACZ,MAAM,CAAC,QAAQ,CAAC,KAAa;QAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;IACjC,CAAC;CACF"}
package/package.json CHANGED
@@ -1,14 +1,20 @@
1
1
  {
2
2
  "name": "@edgenets/utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "Edgenets utilities package containing common types and utilities.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "author": "Edgenets",
9
9
  "license": "MIT",
10
+ "files": [
11
+ "dist/",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
10
15
  "scripts": {
11
16
  "build": "eslint --fix && tsc -p tsconfig.json",
12
- "test": "tsx node_modules/tap/dist/esm/run.mjs 'test/**/*.spec.ts' || true"
17
+ "test": "echo 'Skip Tests'",
18
+ "publish": "pnpm build && npm version patch && npm publish --access public"
13
19
  }
14
20
  }
@@ -1,2 +0,0 @@
1
- export declare function capitalize(str: string): string;
2
- //# sourceMappingURL=capitalize.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../../src/string/capitalize.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C"}
@@ -1,6 +0,0 @@
1
- export function capitalize(str) {
2
- if (!str)
3
- return "";
4
- return str.charAt(0).toUpperCase() + str.slice(1);
5
- }
6
- //# sourceMappingURL=capitalize.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"capitalize.js","sourceRoot":"","sources":["../../src/string/capitalize.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,UAAU,CAAC,GAAW;IACpC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC"}
@@ -1,2 +0,0 @@
1
- export declare function trim(str: string): string;
2
- //# sourceMappingURL=trim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trim.d.ts","sourceRoot":"","sources":["../../src/string/trim.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAExC"}
@@ -1,4 +0,0 @@
1
- export function trim(str) {
2
- return str.trim();
3
- }
4
- //# sourceMappingURL=trim.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trim.js","sourceRoot":"","sources":["../../src/string/trim.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,IAAI,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC;AACpB,CAAC"}
package/eslint.config.js DELETED
@@ -1,16 +0,0 @@
1
- import eslint from "@eslint/js";
2
- import tseslint from "typescript-eslint";
3
- import prettierConfig from "eslint-config-prettier";
4
-
5
- export default tseslint.config({
6
- files: ["src/**/*.ts"],
7
- extends: [
8
- eslint.configs.recommended,
9
- ...tseslint.configs.recommended,
10
- prettierConfig,
11
- ],
12
- rules: {
13
- "@typescript-eslint/array-type": "error",
14
- "@typescript-eslint/consistent-type-imports": "error",
15
- },
16
- });
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES6",
4
- "module": "NodeNext",
5
- "moduleResolution": "nodenext",
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "sourceMap": true,
9
- "declaration": true,
10
- "declarationMap": true,
11
- "strict": true
12
- },
13
- "compileOnSave": true,
14
- "include": ["src/**/*"],
15
- "exclude": ["node_modules", "dist"]
16
- }