maskdata 1.2.0 → 1.2.2
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/MASKDATA_FOR_TYPESCRIPT.md +112 -0
- package/README.md +15 -2
- package/index.d.ts +73 -0
- package/lib/helpers/MaskHelper.js +24 -0
- package/package.json +9 -6
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
## Mask data for Typescript
|
|
2
|
+
The type definitions are bundled with the package. So, no need to install additional dependency. The type definitions are present here: https://github.com/Sumukha1496/maskdata/blob/master/index.d.ts
|
|
3
|
+
|
|
4
|
+
Only difference in using this package is with the import statements.
|
|
5
|
+
|
|
6
|
+
### Example: Mask password functionality
|
|
7
|
+
|
|
8
|
+
```javascript
|
|
9
|
+
import { maskPassword, PasswordMaskOptions } from 'maskdata';
|
|
10
|
+
|
|
11
|
+
const password: string = 'myPassword123';
|
|
12
|
+
const options: PasswordMaskOptions = {
|
|
13
|
+
maskWith: '*',
|
|
14
|
+
maxMaskedCharacters: 10,
|
|
15
|
+
unmaskedStartCharacters: 2,
|
|
16
|
+
unmaskedEndCharacters: 2
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const maskedPassword = maskPassword(password, options);
|
|
20
|
+
console.log(maskedPassword);
|
|
21
|
+
```
|
|
22
|
+
<br/>
|
|
23
|
+
|
|
24
|
+
## Available mask configs/option
|
|
25
|
+
### 1. PasswordMaskOptions
|
|
26
|
+
Used in [Password Masking](#mask-password)
|
|
27
|
+
```javascript
|
|
28
|
+
{
|
|
29
|
+
maskWith?: string;
|
|
30
|
+
maxMaskedCharacters?: number;
|
|
31
|
+
unmaskedStartCharacters?: number;
|
|
32
|
+
unmaskedEndCharacters?: number;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 2. CardMaskOptions
|
|
37
|
+
Used in [Card masking](./README.md#mask-card-number)
|
|
38
|
+
```javascript
|
|
39
|
+
{
|
|
40
|
+
maskWith?: string;
|
|
41
|
+
unmaskedStartDigits?: number;
|
|
42
|
+
unmaskedEndDigits?: number;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 3. EmailMask2Options
|
|
47
|
+
Used in [Email masking](./README.md#mask-email-id)
|
|
48
|
+
```javascript
|
|
49
|
+
{
|
|
50
|
+
maskWith?: string;
|
|
51
|
+
unmaskedStartCharactersBeforeAt?: number;
|
|
52
|
+
unmaskedEndCharactersAfterAt?: number;
|
|
53
|
+
maskAtTheRate?: boolean;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 4. PhoneMaskOptions
|
|
58
|
+
Used in [Phone Number Masking](#mask-phone-number)
|
|
59
|
+
```javascript
|
|
60
|
+
{
|
|
61
|
+
maskWith?: string;
|
|
62
|
+
unmaskedStartDigits?: number;
|
|
63
|
+
unmaskedEndDigits?: number;
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
### 5. StringMaskOptions
|
|
67
|
+
Used in [String masking](./README.md#mask-the-characters-or-words-in-the-string)
|
|
68
|
+
```javascript
|
|
69
|
+
{
|
|
70
|
+
maskWith?: string;
|
|
71
|
+
maskOnlyFirstOccurance?: boolean;
|
|
72
|
+
values?: string[];
|
|
73
|
+
maskAll?: boolean;
|
|
74
|
+
maskSpace?: boolean;
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 6. UuidMaskOptions
|
|
79
|
+
Used in [UUID Masking](#mask-uuid)
|
|
80
|
+
```javascript
|
|
81
|
+
{
|
|
82
|
+
maskWith?: string;
|
|
83
|
+
unmaskedStartCharacters?: number;
|
|
84
|
+
unmaskedEndCharacters?: number;
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 7. JsonMask2Configs
|
|
89
|
+
Used in [JSON fields masking](#mask-json)
|
|
90
|
+
```javascript
|
|
91
|
+
{
|
|
92
|
+
cardMaskOptions?: CardMaskOptions;
|
|
93
|
+
cardFields?: string[];
|
|
94
|
+
emailMaskOptions?: EmailMask2Options;
|
|
95
|
+
emailFields?: string[];
|
|
96
|
+
passwordMaskOptions?: PasswordMaskOptions;
|
|
97
|
+
passwordFields?: string[];
|
|
98
|
+
phoneMaskOptions?: PhoneMaskOptions;
|
|
99
|
+
phoneFields?: string[];
|
|
100
|
+
stringMaskOptions?: StringMaskOptions;
|
|
101
|
+
stringFields?: string[];
|
|
102
|
+
uuidMaskOptions?: UuidMaskOptions;
|
|
103
|
+
uuidFields?: string[];
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
<br/>
|
|
108
|
+
|
|
109
|
+
## Available functions to import along with their configs
|
|
110
|
+
```javascript
|
|
111
|
+
import { maskPassword, PasswordMaskOptions, maskJSON2, JsonMask2Configs, maskPhone, PhoneMaskOptions, maskEmail2, EmailMask2Options, maskCard, CardMaskOptions, maskString, StringMaskOptions, maskUuid, UuidMaskOptions, getInnerProperty, replaceValue } from 'maskdata';
|
|
112
|
+
```
|
package/README.md
CHANGED
|
@@ -4,8 +4,9 @@ maskdata is a Node.js module to mask various kinds of data. With the help of mas
|
|
|
4
4
|
# Table of Contents
|
|
5
5
|
- [Features](#features)
|
|
6
6
|
- [Install maskdata](#install-maskdata)
|
|
7
|
-
- [Version 1.2.
|
|
7
|
+
- [Version 1.2.2 Features](#release-features)
|
|
8
8
|
- [How to Use](#how-to-use)
|
|
9
|
+
- [Maskdata for Typescript](#maskdata-for-typescript)
|
|
9
10
|
- [Mask Card number](#mask-card-number)
|
|
10
11
|
- [Mask Email](#mask-email-id)
|
|
11
12
|
- [Mask Email id with the default configuration](#mask-email-id-with-the-default-configuration)
|
|
@@ -35,11 +36,15 @@ maskdata is a Node.js module to mask various kinds of data. With the help of mas
|
|
|
35
36
|
* Mask JSON - JSON can contain cards, emails, passwords, phones, strings, and UUIDs. Mask all of them with a single call using - [Mask JSON fields](#mask-json)
|
|
36
37
|
* Get nested field from JSON
|
|
37
38
|
* Set/Replace nested field values from JSON
|
|
39
|
+
* [Maskdata for typescript](#maskdata-for-typescript)
|
|
38
40
|
|
|
39
41
|
# Install maskdata
|
|
40
42
|
> npm i maskdata
|
|
41
43
|
|
|
42
44
|
# Release Features
|
|
45
|
+
### Version 1.2.2
|
|
46
|
+
- Type definitions for the typescript developers. Yay!!!
|
|
47
|
+
But there is a small change in how you import and use the library. Follow this to know how you can import and use the masking functions in a typescript project: [Mask data for Typescript](#maskdata-for-typescript)
|
|
43
48
|
### Version 1.2.0
|
|
44
49
|
- Support for masking cards, emails, passwords, phones, strings, and UUIDs. Mask all of them with a single call using - [Mask JSON fields](#mask-json)
|
|
45
50
|
- Support for masking UUID - [Mask UUID](#mask-uuid)
|
|
@@ -61,6 +66,14 @@ https://github.com/Sumukha1496/maskdata/pull/23
|
|
|
61
66
|
const MaskData = require('./maskdata');
|
|
62
67
|
```
|
|
63
68
|
|
|
69
|
+
<br/>
|
|
70
|
+
|
|
71
|
+
## Maskdata for Typescript
|
|
72
|
+
> Follow this document for more details:
|
|
73
|
+
[Maskdata for typescript](./MASKDATA_FOR_TYPESCRIPT.md)
|
|
74
|
+
|
|
75
|
+
<br/>
|
|
76
|
+
|
|
64
77
|
## Mask card number
|
|
65
78
|
This will mask the digits in a card number.<br/>This will mask only the numerical data and not any non-numeric delimiters, alphabets, or any other types of data
|
|
66
79
|
```javascript
|
|
@@ -698,7 +711,7 @@ Type of married: boolean
|
|
|
698
711
|
|
|
699
712
|
```
|
|
700
713
|
|
|
701
|
-
## Mask fields in a JSON
|
|
714
|
+
## Mask fields in a JSON
|
|
702
715
|
<b> NOTE: This is an old functionality. For more flexibility and single masking call to mask different types of data in the json object, start using the new maskJson2() function - [Mask JSON fields](#mask-json)</b>
|
|
703
716
|
|
|
704
717
|
This method masks the field value if present in the given object.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
declare module 'maskdata' {
|
|
2
|
+
export interface CardMaskOptions {
|
|
3
|
+
maskWith?: string;
|
|
4
|
+
unmaskedStartDigits?: number;
|
|
5
|
+
unmaskedEndDigits?: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface EmailMask2Options {
|
|
9
|
+
maskWith?: string;
|
|
10
|
+
unmaskedStartCharactersBeforeAt?: number;
|
|
11
|
+
unmaskedEndCharactersAfterAt?: number;
|
|
12
|
+
maskAtTheRate?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface JsonMaskOptions {
|
|
16
|
+
maskWith?: string;
|
|
17
|
+
fields?: string[];
|
|
18
|
+
maxMaskedCharactersStr?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PasswordMaskOptions {
|
|
22
|
+
maskWith?: string;
|
|
23
|
+
maxMaskedCharacters?: number;
|
|
24
|
+
unmaskedStartCharacters?: number;
|
|
25
|
+
unmaskedEndCharacters?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PhoneMaskOptions {
|
|
29
|
+
maskWith?: string;
|
|
30
|
+
unmaskedStartDigits?: number;
|
|
31
|
+
unmaskedEndDigits?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface StringMaskOptions {
|
|
35
|
+
maskWith?: string;
|
|
36
|
+
maskOnlyFirstOccurance?: boolean;
|
|
37
|
+
values?: string[];
|
|
38
|
+
maskAll?: boolean;
|
|
39
|
+
maskSpace?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UuidMaskOptions {
|
|
43
|
+
maskWith?: string;
|
|
44
|
+
unmaskedStartCharacters?: number;
|
|
45
|
+
unmaskedEndCharacters?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface JsonMask2Configs {
|
|
49
|
+
cardMaskOptions?: CardMaskOptions;
|
|
50
|
+
cardFields?: string[];
|
|
51
|
+
emailMaskOptions?: EmailMask2Options;
|
|
52
|
+
emailFields?: string[];
|
|
53
|
+
passwordMaskOptions?: PasswordMaskOptions;
|
|
54
|
+
passwordFields?: string[];
|
|
55
|
+
phoneMaskOptions?: PhoneMaskOptions;
|
|
56
|
+
phoneFields?: string[];
|
|
57
|
+
stringMaskOptions?: StringMaskOptions;
|
|
58
|
+
stringFields?: string[];
|
|
59
|
+
uuidMaskOptions?: UuidMaskOptions;
|
|
60
|
+
uuidFields?: string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function maskPassword(password?: string, options?: PasswordMaskOptions): string;
|
|
64
|
+
export function maskJSONFields<T extends object>(json?: T, options?: JsonMaskOptions): T;
|
|
65
|
+
export function maskJSON2<T extends object>(json?: T, options?: JsonMask2Configs): T;
|
|
66
|
+
export function maskPhone(phone?: string, options?: PhoneMaskOptions): string;
|
|
67
|
+
export function maskEmail2(email?: string, options?: EmailMask2Options): string;
|
|
68
|
+
export function maskCard(cardNumber?: string, options?: CardMaskOptions): string;
|
|
69
|
+
export function maskString(str?: string, options?: StringMaskOptions): string;
|
|
70
|
+
export function maskUuid(uuid?: string, options?: UuidMaskOptions): string;
|
|
71
|
+
export function getInnerProperty(object: object, field: string): any;
|
|
72
|
+
export function replaceValue(object: object, field: string, value: any): object;
|
|
73
|
+
}
|
|
@@ -245,6 +245,30 @@ class MaskHelper {
|
|
|
245
245
|
configs.cardMaskOptions = JSON.parse(JSON.stringify(Constants.defaultCardMaskOptions));
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
+
if(!configs.cardFields) {
|
|
249
|
+
configs.cardFields = [];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if(!configs.emailFields) {
|
|
253
|
+
configs.emailFields = [];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if(!configs.passwordFields) {
|
|
257
|
+
configs.passwordFields = [];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if(!configs.phoneFields) {
|
|
261
|
+
configs.phoneFields = [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if(!configs.stringFields) {
|
|
265
|
+
configs.stringFields = [];
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if(!configs.uuidFields) {
|
|
269
|
+
configs.uuidFields = [];
|
|
270
|
+
}
|
|
271
|
+
|
|
248
272
|
if(!configs.emailMaskOptions) {
|
|
249
273
|
configs.emailMaskOptions = JSON.parse(JSON.stringify(Constants.defaultEmailMask2Options));
|
|
250
274
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maskdata",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Node module to mask various kinds of data in the required formats",
|
|
5
5
|
"main": "index.js",
|
|
6
|
+
"typings": "index.d.ts",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "https://github.com/Sumukha1496/maskdata"
|
|
@@ -28,15 +29,17 @@
|
|
|
28
29
|
"Set json fields",
|
|
29
30
|
"Replcae json fields"
|
|
30
31
|
],
|
|
31
|
-
"author": "sumukha.
|
|
32
|
+
"author": "sumukha.hs<sumukha.hs369@gmail.com>",
|
|
33
|
+
"homepage": "https://github.com/Sumukha1496/maskdata#readme",
|
|
32
34
|
"license": "MIT",
|
|
33
35
|
"dependencies": {
|
|
34
36
|
"lodash": "^4.17.21"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
37
|
-
"chai": "^4.3.
|
|
38
|
-
"mocha": "^
|
|
39
|
-
"mocha-junit-reporter": "^2.0
|
|
40
|
-
"nyc": "^15.1.0"
|
|
39
|
+
"chai": "^4.3.7",
|
|
40
|
+
"mocha": "^10.2.0",
|
|
41
|
+
"mocha-junit-reporter": "^2.2.0",
|
|
42
|
+
"nyc": "^15.1.0",
|
|
43
|
+
"typescript": "^4.9.5"
|
|
41
44
|
}
|
|
42
45
|
}
|