@anonymask/core 0.4.5 → 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/README.md +51 -5
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ console.log(original);
|
|
|
57
57
|
| Type | Description | Examples |
|
|
58
58
|
| ------------- | ----------------------- | --------------------------------------------------- |
|
|
59
59
|
| `email` | Email addresses | `user@domain.com`, `john.doe@company.co.uk` |
|
|
60
|
-
| `phone` | Phone numbers | `555-123-4567`, `(555) 123-4567`, `555.123.4567`
|
|
60
|
+
| `phone` | Phone numbers | `555-123-4567`, `555-123`, `(555) 123-4567`, `555.123.4567` |
|
|
61
61
|
| `ssn` | Social Security Numbers | `123-45-6789`, `123456789` |
|
|
62
62
|
| `credit_card` | Credit card numbers | `1234-5678-9012-3456`, `1234567890123456` |
|
|
63
63
|
| `ip_address` | IP addresses | `192.168.1.1`, `2001:0db8:85a3::8a2e:0370:7334` |
|
|
@@ -77,7 +77,7 @@ const anonymizer = new Anonymizer(entityTypes: string[])
|
|
|
77
77
|
|
|
78
78
|
#### `anonymize(text: string) => AnonymizationResult`
|
|
79
79
|
|
|
80
|
-
Anonymizes the input text and returns detailed result.
|
|
80
|
+
Anonymizes the input text using automatic detection and returns detailed result.
|
|
81
81
|
|
|
82
82
|
**Returns:**
|
|
83
83
|
|
|
@@ -96,6 +96,24 @@ interface Entity {
|
|
|
96
96
|
}
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
+
#### `anonymizeWithCustom(text: string, customEntities?: Record<string, string[]>) => AnonymizationResult`
|
|
100
|
+
|
|
101
|
+
Anonymizes the input text using both automatic detection and custom entities.
|
|
102
|
+
|
|
103
|
+
**Parameters:**
|
|
104
|
+
- `text`: The input text to anonymize
|
|
105
|
+
- `customEntities`: Optional map of entity types to arrays of custom values to anonymize
|
|
106
|
+
|
|
107
|
+
**Example:**
|
|
108
|
+
```javascript
|
|
109
|
+
const customEntities = {
|
|
110
|
+
email: ["secret@company.com", "admin@internal.org"],
|
|
111
|
+
phone: ["555-999-0000"]
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const result = anonymizer.anonymizeWithCustom(text, customEntities);
|
|
115
|
+
```
|
|
116
|
+
|
|
99
117
|
#### `deanonymize(text: string, mapping: Record<string, string>) => string`
|
|
100
118
|
|
|
101
119
|
Restores original text using the provided mapping.
|
|
@@ -139,9 +157,11 @@ class SecureLLMClient {
|
|
|
139
157
|
this.anonymizer = new Anonymizer(["email", "phone", "ssn", "credit_card"]);
|
|
140
158
|
}
|
|
141
159
|
|
|
142
|
-
async processMessage(userMessage) {
|
|
143
|
-
// Anonymize user input
|
|
144
|
-
const result =
|
|
160
|
+
async processMessage(userMessage, customEntities = null) {
|
|
161
|
+
// Anonymize user input with optional custom entities
|
|
162
|
+
const result = customEntities
|
|
163
|
+
? this.anonymizer.anonymizeWithCustom(userMessage, customEntities)
|
|
164
|
+
: this.anonymizer.anonymize(userMessage);
|
|
145
165
|
|
|
146
166
|
// Send anonymized message to LLM
|
|
147
167
|
const llmResponse = await this.callLLM(result.anonymized_text);
|
|
@@ -157,6 +177,32 @@ class SecureLLMClient {
|
|
|
157
177
|
}
|
|
158
178
|
```
|
|
159
179
|
|
|
180
|
+
### Custom Entity Anonymization
|
|
181
|
+
|
|
182
|
+
```javascript
|
|
183
|
+
const { Anonymizer } = require("@anonymask/core");
|
|
184
|
+
|
|
185
|
+
// Initialize with basic detection
|
|
186
|
+
const anonymizer = new Anonymizer(["email"]);
|
|
187
|
+
|
|
188
|
+
// Define custom entities to anonymize
|
|
189
|
+
const customEntities = {
|
|
190
|
+
email: ["internal@company.com", "admin@secure.org"],
|
|
191
|
+
phone: ["555-999-0000", "555-888-1111"],
|
|
192
|
+
// You can even specify entity types not in the initial list
|
|
193
|
+
ssn: ["123-45-6789"]
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const text = "Contact internal@company.com or call 555-999-0000";
|
|
197
|
+
const result = anonymizer.anonymizeWithCustom(text, customEntities);
|
|
198
|
+
|
|
199
|
+
console.log(result.anonymizedText);
|
|
200
|
+
// "Contact EMAIL_xxx or call PHONE_xxx"
|
|
201
|
+
|
|
202
|
+
console.log(result.mapping);
|
|
203
|
+
// { EMAIL_xxx: 'internal@company.com', PHONE_xxx: '555-999-0000' }
|
|
204
|
+
```
|
|
205
|
+
|
|
160
206
|
### Batch Processing
|
|
161
207
|
|
|
162
208
|
```javascript
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anonymask/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Secure anonymization/de-anonymization library for PII data",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -68,10 +68,10 @@
|
|
|
68
68
|
"typescript": "^5.9.2"
|
|
69
69
|
},
|
|
70
70
|
"optionalDependencies": {
|
|
71
|
-
"@anonymask/core-win32-x64-msvc": "0.
|
|
72
|
-
"@anonymask/core-darwin-x64": "0.
|
|
73
|
-
"@anonymask/core-linux-x64-gnu": "0.
|
|
74
|
-
"@anonymask/core-linux-arm64-gnu": "0.
|
|
75
|
-
"@anonymask/core-darwin-arm64": "0.
|
|
71
|
+
"@anonymask/core-win32-x64-msvc": "1.0.0",
|
|
72
|
+
"@anonymask/core-darwin-x64": "1.0.0",
|
|
73
|
+
"@anonymask/core-linux-x64-gnu": "1.0.0",
|
|
74
|
+
"@anonymask/core-linux-arm64-gnu": "1.0.0",
|
|
75
|
+
"@anonymask/core-darwin-arm64": "1.0.0"
|
|
76
76
|
}
|
|
77
77
|
}
|