maskdata 1.2.1 → 1.2.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.
package/.prettierrc.js ADDED
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ semi: true,
3
+ trailingComma: 'none',
4
+ singleQuote: true,
5
+ printWidth: 100,
6
+ tabWidth: 2
7
+ };
package/README.md CHANGED
@@ -4,7 +4,7 @@ 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.1 Features](#release-features)
7
+ - [Version 1.2.3 Features](#release-features)
8
8
  - [How to Use](#how-to-use)
9
9
  - [Maskdata for Typescript](#maskdata-for-typescript)
10
10
  - [Mask Card number](#mask-card-number)
@@ -12,6 +12,7 @@ maskdata is a Node.js module to mask various kinds of data. With the help of mas
12
12
  - [Mask Email id with the default configuration](#mask-email-id-with-the-default-configuration)
13
13
  - [Mask JSON fields](#mask-json)
14
14
  - [JSON mask examples with nested fields](#json-mask-examples)
15
+ - [Mask multiple fields at once using .* and [*].](#mask-multiple-fields)
15
16
  - [Mask Password](#mask-password)
16
17
  - [Mask Password with the default configuration](#mask-password-with-the-default-configuration)
17
18
  - [Mask Phone Number](#mask-phone-number)
@@ -20,8 +21,6 @@ maskdata is a Node.js module to mask various kinds of data. With the help of mas
20
21
  - [Mask UUID](#mask-uuid)
21
22
  - [Get Nested JSON Property](#get-nested-json-property)
22
23
  - [Replace the value of a JSON field](#replace-the-value-of-a-json-field)
23
- - [Mask JSON fields](#mask-fields-in-a-json)
24
- - [Mask nested JSON fields](#mask-fields-of-a-nested-object)
25
24
  - [Report Bugs](#report-bugs)
26
25
  - [Give a Star](#give-a-star)
27
26
  - [LICENSE - "MIT"](#license---mit)
@@ -42,24 +41,18 @@ maskdata is a Node.js module to mask various kinds of data. With the help of mas
42
41
  > npm i maskdata
43
42
 
44
43
  # Release Features
45
- ### Version 1.2.1
44
+ ### Version 1.2.3
45
+ - Bug fix for masking a list of elements in the nested json. More details: [Mask multiple fields](#mask-multiple-fields)
46
+ - Deprecated *maskJsonFields*(For documentation on the maskJsonFields, check previous version README.md files) function and will be removed in the subsequent versions. Use *maksJson2* instead: https://www.npmjs.com/package/maskdata#mask-json
47
+ ### Version 1.2.2
46
48
  - 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](#mask-data-for-typescript)
49
+ 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)
48
50
  ### Version 1.2.0
49
51
  - Support for masking cards, emails, passwords, phones, strings, and UUIDs. Mask all of them with a single call using - [Mask JSON fields](#mask-json)
50
52
  - Support for masking UUID - [Mask UUID](#mask-uuid)
51
53
  - Minor bug fix in card masking.
52
54
  - Extensive testing with the help of mocha test cases for all features covering more than 110 test cases.
53
55
  - Improved Documentation
54
- ### Version: 1.1.10
55
- - Support of maxMaskedCharacters in masking JSON fields: https://github.com/Sumukha1496/maskdata/issues/21
56
- - This is applicable only if the type of value is a string. Details: [Mask JSON fields](#mask-fields-in-a-json)
57
- ### Version: 1.1.8
58
- - Mocha test cases for most of the use cases.
59
- https://github.com/Sumukha1496/maskdata/pull/23
60
- - Handling null/Empty inputs --> Mask function will return the input itself.
61
- ### Version: 1.1.6
62
- - Feature to mask all the characters in the String along with mask/visible spaces in the string.
63
56
 
64
57
  # How to Use
65
58
  ```javascript
@@ -70,8 +63,9 @@ const MaskData = require('./maskdata');
70
63
 
71
64
  ## Maskdata for Typescript
72
65
  > Follow this document for more details:
73
- [Maskdata for typescript](./MASKDATA_FOR_TYPESCRIPT.md) <br/><br/>
66
+ [Maskdata for typescript](./MASKDATA_FOR_TYPESCRIPT.md)
74
67
 
68
+ <br/>
75
69
 
76
70
  ## Mask card number
77
71
  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
@@ -710,158 +704,83 @@ Type of married: boolean
710
704
 
711
705
  ```
712
706
 
713
- ## Mask fields in a JSON
714
- <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>
715
-
716
- This method masks the field value if present in the given object.
707
+ ### Mask Multiple Fields
717
708
  ```javascript
718
- const MaskData = require('./maskdata');
719
-
720
- const maskJSONOptions = {
721
- // Character to mask the data. The default value is '*'
722
- maskWith: "*",
723
-
724
- // It should be an array
725
- // Field names to mask. Can give multiple fields.
726
- fields: ['password', 'firstName'],
727
-
728
- // If the type of value is a string and if we want to limit the number of characters in the output, then we can use this. The default value is -1 means, by default this feature is disabled. It is enabled if we provide a positive integer value. This is not a mandatory field in the config and if not provided, it will take the default value -1 and disable the feature.
729
- maxMaskedCharactersStr: 4 // Default value is -1 (Disable feature)
730
- };
731
-
732
- const obj = {
733
- password: "IKnowNothing",
734
- firstName: "Jon",
735
- lastName: "Snoww"
736
- };
737
-
738
- const maskedObj = MaskData.maskJSONFields(obj, maskJSONOptions);
739
-
740
- //Output: { password: '****', firstName: '***', lastName: 'Snoww' }
741
-
742
- ```
743
-
744
-
745
- ## Mask fields of a nested Object
746
- <b>NOTE: USE [Mask JSON fields](#mask-json) for better functionalities.</b>
747
-
748
- This method masks the field value if present in the given object.
749
- The masked value type will always be a string. Won't mask if the value is ```null```.
750
-
751
- If the field doesn't exist or if there is any syntax error, then it will ignore it without throwing any error.
752
- ```javascript
753
- const MaskData = require('./maskdata');
754
-
755
- const maskJSONOptions = {
756
- // Character to mask the data. The default value is '*'
757
- maskWith: "*",
758
-
759
- // It should be an array
760
- // Field names to mask. Can give multiple fields.
761
- fields : [ 'level1.level2.level3.field3',
762
- 'level1.level2.field2',
763
- 'level1.field1',
764
- 'value1',
765
- 'level1.level2.level3.field4[0].Hello',
766
- 'level1.level2.level3.field4[2]']
767
- };
768
-
769
- const nestedObject = {
770
- level1: {
771
- field1: "field1",
772
- level2: {
773
- field2: "field2",
774
- level3: {
775
- field3: "field3",
776
- field4: [{ Hello: "world" }, { Hello: "Newworld" }, "Just a String"]
777
- }
709
+ const jsonInput = {
710
+ cards: [
711
+ {
712
+ number: '1234-5678-8765-1234'
713
+ },
714
+ {
715
+ number: '1111-2222-1111-2222'
716
+ },
717
+ {
718
+ number: '0000-1111-2222-3333'
719
+ },
720
+ {
721
+ name: "No card number here"
778
722
  }
723
+ ],
724
+ emails: {
725
+ primaryEmail: 'primary@Email.com',
726
+ secondaryEmail: 'secondary@Email.com',
727
+ moreEmails: ["email1@email.com", "email2@email.com", "email3@email.com", {childEmail: "child@child.com", secondChild: {nestedkid: "hello@hello.com"}}]
779
728
  },
780
- value1: "value"
729
+ array: ["element1", "element22", "element333"]
781
730
  };
782
- const maskedObj = MaskData.maskJSONFields(nestedObject, defaultJSONMaskOptions2);
783
-
784
- //Output:
785
- {
786
- "level1": {
787
- "field1": "******",
788
- "level2": {
789
- "field2": "******",
790
- "level3": {
791
- "field3": "******",
792
- "field4": [
793
- {
794
- "Hello": null
795
- },
796
- {
797
- "Hello": "Newworld"
798
- },
799
- "*************"
800
- ]
801
- }
802
- }
803
- },
804
- "value1": "*****"
805
- }
806
- ```
807
731
 
732
+ const jsonMaskConfig = {
733
+ cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 0, unmaskedEndDigits: 0},
808
734
 
809
- ### Example2: To mask all the keys of an object or to mask a field from all the elements of an array.
810
-
811
- ```javascript
812
- Limitations:
813
- 1. Only one * is allowed per field. Either ARRAY[*].FIELD or JSON.*
814
- 2. It will not work for nested fields like ARRAY[*].FIELD1.FIELD2
815
- 3. It will not mask all array elements if given ARRAY[*] or ARRAY[*].
816
- 4. Will not mask null values.
817
- 5. If ARRAY[*].FIELD is an object, then it will mask that entire object including the key.
735
+ emailMaskOptions: { maskWith: "*", unmaskedStartCharactersBeforeAt: 0,
736
+ unmaskedEndCharactersAfterAt: 0, maskAtTheRate: false },
818
737
 
819
- const nestedObject = {
820
- level1: {
821
- field1: "field1Value",
822
- level2: {
823
- field2: "field2Value",
824
- field3: [ { Hello: "Hello", Hi: "one" }, { Hello: "Hello again" } ],
825
- level3: {
826
- field4: "field4Value",
827
- field5: "field5Value"
828
- }
829
- }
830
- },
831
- value1: "value"
832
- };
738
+ stringMaskOptions: { maskWith: "?", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false },
833
739
 
834
- const maskAllFields = {
835
- fields : ['level1.level2.field3[*].Hello', 'level1.level2.level3.*']
836
- };
740
+ cardFields: ['cards[*].number'],
741
+ emailFields: ['emails.*'],
742
+ stringFields: ['array.*']
743
+ }
837
744
 
838
- const maskedObject = MaskData.maskJSONFields(nestedObject, maskAllFields);
745
+ const maskedOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig);
839
746
 
840
747
  // Output:
841
748
  {
842
- "level1": {
843
- "field1": "field1Value",
844
- "level2": {
845
- "field2": "field2Value",
846
- "field3": [
847
- {
848
- "Hello": "*****",
849
- "Hi": "one"
850
- },
851
- {
852
- "Hello": "***********"
749
+ "cards": [
750
+ {
751
+ "number": "XXXX-XXXX-XXXX-XXXX"
752
+ },
753
+ {
754
+ "number": "XXXX-XXXX-XXXX-XXXX"
755
+ },
756
+ {
757
+ "number": "XXXX-XXXX-XXXX-XXXX"
758
+ },
759
+ {
760
+ "name": "No card number here"
761
+ }
762
+ ],
763
+ "emails": {
764
+ "primaryEmail": "*******@*********",
765
+ "secondaryEmail": "*********@*********",
766
+ "moreEmails": [
767
+ "******@*********",
768
+ "******@*********",
769
+ "******@*********",
770
+ {
771
+ "childEmail": "*****@*********",
772
+ "secondChild": {
773
+ "nestedkid": "*****@*********"
853
774
  }
854
- ],
855
- "level3": {
856
- "field4": "***********",
857
- "field5": "***********"
858
775
  }
859
- }
776
+ ]
860
777
  },
861
- "value1": "value"
778
+ "array": ["????????", "?????????", "??????????"]
862
779
  }
780
+
863
781
  ```
864
782
 
783
+
865
784
  # Report Bugs
866
785
  If there is any help needed with the library functionalities or if there is any bug/issue, please raise an issue in GitHub: https://github.com/Sumukha1496/maskdata/issues
867
786
 
package/index.d.ts CHANGED
@@ -1,73 +1,77 @@
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
- }
1
+ declare module 'maskdata' {
2
+ export interface CardMaskOptions {
3
+ maskWith?: string;
4
+ unmaskedStartDigits?: number;
5
+ unmaskedEndDigits?: number;
6
+ }
47
7
 
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
- }
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
+ /**
65
+ * @deprecated
66
+ * Use maskJSON2 instead: https://www.npmjs.com/package/maskdata#mask-json
67
+ */
68
+ export function maskJSONFields<T extends object>(json?: T, options?: JsonMaskOptions): T;
69
+ export function maskJSON2<T extends object>(json?: T, options?: JsonMask2Configs): T;
70
+ export function maskPhone(phone?: string, options?: PhoneMaskOptions): string;
71
+ export function maskEmail2(email?: string, options?: EmailMask2Options): string;
72
+ export function maskCard(cardNumber?: string, options?: CardMaskOptions): string;
73
+ export function maskString(str?: string, options?: StringMaskOptions): string;
74
+ export function maskUuid(uuid?: string, options?: UuidMaskOptions): string;
75
+ export function getInnerProperty(object: object, field: string): any;
76
+ export function replaceValue(object: object, field: string, value: any): object;
77
+ }
package/index.js CHANGED
@@ -10,11 +10,15 @@ const JsonMask = require('./lib/maskService/JsonMask');
10
10
  const JsonGetSet = require('./lib/helpers/jsonGetSet');
11
11
 
12
12
  class MaskData {
13
-
14
13
  static maskPassword(password, options) {
15
14
  return MaskPassword.maskPassword(password, options);
16
15
  }
17
16
 
17
+ /**
18
+ *
19
+ * @deprecated
20
+ * Use maskJSON2 instead: https://www.npmjs.com/package/maskdata#mask-json
21
+ */
18
22
  static maskJSONFields(json, options) {
19
23
  return JsonMask.maskJSONFields(json, options);
20
24
  }
@@ -50,7 +54,6 @@ class MaskData {
50
54
  static replaceValue(object, field, value) {
51
55
  return JsonGetSet.set(object, field, value);
52
56
  }
53
-
54
57
  }
55
58
 
56
- module.exports = MaskData;
59
+ module.exports = MaskData;
@@ -5,8 +5,8 @@ class BadOption {
5
5
  }
6
6
 
7
7
  throwBadOptionException() {
8
- throw `Bad config value : ${JSON.stringify({where : this.where, reasons : this.reasons})}`;
8
+ throw `Bad config value : ${JSON.stringify({ where: this.where, reasons: this.reasons })}`;
9
9
  }
10
10
  }
11
11
 
12
- module.exports = BadOption;
12
+ module.exports = BadOption;
@@ -1,72 +1,71 @@
1
1
  const defaultCardMaskOptions = {
2
- maskWith: "*",
3
- unmaskedStartDigits: 4,
4
- unmaskedEndDigits: 1
2
+ maskWith: '*',
3
+ unmaskedStartDigits: 4,
4
+ unmaskedEndDigits: 1
5
5
  };
6
6
 
7
7
  const defaultEmailMask2Options = {
8
- maskWith: "*",
9
- unmaskedStartCharactersBeforeAt: 3,
10
- unmaskedEndCharactersAfterAt: 2,
11
- maskAtTheRate: false
12
- };
8
+ maskWith: '*',
9
+ unmaskedStartCharactersBeforeAt: 3,
10
+ unmaskedEndCharactersAfterAt: 2,
11
+ maskAtTheRate: false
12
+ };
13
13
 
14
14
  const defaultJsonMaskOptions = {
15
- maskWith: "*",
16
- fields: [],
17
- maxMaskedCharactersStr: -1
15
+ maskWith: '*',
16
+ fields: [],
17
+ maxMaskedCharactersStr: -1
18
18
  };
19
19
 
20
20
  const defaultPasswordMaskOptions = {
21
- maskWith: "*",
22
- maxMaskedCharacters: 16,
23
- unmaskedStartCharacters: 0,
24
- unmaskedEndCharacters: 0
21
+ maskWith: '*',
22
+ maxMaskedCharacters: 16,
23
+ unmaskedStartCharacters: 0,
24
+ unmaskedEndCharacters: 0
25
25
  };
26
26
 
27
27
  const defaultPhoneMaskOptions = {
28
- maskWith: "*",
29
- unmaskedStartDigits: 4,
30
- unmaskedEndDigits: 1
28
+ maskWith: '*',
29
+ unmaskedStartDigits: 4,
30
+ unmaskedEndDigits: 1
31
31
  };
32
32
 
33
33
  const defaultStringMaskOptions = {
34
- maskWith: "*",
35
- maskOnlyFirstOccurance: false,
36
- values: [],
37
- maskAll: false,
38
- maskSpace: true
34
+ maskWith: '*',
35
+ maskOnlyFirstOccurance: false,
36
+ values: [],
37
+ maskAll: false,
38
+ maskSpace: true
39
39
  };
40
40
 
41
41
  const defaultUuidMaskOptions = {
42
- maskWith: "*",
43
- unmaskedStartCharacters: 0,
44
- unmaskedEndCharacters: 0
42
+ maskWith: '*',
43
+ unmaskedStartCharacters: 0,
44
+ unmaskedEndCharacters: 0
45
45
  };
46
46
 
47
47
  const defaultjsonMask2Configs = {
48
- cardMaskOptions: defaultCardMaskOptions,
49
- cardFields: [],
50
- emailMaskOptions: defaultEmailMask2Options,
51
- emailFields: [],
52
- passwordMaskOptions: defaultPasswordMaskOptions,
53
- passwordFields: [],
54
- phoneMaskOptions: defaultPhoneMaskOptions,
55
- phoneFields: [],
56
- stringMaskOptions: defaultStringMaskOptions,
57
- stringFields: [],
58
- uuidMaskOptions: defaultUuidMaskOptions,
59
- uuidFields: []
48
+ cardMaskOptions: defaultCardMaskOptions,
49
+ cardFields: [],
50
+ emailMaskOptions: defaultEmailMask2Options,
51
+ emailFields: [],
52
+ passwordMaskOptions: defaultPasswordMaskOptions,
53
+ passwordFields: [],
54
+ phoneMaskOptions: defaultPhoneMaskOptions,
55
+ phoneFields: [],
56
+ stringMaskOptions: defaultStringMaskOptions,
57
+ stringFields: [],
58
+ uuidMaskOptions: defaultUuidMaskOptions,
59
+ uuidFields: []
60
60
  };
61
61
 
62
-
63
62
  module.exports = {
64
- defaultPhoneMaskOptions,
65
- defaultCardMaskOptions,
66
- defaultEmailMask2Options,
67
- defaultJsonMaskOptions,
68
- defaultPasswordMaskOptions,
69
- defaultStringMaskOptions,
70
- defaultUuidMaskOptions,
71
- defaultjsonMask2Configs
72
- }
63
+ defaultPhoneMaskOptions,
64
+ defaultCardMaskOptions,
65
+ defaultEmailMask2Options,
66
+ defaultJsonMaskOptions,
67
+ defaultPasswordMaskOptions,
68
+ defaultStringMaskOptions,
69
+ defaultUuidMaskOptions,
70
+ defaultjsonMask2Configs
71
+ };