@etsoo/shared 1.1.9 → 1.1.10

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 CHANGED
@@ -159,6 +159,10 @@ String and other related utilities
159
159
  |formatString|Format string with parameters|
160
160
  |getDataChanges|Get data changed fields with input data updated|
161
161
  |getTimeZone|Get time zone|
162
+ |hideData|Hide data|
163
+ |hideEmail|Hide email data|
164
+ |isDigits|Is digits string|
165
+ |isEmail|Is email string|
162
166
  |joinItems|Join items as a string|
163
167
  |mergeFormData|Merge form data to primary one|
164
168
  |mergeClasses|Merge class names|
@@ -168,5 +172,6 @@ String and other related utilities
168
172
  |objectKeys|Get two object's unqiue properties|
169
173
  |objectUpdated|Get the new object's updated fields contrast to the previous object|
170
174
  |parseString|Parse string (JSON) to specific type|
175
+ |removeNonLetters|Remove non letters (0-9, a-z, A-Z)|
171
176
  |setLabels|Set source with new labels|
172
177
  |snakeNameToWord|Snake name to works, 'snake_name' to 'Snake Name'|
@@ -77,6 +77,13 @@ test('Tests for formatString', () => {
77
77
  expect(template.format('aa', 'bb')).toBe(result);
78
78
  });
79
79
 
80
+ test('Tests for hideData', () => {
81
+ expect('xz@etsoo.com'.hideEmail()).toBe('x***@etsoo.com');
82
+ expect('info@etsoo.com'.hideEmail()).toBe('in***@etsoo.com');
83
+ expect('info@etsoo.com'.hideData('@')).toBe('in***@etsoo.com');
84
+ expect('12345678'.hideData()).toBe('123***678');
85
+ });
86
+
80
87
  test('Tests for isDigits', () => {
81
88
  expect(Utils.isDigits('1')).toBeTruthy();
82
89
  expect(Utils.isDigits('12', 3)).toBeFalsy();
@@ -13,6 +13,17 @@ declare global {
13
13
  * @param upperCase To upper case or lower case
14
14
  */
15
15
  formatInitial(this: string, upperCase: boolean): string;
16
+ /**
17
+ * Hide data
18
+ * @param this Input string
19
+ * @param endChar End char
20
+ */
21
+ hideData(this: string, endChar?: string): string;
22
+ /**
23
+ * Hide email data
24
+ * @param this Input email
25
+ */
26
+ hideEmail(this: string): string;
16
27
  /**
17
28
  * Is digits string
18
29
  * @param this Input string
package/lib/cjs/Utils.js CHANGED
@@ -14,6 +14,27 @@ String.prototype.formatInitial = function (upperCase = false) {
14
14
  return ((upperCase ? initial.toUpperCase() : initial.toLowerCase()) +
15
15
  this.slice(1));
16
16
  };
17
+ String.prototype.hideData = function (endChar) {
18
+ if (endChar != null) {
19
+ const index = this.indexOf(endChar);
20
+ if (index === -1)
21
+ return this.hideData();
22
+ return this.substring(0, index).hideData() + this.substring(index);
23
+ }
24
+ var len = this.length;
25
+ if (len < 4)
26
+ return this.substring(0, 1) + '***';
27
+ if (len < 6)
28
+ return this.substring(0, 2) + '***';
29
+ if (len < 8)
30
+ return this.substring(0, 2) + '***' + this.slice(-2);
31
+ if (len < 12)
32
+ return this.substring(0, 3) + '***' + this.slice(-3);
33
+ return this.substring(0, 4) + '***' + this.slice(-4);
34
+ };
35
+ String.prototype.hideEmail = function () {
36
+ return this.hideData('@');
37
+ };
17
38
  String.prototype.isDigits = function (minLength) {
18
39
  return this.length >= (minLength !== null && minLength !== void 0 ? minLength : 0) && /^\d+$/.test(this);
19
40
  };
@@ -13,6 +13,17 @@ declare global {
13
13
  * @param upperCase To upper case or lower case
14
14
  */
15
15
  formatInitial(this: string, upperCase: boolean): string;
16
+ /**
17
+ * Hide data
18
+ * @param this Input string
19
+ * @param endChar End char
20
+ */
21
+ hideData(this: string, endChar?: string): string;
22
+ /**
23
+ * Hide email data
24
+ * @param this Input email
25
+ */
26
+ hideEmail(this: string): string;
16
27
  /**
17
28
  * Is digits string
18
29
  * @param this Input string
package/lib/mjs/Utils.js CHANGED
@@ -11,6 +11,27 @@ String.prototype.formatInitial = function (upperCase = false) {
11
11
  return ((upperCase ? initial.toUpperCase() : initial.toLowerCase()) +
12
12
  this.slice(1));
13
13
  };
14
+ String.prototype.hideData = function (endChar) {
15
+ if (endChar != null) {
16
+ const index = this.indexOf(endChar);
17
+ if (index === -1)
18
+ return this.hideData();
19
+ return this.substring(0, index).hideData() + this.substring(index);
20
+ }
21
+ var len = this.length;
22
+ if (len < 4)
23
+ return this.substring(0, 1) + '***';
24
+ if (len < 6)
25
+ return this.substring(0, 2) + '***';
26
+ if (len < 8)
27
+ return this.substring(0, 2) + '***' + this.slice(-2);
28
+ if (len < 12)
29
+ return this.substring(0, 3) + '***' + this.slice(-3);
30
+ return this.substring(0, 4) + '***' + this.slice(-4);
31
+ };
32
+ String.prototype.hideEmail = function () {
33
+ return this.hideData('@');
34
+ };
14
35
  String.prototype.isDigits = function (minLength) {
15
36
  return this.length >= (minLength !== null && minLength !== void 0 ? minLength : 0) && /^\d+$/.test(this);
16
37
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.9",
3
+ "version": "1.1.10",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/Utils.ts CHANGED
@@ -16,6 +16,19 @@ declare global {
16
16
  */
17
17
  formatInitial(this: string, upperCase: boolean): string;
18
18
 
19
+ /**
20
+ * Hide data
21
+ * @param this Input string
22
+ * @param endChar End char
23
+ */
24
+ hideData(this: string, endChar?: string): string;
25
+
26
+ /**
27
+ * Hide email data
28
+ * @param this Input email
29
+ */
30
+ hideEmail(this: string): string;
31
+
19
32
  /**
20
33
  * Is digits string
21
34
  * @param this Input string
@@ -59,6 +72,26 @@ String.prototype.formatInitial = function (
59
72
  );
60
73
  };
61
74
 
75
+ String.prototype.hideData = function (this: string, endChar?: string) {
76
+ if (endChar != null) {
77
+ const index = this.indexOf(endChar);
78
+ if (index === -1) return this.hideData();
79
+ return this.substring(0, index).hideData() + this.substring(index);
80
+ }
81
+
82
+ var len = this.length;
83
+ if (len < 4) return this.substring(0, 1) + '***';
84
+ if (len < 6) return this.substring(0, 2) + '***';
85
+ if (len < 8) return this.substring(0, 2) + '***' + this.slice(-2);
86
+ if (len < 12) return this.substring(0, 3) + '***' + this.slice(-3);
87
+
88
+ return this.substring(0, 4) + '***' + this.slice(-4);
89
+ };
90
+
91
+ String.prototype.hideEmail = function (this: string) {
92
+ return this.hideData('@');
93
+ };
94
+
62
95
  String.prototype.isDigits = function (this: string, minLength?: number) {
63
96
  return this.length >= (minLength ?? 0) && /^\d+$/.test(this);
64
97
  };