@etsoo/shared 1.1.18 → 1.1.19

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
@@ -190,5 +190,6 @@ String and other related utilities
190
190
  |objectUpdated|Get the new object's updated fields contrast to the previous object|
191
191
  |parseString|Parse string (JSON) to specific type|
192
192
  |removeNonLetters|Remove non letters (0-9, a-z, A-Z)|
193
+ |replaceNullOrEmpty|Replace null or empty with default value|
193
194
  |setLabels|Set source with new labels|
194
195
  |snakeNameToWord|Snake name to works, 'snake_name' to 'Snake Name'|
@@ -126,6 +126,12 @@ test('Tests for removeNonLetters', () => {
126
126
  expect(input.removeNonLetters()).toBe(result);
127
127
  });
128
128
 
129
+ test('Tests for replaceNullOrEmpty', () => {
130
+ expect(Utils.replaceNullOrEmpty('a', 's')).toBe('a');
131
+ expect(Utils.replaceNullOrEmpty(null, 's')).toBe('s');
132
+ expect(Utils.replaceNullOrEmpty(' ', 's')).toBe('s');
133
+ });
134
+
129
135
  test('Tests for objectEqual', () => {
130
136
  const obj1 = { a: 1, b: 'abc', c: true, d: null, f: [1, 2] };
131
137
  const obj2 = { a: '1', b: 'abc', c: true, f: [1, 2] };
@@ -189,6 +189,13 @@ export declare namespace Utils {
189
189
  * @returns Result
190
190
  */
191
191
  const removeNonLetters: (input?: string | undefined) => string | undefined;
192
+ /**
193
+ * Replace null or empty with default value
194
+ * @param input Input string
195
+ * @param defaultValue Default value
196
+ * @returns Result
197
+ */
198
+ const replaceNullOrEmpty: (input: string | null | undefined, defaultValue: string) => string;
192
199
  /**
193
200
  * Set source with new labels
194
201
  * @param source Source
package/lib/cjs/Utils.js CHANGED
@@ -371,6 +371,17 @@ var Utils;
371
371
  Utils.removeNonLetters = (input) => {
372
372
  return input === null || input === void 0 ? void 0 : input.removeNonLetters();
373
373
  };
374
+ /**
375
+ * Replace null or empty with default value
376
+ * @param input Input string
377
+ * @param defaultValue Default value
378
+ * @returns Result
379
+ */
380
+ Utils.replaceNullOrEmpty = (input, defaultValue) => {
381
+ if (input == null || input.trim() === '')
382
+ return defaultValue;
383
+ return input;
384
+ };
374
385
  /**
375
386
  * Set source with new labels
376
387
  * @param source Source
@@ -189,6 +189,13 @@ export declare namespace Utils {
189
189
  * @returns Result
190
190
  */
191
191
  const removeNonLetters: (input?: string | undefined) => string | undefined;
192
+ /**
193
+ * Replace null or empty with default value
194
+ * @param input Input string
195
+ * @param defaultValue Default value
196
+ * @returns Result
197
+ */
198
+ const replaceNullOrEmpty: (input: string | null | undefined, defaultValue: string) => string;
192
199
  /**
193
200
  * Set source with new labels
194
201
  * @param source Source
package/lib/mjs/Utils.js CHANGED
@@ -368,6 +368,17 @@ export var Utils;
368
368
  Utils.removeNonLetters = (input) => {
369
369
  return input === null || input === void 0 ? void 0 : input.removeNonLetters();
370
370
  };
371
+ /**
372
+ * Replace null or empty with default value
373
+ * @param input Input string
374
+ * @param defaultValue Default value
375
+ * @returns Result
376
+ */
377
+ Utils.replaceNullOrEmpty = (input, defaultValue) => {
378
+ if (input == null || input.trim() === '')
379
+ return defaultValue;
380
+ return input;
381
+ };
371
382
  /**
372
383
  * Set source with new labels
373
384
  * @param source Source
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.18",
3
+ "version": "1.1.19",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -55,9 +55,9 @@
55
55
  "dependencies": {},
56
56
  "devDependencies": {
57
57
  "@types/jest": "^27.4.1",
58
- "@typescript-eslint/eslint-plugin": "^5.16.0",
59
- "@typescript-eslint/parser": "^5.16.0",
60
- "eslint": "^8.11.0",
58
+ "@typescript-eslint/eslint-plugin": "^5.17.0",
59
+ "@typescript-eslint/parser": "^5.17.0",
60
+ "eslint": "^8.12.0",
61
61
  "eslint-config-airbnb-base": "^15.0.0",
62
62
  "eslint-plugin-import": "^2.25.4",
63
63
  "jest": "^27.5.1",
package/src/Utils.ts CHANGED
@@ -516,6 +516,20 @@ export namespace Utils {
516
516
  return input?.removeNonLetters();
517
517
  };
518
518
 
519
+ /**
520
+ * Replace null or empty with default value
521
+ * @param input Input string
522
+ * @param defaultValue Default value
523
+ * @returns Result
524
+ */
525
+ export const replaceNullOrEmpty = (
526
+ input: string | null | undefined,
527
+ defaultValue: string
528
+ ) => {
529
+ if (input == null || input.trim() === '') return defaultValue;
530
+ return input;
531
+ };
532
+
519
533
  /**
520
534
  * Set source with new labels
521
535
  * @param source Source