maskdata 1.2.2 → 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.2 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,6 +41,9 @@ 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
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
45
47
  ### Version 1.2.2
46
48
  - Type definitions for the typescript developers. Yay!!!
47
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)
@@ -51,15 +53,6 @@ But there is a small change in how you import and use the library. Follow this t
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
@@ -711,158 +704,83 @@ Type of married: boolean
711
704
 
712
705
  ```
713
706
 
714
- ## Mask fields in a JSON
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>
716
-
717
- This method masks the field value if present in the given object.
718
- ```javascript
719
- const MaskData = require('./maskdata');
720
-
721
- const maskJSONOptions = {
722
- // Character to mask the data. The default value is '*'
723
- maskWith: "*",
724
-
725
- // It should be an array
726
- // Field names to mask. Can give multiple fields.
727
- fields: ['password', 'firstName'],
728
-
729
- // 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.
730
- maxMaskedCharactersStr: 4 // Default value is -1 (Disable feature)
731
- };
732
-
733
- const obj = {
734
- password: "IKnowNothing",
735
- firstName: "Jon",
736
- lastName: "Snoww"
737
- };
738
-
739
- const maskedObj = MaskData.maskJSONFields(obj, maskJSONOptions);
740
-
741
- //Output: { password: '****', firstName: '***', lastName: 'Snoww' }
742
-
743
- ```
744
-
745
-
746
- ## Mask fields of a nested Object
747
- <b>NOTE: USE [Mask JSON fields](#mask-json) for better functionalities.</b>
748
-
749
- This method masks the field value if present in the given object.
750
- The masked value type will always be a string. Won't mask if the value is ```null```.
751
-
752
- If the field doesn't exist or if there is any syntax error, then it will ignore it without throwing any error.
707
+ ### Mask Multiple Fields
753
708
  ```javascript
754
- const MaskData = require('./maskdata');
755
-
756
- const maskJSONOptions = {
757
- // Character to mask the data. The default value is '*'
758
- maskWith: "*",
759
-
760
- // It should be an array
761
- // Field names to mask. Can give multiple fields.
762
- fields : [ 'level1.level2.level3.field3',
763
- 'level1.level2.field2',
764
- 'level1.field1',
765
- 'value1',
766
- 'level1.level2.level3.field4[0].Hello',
767
- 'level1.level2.level3.field4[2]']
768
- };
769
-
770
- const nestedObject = {
771
- level1: {
772
- field1: "field1",
773
- level2: {
774
- field2: "field2",
775
- level3: {
776
- field3: "field3",
777
- field4: [{ Hello: "world" }, { Hello: "Newworld" }, "Just a String"]
778
- }
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"
779
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"}}]
780
728
  },
781
- value1: "value"
729
+ array: ["element1", "element22", "element333"]
782
730
  };
783
- const maskedObj = MaskData.maskJSONFields(nestedObject, defaultJSONMaskOptions2);
784
-
785
- //Output:
786
- {
787
- "level1": {
788
- "field1": "******",
789
- "level2": {
790
- "field2": "******",
791
- "level3": {
792
- "field3": "******",
793
- "field4": [
794
- {
795
- "Hello": null
796
- },
797
- {
798
- "Hello": "Newworld"
799
- },
800
- "*************"
801
- ]
802
- }
803
- }
804
- },
805
- "value1": "*****"
806
- }
807
- ```
808
731
 
732
+ const jsonMaskConfig = {
733
+ cardMaskOptions: { maskWith: "X", unmaskedStartDigits: 0, unmaskedEndDigits: 0},
809
734
 
810
- ### Example2: To mask all the keys of an object or to mask a field from all the elements of an array.
811
-
812
- ```javascript
813
- Limitations:
814
- 1. Only one * is allowed per field. Either ARRAY[*].FIELD or JSON.*
815
- 2. It will not work for nested fields like ARRAY[*].FIELD1.FIELD2
816
- 3. It will not mask all array elements if given ARRAY[*] or ARRAY[*].
817
- 4. Will not mask null values.
818
- 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 },
819
737
 
820
- const nestedObject = {
821
- level1: {
822
- field1: "field1Value",
823
- level2: {
824
- field2: "field2Value",
825
- field3: [ { Hello: "Hello", Hi: "one" }, { Hello: "Hello again" } ],
826
- level3: {
827
- field4: "field4Value",
828
- field5: "field5Value"
829
- }
830
- }
831
- },
832
- value1: "value"
833
- };
738
+ stringMaskOptions: { maskWith: "?", maskOnlyFirstOccurance: false, values: [], maskAll: true, maskSpace: false },
834
739
 
835
- const maskAllFields = {
836
- fields : ['level1.level2.field3[*].Hello', 'level1.level2.level3.*']
837
- };
740
+ cardFields: ['cards[*].number'],
741
+ emailFields: ['emails.*'],
742
+ stringFields: ['array.*']
743
+ }
838
744
 
839
- const maskedObject = MaskData.maskJSONFields(nestedObject, maskAllFields);
745
+ const maskedOutput = maskData.maskJSON2(jsonInput, jsonMaskConfig);
840
746
 
841
747
  // Output:
842
748
  {
843
- "level1": {
844
- "field1": "field1Value",
845
- "level2": {
846
- "field2": "field2Value",
847
- "field3": [
848
- {
849
- "Hello": "*****",
850
- "Hi": "one"
851
- },
852
- {
853
- "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": "*****@*********"
854
774
  }
855
- ],
856
- "level3": {
857
- "field4": "***********",
858
- "field5": "***********"
859
775
  }
860
- }
776
+ ]
861
777
  },
862
- "value1": "value"
778
+ "array": ["????????", "?????????", "??????????"]
863
779
  }
780
+
864
781
  ```
865
782
 
783
+
866
784
  # Report Bugs
867
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
868
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
+ };