privacy-brush 1.0.2 → 1.1.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/README.md +20 -33
- package/package.json +1 -1
- package/src/index.mjs +60 -2
- package/src/index.test.mjs +234 -161
- package/src/lib/config.mjs +2 -0
- package/src/type.ts +1 -0
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
[](https://opensource.org/licenses/MIT)
|
|
10
10
|
[](https://github.com/legend80s/privacy-brush/actions/workflows/typecheck.yml)
|
|
11
11
|
|
|
12
|
-
<p align="center">
|
|
12
|
+
<!-- <p align="center">
|
|
13
13
|
<img src="https://raw.githubusercontent.com/legend80s/privacy-brush/main/docs/demo.gif" alt="PrivacyBrush Demo" width="800">
|
|
14
|
-
</p>
|
|
14
|
+
</p> -->
|
|
15
15
|
|
|
16
16
|
## ✨ Features
|
|
17
17
|
|
|
@@ -204,39 +204,26 @@ PrivacyBrush includes 20+ pre-configured sensitive information patterns:
|
|
|
204
204
|
### Stream Processing for Large Files
|
|
205
205
|
|
|
206
206
|
```javascript
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const inputStream = fs.createReadStream('huge.log');
|
|
211
|
-
const maskStream = createMaskStream();
|
|
212
|
-
|
|
213
|
-
inputStream
|
|
214
|
-
.pipe(maskStream)
|
|
215
|
-
.pipe(fs.createWriteStream('masked-huge.log'))
|
|
216
|
-
.on('finish', () => {
|
|
217
|
-
console.log('Large file processing completed!');
|
|
218
|
-
});
|
|
219
|
-
```
|
|
207
|
+
import { createReadStream, createWriteStream } from "node:fs"
|
|
208
|
+
import { pipeline } from "node:stream/promises"
|
|
220
209
|
|
|
221
|
-
|
|
210
|
+
import { PrivacyBrush } from "privacy-brush"
|
|
222
211
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
next();
|
|
239
|
-
});
|
|
212
|
+
const brush = new PrivacyBrush()
|
|
213
|
+
|
|
214
|
+
const inputStream = createReadStream("./test/fixtures/huge.log")
|
|
215
|
+
const maskStream = await brush.createMaskStream()
|
|
216
|
+
|
|
217
|
+
const dist = `./test/fixtures/masked-huge-${Date.now()}.generated.log`
|
|
218
|
+
|
|
219
|
+
// biome-ignore format: one stream per line
|
|
220
|
+
await pipeline(
|
|
221
|
+
inputStream,
|
|
222
|
+
maskStream,
|
|
223
|
+
createWriteStream(dist)
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
console.log("✅ Large file processing completed!", dist)
|
|
240
227
|
```
|
|
241
228
|
|
|
242
229
|
### Git Hook Integration
|
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -73,7 +73,7 @@ export class PrivacyBrush {
|
|
|
73
73
|
{
|
|
74
74
|
/** @type {IPatternName} */
|
|
75
75
|
name: "user_name_in_path",
|
|
76
|
-
regex: /\/Users\/([
|
|
76
|
+
regex: /\/Users\/([^/]+)\//g,
|
|
77
77
|
/**
|
|
78
78
|
* Handle user name in file path masking.
|
|
79
79
|
* @param {string} match
|
|
@@ -84,6 +84,32 @@ export class PrivacyBrush {
|
|
|
84
84
|
return match.replace(userName, this.maskChar.repeat(userName.length))
|
|
85
85
|
},
|
|
86
86
|
},
|
|
87
|
+
|
|
88
|
+
// uuid
|
|
89
|
+
{
|
|
90
|
+
name: "uuid",
|
|
91
|
+
regex:
|
|
92
|
+
/\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-5][0-9a-fA-F]{3}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g,
|
|
93
|
+
/**
|
|
94
|
+
* Handle UUID masking.
|
|
95
|
+
* @param {string} match
|
|
96
|
+
* @returns {string}
|
|
97
|
+
*/
|
|
98
|
+
replacer: match => {
|
|
99
|
+
return this.maskUUID(match)
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// mac address (CA:FE:BA:BE:12:34 or CA-FE-BA-BE-12-34)
|
|
104
|
+
{
|
|
105
|
+
name: "mac_address",
|
|
106
|
+
// match six hex pairs separated by ':' or '-'
|
|
107
|
+
regex:
|
|
108
|
+
/\b(?:[0-9A-Fa-f]{2}([:-]))(?:[0-9A-Fa-f]{2}\1){4}[0-9A-Fa-f]{2}\b/g,
|
|
109
|
+
replacer: match => {
|
|
110
|
+
return match.replace(/[0-9A-Fa-f]{2}/g, () => this.maskChar.repeat(2))
|
|
111
|
+
},
|
|
112
|
+
},
|
|
87
113
|
]
|
|
88
114
|
|
|
89
115
|
return allPatterns
|
|
@@ -240,13 +266,45 @@ export class PrivacyBrush {
|
|
|
240
266
|
}
|
|
241
267
|
}
|
|
242
268
|
|
|
269
|
+
/**
|
|
270
|
+
* mask uuid by version
|
|
271
|
+
* - version 4: 6ba7b810-xxxx-4xxx-xxxx-xxxxxxxxxxxx
|
|
272
|
+
* - other versions: xxxxxxxx-xxxx-vxxx-xxxx-xxxxxxxxxxxx (v is 1-5)
|
|
273
|
+
* @param {string} uuid
|
|
274
|
+
* @returns
|
|
275
|
+
*/
|
|
276
|
+
maskUUID(uuid) {
|
|
277
|
+
return uuid.replace(
|
|
278
|
+
/\b([0-9a-fA-F]{8})-([0-9a-fA-F]{4})-([1-5])([0-9a-fA-F]{3})-([0-9a-fA-F]{4})-([0-9a-fA-F]{12})\b/g,
|
|
279
|
+
(match, p1, p2, p3, p4, p5, p6) => {
|
|
280
|
+
/** @type {(target: string) => string} */
|
|
281
|
+
const mask = target => this.maskChar.repeat(target.length)
|
|
282
|
+
|
|
283
|
+
const maskedP2 = mask(p2)
|
|
284
|
+
const maskedP4 = mask(p4)
|
|
285
|
+
const maskedP5 = mask(p5)
|
|
286
|
+
const maskedP6 = mask(p6)
|
|
287
|
+
|
|
288
|
+
if (p3 === "4") {
|
|
289
|
+
return `${p1}-${maskedP2}-4${maskedP4}-${maskedP5}-${maskedP6}`
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const maskedP1 = mask(p1)
|
|
293
|
+
|
|
294
|
+
return `${maskedP1}-${maskedP2}-${p3}${maskedP4}-${maskedP5}-${maskedP6}`
|
|
295
|
+
},
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
|
|
243
299
|
// 实时流处理
|
|
244
300
|
async createMaskStream() {
|
|
245
301
|
const { Transform } = await import("node:stream")
|
|
302
|
+
// let count = 0
|
|
246
303
|
|
|
247
304
|
return new Transform({
|
|
248
305
|
transform: (chunk, encoding, callback) => {
|
|
249
|
-
const text =
|
|
306
|
+
const text = chunk.toString("utf8")
|
|
307
|
+
// console.log(`chunk${++count}:`, { chunk, text })
|
|
250
308
|
|
|
251
309
|
const masked = this.maskText(text)
|
|
252
310
|
callback(null, masked)
|
package/src/index.test.mjs
CHANGED
|
@@ -1,161 +1,234 @@
|
|
|
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
|
|
141
|
-
// 使用示例
|
|
142
|
-
const masker = new PrivacyBrush()
|
|
143
|
-
|
|
144
|
-
// 处理终端输出
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
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 username in path", () => {
|
|
141
|
+
// 使用示例
|
|
142
|
+
const masker = new PrivacyBrush()
|
|
143
|
+
|
|
144
|
+
// 处理终端输出
|
|
145
|
+
const input = `/c/Users/legend80s/AppData/ /Users/test/code/`
|
|
146
|
+
|
|
147
|
+
const safeOutput = masker.maskText(input)
|
|
148
|
+
|
|
149
|
+
// console.log("safeOutput3:", safeOutput)
|
|
150
|
+
|
|
151
|
+
const expectedOutput = `/c/Users/█████████/AppData/ /Users/████/code/`
|
|
152
|
+
|
|
153
|
+
assert.strictEqual(safeOutput, expectedOutput)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
test("mask IP", () => {
|
|
157
|
+
// 使用示例
|
|
158
|
+
const masker = new PrivacyBrush()
|
|
159
|
+
|
|
160
|
+
// 处理终端输出
|
|
161
|
+
const terminalOutput = `Windows [Version 10.0.12345.1234]
|
|
162
|
+
Chrome 144.0.1234.12
|
|
163
|
+
User IP: 10.12.123.12`
|
|
164
|
+
|
|
165
|
+
const safeOutput = masker.maskText(terminalOutput)
|
|
166
|
+
|
|
167
|
+
// console.log("safeOutput3:", safeOutput)
|
|
168
|
+
|
|
169
|
+
const expectedOutput = `Windows [Version 10.█.█████.████]
|
|
170
|
+
Chrome 144.█.████.██
|
|
171
|
+
User IP: 10.██.███.██`
|
|
172
|
+
|
|
173
|
+
assert.strictEqual(safeOutput, expectedOutput)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
test("mask uuid", () => {
|
|
177
|
+
// 使用示例
|
|
178
|
+
const masker = new PrivacyBrush()
|
|
179
|
+
|
|
180
|
+
// 处理终端输出
|
|
181
|
+
const terminalOutput = `
|
|
182
|
+
UUID v1: 11111111-1111-1111-8111-111111111111
|
|
183
|
+
UUID v2: 22222222-2222-2222-8222-222222222222
|
|
184
|
+
UUID v3: 33333333-3333-3333-8333-333333333333
|
|
185
|
+
UUID v4: 44444444-4444-4444-8444-444444444444
|
|
186
|
+
UUID v5: 55555555-5555-5555-8555-555555555555
|
|
187
|
+
`
|
|
188
|
+
|
|
189
|
+
const safeOutput = masker.maskText(terminalOutput)
|
|
190
|
+
|
|
191
|
+
// console.log("safeOutput3:", safeOutput)
|
|
192
|
+
|
|
193
|
+
const expectedOutput = `
|
|
194
|
+
UUID v1: ████████-████-1███-████-████████████
|
|
195
|
+
UUID v2: ████████-████-2███-████-████████████
|
|
196
|
+
UUID v3: ████████-████-3███-████-████████████
|
|
197
|
+
UUID v4: 44444444-████-4███-████-████████████
|
|
198
|
+
UUID v5: ████████-████-5███-████-████████████
|
|
199
|
+
`
|
|
200
|
+
|
|
201
|
+
assert.strictEqual(safeOutput, expectedOutput)
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
test("mask mac address", () => {
|
|
205
|
+
// 使用示例
|
|
206
|
+
const masker = new PrivacyBrush()
|
|
207
|
+
|
|
208
|
+
// 处理终端输出
|
|
209
|
+
const input = `
|
|
210
|
+
CA:FE:BA:BE:12:34 # "Cafe Babe"
|
|
211
|
+
DE:AD:BE:EF:CA:FE # "Dead Beef Cafe"
|
|
212
|
+
BA:DC:0F:FE:E0:0D # "Bad Coffee Feed"
|
|
213
|
+
|
|
214
|
+
CA-FE-BA-BE-12-34 # "Cafe Babe"
|
|
215
|
+
DE-AD-BE-EF-CA-FE # "Dead Beef Cafe"
|
|
216
|
+
BA-DC-0F-FE-E0-0D # "Bad Coffee Feed"
|
|
217
|
+
`
|
|
218
|
+
|
|
219
|
+
const safeOutput = masker.maskText(input)
|
|
220
|
+
|
|
221
|
+
// console.log("safeOutput3:", safeOutput)
|
|
222
|
+
|
|
223
|
+
const expectedOutput = `
|
|
224
|
+
██:██:██:██:██:██ # "Cafe Babe"
|
|
225
|
+
██:██:██:██:██:██ # "Dead Beef Cafe"
|
|
226
|
+
██:██:██:██:██:██ # "Bad Coffee Feed"
|
|
227
|
+
|
|
228
|
+
██-██-██-██-██-██ # "Cafe Babe"
|
|
229
|
+
██-██-██-██-██-██ # "Dead Beef Cafe"
|
|
230
|
+
██-██-██-██-██-██ # "Bad Coffee Feed"
|
|
231
|
+
`
|
|
232
|
+
|
|
233
|
+
assert.strictEqual(safeOutput, expectedOutput)
|
|
234
|
+
})
|
package/src/lib/config.mjs
CHANGED