@bhsd/nodejs 0.1.1 → 1.0.0

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/dist/index.d.ts CHANGED
@@ -1,6 +1,31 @@
1
+ /**
2
+ * 进行性能分析,生成prof.json和prof-summary.json文件
3
+ * @param callback 要分析的函数
4
+ * @param dir 输出文件夹路径
5
+ */
1
6
  export declare const profile: (callback: () => void | Promise<void>, dir: string) => Promise<void>;
2
7
  /**
3
8
  * 刷新屏幕输出
4
9
  * @param str 要输出的字符串
5
10
  */
6
11
  export declare const refreshStdout: (str: string) => void;
12
+ /**
13
+ * 将字符串以绿色显示
14
+ * @param str 要显示的字符串
15
+ */
16
+ export declare const green: (str: string) => string;
17
+ /**
18
+ * 将字符串以黄色显示
19
+ * @param str 要显示的字符串
20
+ */
21
+ export declare const yellow: (str: string) => string;
22
+ /**
23
+ * 将字符串以红色显示
24
+ * @param str 要显示的字符串
25
+ */
26
+ export declare const red: (str: string) => string;
27
+ /**
28
+ * 将字符串以蓝色显示
29
+ * @param str 要显示的字符串
30
+ */
31
+ export declare const blue: (str: string) => string;
package/dist/index.js CHANGED
@@ -1,12 +1,7 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.refreshStdout = exports.profile = void 0;
7
- const fs_1 = __importDefault(require("fs"));
8
- const path_1 = __importDefault(require("path"));
9
- const promises_1 = require("inspector/promises");
1
+ import * as fs from 'fs';
2
+ import * as path from 'path';
3
+ import { Session } from 'inspector/promises';
4
+ import { styleText } from 'util';
10
5
  /**
11
6
  * Adds the ticks to the myTicks object.
12
7
  * @param myTicks ticks记录对象
@@ -19,8 +14,13 @@ const addTicks = (myTicks, positionTicks) => {
19
14
  }
20
15
  }
21
16
  };
22
- const profile = async (callback, dir) => {
23
- const session = new promises_1.Session();
17
+ /**
18
+ * 进行性能分析,生成prof.json和prof-summary.json文件
19
+ * @param callback 要分析的函数
20
+ * @param dir 输出文件夹路径
21
+ */
22
+ export const profile = async (callback, dir) => {
23
+ const session = new Session();
24
24
  session.connect();
25
25
  await session.post('Profiler.enable');
26
26
  await session.post('Profiler.start');
@@ -42,18 +42,36 @@ const profile = async (callback, dir) => {
42
42
  summary.push({ callFrame, hitCount, positionTicks: myTicks });
43
43
  }
44
44
  }
45
- fs_1.default.writeFileSync(path_1.default.join(dir, 'prof.json'), `${JSON.stringify(useful, null, '\t')}\n`);
46
- fs_1.default.writeFileSync(path_1.default.join(dir, 'prof-summary.json'), `${JSON.stringify(summary, null, '\t')}\n`);
45
+ fs.writeFileSync(path.join(dir, 'prof.json'), `${JSON.stringify(useful, null, '\t')}\n`);
46
+ fs.writeFileSync(path.join(dir, 'prof-summary.json'), `${JSON.stringify(summary, null, '\t')}\n`);
47
47
  session.disconnect();
48
48
  };
49
- exports.profile = profile;
50
49
  /**
51
50
  * 刷新屏幕输出
52
51
  * @param str 要输出的字符串
53
52
  */
54
- const refreshStdout = (str) => {
53
+ export const refreshStdout = (str) => {
55
54
  process.stdout.moveCursor(-process.stdout.columns, 0);
56
55
  process.stdout.clearLine(0);
57
56
  process.stdout.write(`\x1B[?7l${str}\x1B[?7h\r`);
58
57
  };
59
- exports.refreshStdout = refreshStdout;
58
+ /**
59
+ * 将字符串以绿色显示
60
+ * @param str 要显示的字符串
61
+ */
62
+ export const green = (str) => styleText('green', str);
63
+ /**
64
+ * 将字符串以黄色显示
65
+ * @param str 要显示的字符串
66
+ */
67
+ export const yellow = (str) => styleText('yellow', str);
68
+ /**
69
+ * 将字符串以红色显示
70
+ * @param str 要显示的字符串
71
+ */
72
+ export const red = (str) => styleText('red', str);
73
+ /**
74
+ * 将字符串以蓝色显示
75
+ * @param str 要显示的字符串
76
+ */
77
+ export const blue = (str) => styleText('blue', str);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bhsd/nodejs",
3
- "version": "0.1.1",
3
+ "version": "1.0.0",
4
4
  "homepage": "https://github.com/bhsd-harry/nodejs#readme",
5
5
  "bugs": {
6
6
  "url": "https://github.com/bhsd-harry/nodejs/issues"
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "main": "./dist/index.js",
14
14
  "types": "./dist/index.d.ts",
15
+ "type": "module",
15
16
  "scripts": {
16
17
  "prepublishOnly": "npm run build",
17
18
  "build": "tsc",
@@ -19,22 +20,22 @@
19
20
  "lint": "npm run lint:ts"
20
21
  },
21
22
  "devDependencies": {
22
- "@bhsd/code-standard": "^2.1.0",
23
- "@stylistic/eslint-plugin": "^5.9.0",
23
+ "@bhsd/code-standard": "^2.1.1",
24
+ "@stylistic/eslint-plugin": "^5.10.0",
24
25
  "@types/node": "^24.11.0",
25
- "@typescript-eslint/eslint-plugin": "^8.54.0",
26
- "@typescript-eslint/parser": "^8.54.0",
27
- "eslint": "^9.39.3",
26
+ "@typescript-eslint/eslint-plugin": "^8.57.0",
27
+ "@typescript-eslint/parser": "^8.57.0",
28
+ "eslint": "^9.39.4",
28
29
  "eslint-plugin-eslint-comments": "^3.2.0",
29
30
  "eslint-plugin-jsdoc": "^62.7.1",
30
31
  "eslint-plugin-jsonc": "^3.1.1",
31
32
  "eslint-plugin-n": "^17.24.0",
32
33
  "eslint-plugin-promise": "^7.2.1",
33
- "eslint-plugin-regexp": "^3.0.0",
34
+ "eslint-plugin-regexp": "^3.1.0",
34
35
  "eslint-plugin-unicorn": "^63.0.0",
35
36
  "typescript": "^5.9.3"
36
37
  },
37
38
  "engines": {
38
- "node": ">=20.19.0"
39
+ "node": "^20.19.0 || ^22.13.0 || >=24.11.0"
39
40
  }
40
41
  }