privacy-brush 0.0.3

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.
@@ -0,0 +1,161 @@
1
+ import { strict as assert } from "node:assert"
2
+ import { test } from "node:test"
3
+ import { PrivacyBrush } from "./index.mjs"
4
+
5
+ const WINDOWS_VERSION_SAMPLE = "10.0.12345.6785"
6
+ const GOOGLE_BROWSER_VERSION_SAMPLE = "144.0.1234.56"
7
+ const EDGE_BROWSER_VERSION_SAMPLE = "144.0.3421.12"
8
+
9
+ test("default configurations", () => {
10
+ // 使用示例
11
+ const masker = new PrivacyBrush()
12
+
13
+ // 处理终端输出
14
+ const terminalOutput = `❯ flutter devices
15
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
16
+ Found 4 connected devices:
17
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
18
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 ${WINDOWS_VERSION_SAMPLE}]
19
+ Chrome (web) • chrome • web-javascript • Google Chrome ${GOOGLE_BROWSER_VERSION_SAMPLE}
20
+ Edge (web) • edge • web-javascript • Microsoft Edge ${EDGE_BROWSER_VERSION_SAMPLE}
21
+
22
+ Run "flutter emulators" to list and start any available device emulators.
23
+
24
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
25
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
26
+ troubleshooting tips.
27
+ `
28
+
29
+ const safeOutput = masker.maskText(terminalOutput)
30
+
31
+ // console.log("safeOutput:", safeOutput)
32
+
33
+ const expectedOutput = `❯ flutter devices
34
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
35
+ Found 4 connected devices:
36
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
37
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 10.█.█████.████]
38
+ Chrome (web) • chrome • web-javascript • Google Chrome 144.█.████.██
39
+ Edge (web) • edge • web-javascript • Microsoft Edge 144.█.████.██
40
+
41
+ Run "flutter emulators" to list and start any available device emulators.
42
+
43
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
44
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
45
+ troubleshooting tips.
46
+ `
47
+
48
+ assert.strictEqual(safeOutput, expectedOutput)
49
+ })
50
+
51
+ test("use custom maskChar and not preserveFirstPart", () => {
52
+ // 使用示例
53
+ const masker = new PrivacyBrush({
54
+ maskChar: "░",
55
+ preserveFirstPart: false,
56
+ })
57
+
58
+ // 处理终端输出
59
+ const terminalOutput = `❯ flutter devices
60
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
61
+ Found 4 connected devices:
62
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
63
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 ${WINDOWS_VERSION_SAMPLE}]
64
+ Chrome (web) • chrome • web-javascript • Google Chrome ${GOOGLE_BROWSER_VERSION_SAMPLE}
65
+ Edge (web) • edge • web-javascript • Microsoft Edge ${EDGE_BROWSER_VERSION_SAMPLE}
66
+
67
+ Run "flutter emulators" to list and start any available device emulators.
68
+
69
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
70
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
71
+ troubleshooting tips.
72
+ `
73
+
74
+ const safeOutput = masker.maskText(terminalOutput)
75
+
76
+ // console.log("safeOutput2:", safeOutput)
77
+
78
+ const expectedOutput = `❯ flutter devices
79
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
80
+ Found 4 connected devices:
81
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
82
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 ░░.░.░░░░░.░░░░]
83
+ Chrome (web) • chrome • web-javascript • Google Chrome ░░░.░.░░░░.░░
84
+ Edge (web) • edge • web-javascript • Microsoft Edge ░░░.░.░░░░.░░
85
+
86
+ Run "flutter emulators" to list and start any available device emulators.
87
+
88
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
89
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
90
+ troubleshooting tips.
91
+ `
92
+
93
+ assert.strictEqual(safeOutput, expectedOutput)
94
+ })
95
+
96
+ test("only mask browser_version", () => {
97
+ // 使用示例
98
+ const masker = new PrivacyBrush({
99
+ maskPatternNames: ["browser_version"],
100
+ })
101
+
102
+ // 处理终端输出
103
+ const terminalOutput = `❯ flutter devices
104
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
105
+ Found 4 connected devices:
106
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
107
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 ${WINDOWS_VERSION_SAMPLE}]
108
+ Chrome (web) • chrome • web-javascript • Google Chrome ${GOOGLE_BROWSER_VERSION_SAMPLE}
109
+ Edge (web) • edge • web-javascript • Microsoft Edge ${EDGE_BROWSER_VERSION_SAMPLE}
110
+
111
+ Run "flutter emulators" to list and start any available device emulators.
112
+
113
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
114
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
115
+ troubleshooting tips.
116
+ `
117
+
118
+ const safeOutput = masker.maskText(terminalOutput)
119
+
120
+ // console.log("safeOutput3:", safeOutput)
121
+
122
+ const expectedOutput = `❯ flutter devices
123
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
124
+ Found 4 connected devices:
125
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
126
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 ${WINDOWS_VERSION_SAMPLE}]
127
+ Chrome (web) • chrome • web-javascript • Google Chrome 144.█.████.██
128
+ Edge (web) • edge • web-javascript • Microsoft Edge 144.█.████.██
129
+
130
+ Run "flutter emulators" to list and start any available device emulators.
131
+
132
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
133
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
134
+ troubleshooting tips.
135
+ `
136
+
137
+ assert.strictEqual(safeOutput, expectedOutput)
138
+ })
139
+
140
+ test("mask IP", () => {
141
+ // 使用示例
142
+ const masker = new PrivacyBrush()
143
+
144
+ // 处理终端输出
145
+ const terminalOutput = `Windows [Version 10.0.12345.1234]
146
+ Chrome 144.0.1234.12
147
+ User IP: 10.12.123.12`
148
+
149
+ const safeOutput = masker.maskText(terminalOutput)
150
+
151
+ // console.log("safeOutput3:", safeOutput)
152
+
153
+ const expectedOutput = `Windows [Version 10.█.█████.████]
154
+ Chrome 144.█.████.██
155
+ User IP: 10.██.███.██`
156
+
157
+ assert.strictEqual(safeOutput, expectedOutput)
158
+ })
159
+
160
+ // // 处理日志文件
161
+ // masker.maskFile('terminal_log.txt', 'masked_log.txt');
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @type {Required<import('../type.js').IConfig>}
3
+ */
4
+ export const defaultConfig = {
5
+ maskChar: "█",
6
+ preserveFirstPart: true, // 是否保留版本号的第一部分
7
+ maskPatternNames: ["windows_version", "browser_version", "ip_address"],
8
+ }
package/src/type.ts ADDED
@@ -0,0 +1,17 @@
1
+ export type IConfig = {
2
+ maskChar?: string
3
+ preserveFirstPart?: boolean
4
+ maskPatternNames?: IPatternName[]
5
+ }
6
+
7
+ export type IPatternName =
8
+ | "windows_version"
9
+ | "browser_version"
10
+ | "android_version"
11
+ | "ip_address"
12
+
13
+ export type IPattern = {
14
+ name: IPatternName
15
+ regex: RegExp
16
+ replacer: (substring: string, ...args: any[]) => string
17
+ }
@@ -0,0 +1,13 @@
1
+ ❯ flutter devices
2
+ Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
3
+ Found 4 connected devices:
4
+ sdk gphone64 x86 64 (mobile) • emulator-5554 • android-x64 • Android 16 (API 36) (emulator)
5
+ Windows (desktop) • windows • windows-x64 • Microsoft Windows [版本 10.0.12345.6456]
6
+ Chrome (web) • chrome • web-javascript • Google Chrome 144.0.1234.60
7
+ Edge (web) • edge • web-javascript • Microsoft Edge 144.0.1234.82
8
+
9
+ Run "flutter emulators" to list and start any available device emulators.
10
+
11
+ If you expected another device to be detected, please run "flutter doctor" to diagnose potential issues. You may also try
12
+ increasing the time to wait for connected devices with the "--device-timeout" flag. Visit https://flutter.dev/setup/ for
13
+ troubleshooting tips.
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "lib": ["ESNext"],
5
+ "module": "nodenext",
6
+ "target": "es2017",
7
+ "checkJs": true
8
+ },
9
+ "include": ["src"]
10
+ }