typeshi 1.7.19 → 2.0.1

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.
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isStringCleanOptions = isStringCleanOptions;
4
+ exports.isStringStripOptions = isStringStripOptions;
5
+ exports.isStringPadOptions = isStringPadOptions;
6
+ exports.isStringCaseEnum = isStringCaseEnum;
7
+ exports.isStringPadEnum = isStringPadEnum;
8
+ exports.isStringReplaceParams = isStringReplaceParams;
9
+ exports.isStringCondition = isStringCondition;
10
+ exports.isStringStripCondition = isStringStripCondition;
11
+ exports.DEP_isCleanStringOptions = DEP_isCleanStringOptions;
12
+ /**
13
+ * @file src/utils/regex/types/StringOptions.TypeGuards.ts
14
+ */
15
+ const StringOptions_1 = require("./StringOptions");
16
+ const typeValidation_1 = require("../../typeValidation");
17
+ function isStringCleanOptions(value) {
18
+ const candidate = value;
19
+ return ((0, typeValidation_1.isObject)(candidate, false)
20
+ && typeValidation_1.isUndefinedOr.type(candidate.strip, isStringStripOptions)
21
+ && typeValidation_1.isUndefinedOr.type(candidate.pad, isStringPadOptions)
22
+ && typeValidation_1.isUndefinedOr.type(candidate.case, isStringCaseEnum)
23
+ && typeValidation_1.isUndefinedOr.array(candidate.replace, isStringReplaceParams)
24
+ && typeValidation_1.isUndefinedOr.boolean(candidate.useDefault));
25
+ }
26
+ function isStringStripOptions(value) {
27
+ const candidate = value;
28
+ return ((0, typeValidation_1.isObject)(candidate, false)
29
+ && (typeValidation_1.isUndefinedOr.string(candidate.char) || candidate.char instanceof RegExp)
30
+ && typeValidation_1.isUndefinedOr.type(candidate.left, isStringStripCondition)
31
+ && typeValidation_1.isUndefinedOr.type(candidate.right, isStringStripCondition));
32
+ }
33
+ function isStringPadOptions(value) {
34
+ const candidate = value;
35
+ return ((0, typeValidation_1.isObject)(candidate)
36
+ && (0, typeValidation_1.isPositveInteger)(candidate.maxLength)
37
+ && (!candidate.char || (typeof candidate.char === 'string' && candidate.char.length === 1))
38
+ && typeValidation_1.isUndefinedOr.type(candidate.side, isStringPadEnum));
39
+ }
40
+ function isStringCaseEnum(value) {
41
+ return ((0, typeValidation_1.isNonEmptyString)(value)
42
+ && Object.values(StringOptions_1.StringCaseEnum).includes(value));
43
+ }
44
+ function isStringPadEnum(value) {
45
+ return ((0, typeValidation_1.isNonEmptyString)(value)
46
+ && Object.values(StringOptions_1.StringPadEnum).includes(value));
47
+ }
48
+ function isStringReplaceParams(value) {
49
+ const candidate = value;
50
+ return ((0, typeValidation_1.isObject)(candidate)
51
+ && (typeof candidate.searchValue === 'string' || candidate.searchValue instanceof RegExp)
52
+ && (typeof candidate.replaceValue === 'string'));
53
+ }
54
+ function isStringCondition(value) {
55
+ const candidate = value;
56
+ return ((0, typeValidation_1.isObject)(candidate)
57
+ && (0, typeValidation_1.isFunction)(candidate.condition)
58
+ && (!candidate.args || Array.isArray(candidate.args)));
59
+ }
60
+ function isStringStripCondition(value) {
61
+ const candidate = value;
62
+ return ((0, typeValidation_1.isObject)(candidate)
63
+ && (0, typeValidation_1.isFunction)(candidate.condition)
64
+ && typeValidation_1.isUndefinedOr.array(candidate.args)
65
+ && typeValidation_1.isUndefinedOr.positiveInteger(candidate.max));
66
+ }
67
+ /**
68
+ * - {@link DEP_CleanStringOptions}
69
+ * @param value `any`
70
+ * @returns **`isCleanStringOptions`** `boolean`
71
+ * - **`true`** if the `value` is an object with at least one key in `['strip', 'case', 'pad', 'replace']` and no other keys,
72
+ * - **`false`** `otherwise`.
73
+ */
74
+ function DEP_isCleanStringOptions(value) {
75
+ return (value && typeof value === 'object'
76
+ && (0, typeValidation_1.hasKeys)(value, ['strip', 'case', 'pad', 'replace'], false, true));
77
+ }
@@ -1,6 +1,64 @@
1
1
  /**
2
2
  * @file src/utils/regex/types/StringOptions.ts
3
3
  */
4
+ export declare const StringCaseEnum: {
5
+ readonly UPPER: "upper";
6
+ readonly LOWER: "lower";
7
+ readonly TITLE: "title";
8
+ };
9
+ export type StringCaseEnum = (typeof StringCaseEnum)[keyof typeof StringCaseEnum];
10
+ export declare const StringPadEnum: {
11
+ readonly LEFT: "left";
12
+ readonly RIGHT: "right";
13
+ readonly BOTH: "both";
14
+ };
15
+ export type StringPadEnum = (typeof StringPadEnum)[keyof typeof StringPadEnum];
16
+ export interface StringPadOptions {
17
+ maxLength: number;
18
+ /** `default` = `' '` (single space character) */
19
+ char?: string;
20
+ /** `default` = `'left'` (pad left side of string) */
21
+ side?: StringPadEnum;
22
+ }
23
+ export interface StringCondition {
24
+ condition: (s: string, ...args: any[]) => boolean;
25
+ args?: any[];
26
+ }
27
+ export type StringStripCondition = StringCondition & {
28
+ /** max number of times to strip char from one side */
29
+ max?: number;
30
+ };
31
+ export interface StringStripOptions {
32
+ /**
33
+ * `default` = `/\s+/`
34
+ * - will escape special characters if `char` is `string`
35
+ * */
36
+ char?: string | RegExp;
37
+ left?: StringStripCondition;
38
+ right?: StringStripCondition;
39
+ }
40
+ export interface StringCleanOptions {
41
+ strip?: StringStripOptions;
42
+ case?: StringCaseEnum;
43
+ pad?: StringPadOptions;
44
+ replace?: StringReplaceParams[];
45
+ useDefault?: boolean;
46
+ }
47
+ export type CleanStringOptions = StringCleanOptions;
48
+ /**
49
+ * @typedefn **`StringReplaceOptions`**
50
+ * @property {StringReplaceParams[]} replacements - an array of objects containing `searchValue` and `replaceValue` properties
51
+ */
52
+ export type StringReplaceOptions = StringReplaceParams[];
53
+ /**
54
+ * @typedefn **`StringReplaceParams`**
55
+ * @property {string | RegExp} searchValue - the string or regular expression to search for in the string
56
+ * @property {string} replaceValue - the string to replace the `searchValue` with
57
+ */
58
+ export type StringReplaceParams = {
59
+ searchValue: string | RegExp;
60
+ replaceValue: string;
61
+ };
4
62
  /**
5
63
  * @reference {@link https://javascript.info/regexp-introduction}
6
64
  * @enum {string} **`RegExpFlagsEnum`**
@@ -22,10 +80,10 @@ export declare enum RegExpFlagsEnum {
22
80
  /**
23
81
  * @typedefn **`CleanStringOptions`**
24
82
  */
25
- export type CleanStringOptions = {
26
- strip?: StringStripOptions;
27
- case?: StringCaseOptions;
28
- pad?: StringPadOptions;
83
+ export type DEP_CleanStringOptions = {
84
+ strip?: DEP_StringStripOptions;
85
+ case?: DEP_StringCaseOptions;
86
+ pad?: DEP_StringPadOptions;
29
87
  replace?: StringReplaceOptions;
30
88
  };
31
89
  /**
@@ -34,7 +92,7 @@ export type CleanStringOptions = {
34
92
  * @property {boolean} [toLower] - `true` if the string should be converted to lower case
35
93
  * @property {boolean} [toTitle] - `true` if the string should be converted to title case, see {@link toTitleCase}
36
94
  */
37
- export type StringCaseOptions = {
95
+ export type DEP_StringCaseOptions = {
38
96
  toUpper?: boolean;
39
97
  toLower?: boolean;
40
98
  toTitle?: boolean;
@@ -46,7 +104,7 @@ export type StringCaseOptions = {
46
104
  * @property {boolean} [padLeft] - `true` if the padding should be added to the left side of the string
47
105
  * @property {boolean} [padRight] - `true` if the padding should be added to the right side of the string
48
106
  */
49
- export type StringPadOptions = {
107
+ export type DEP_StringPadOptions = {
50
108
  padLength: number;
51
109
  padChar?: string;
52
110
  padLeft?: boolean;
@@ -63,7 +121,7 @@ export type StringPadOptions = {
63
121
  * @property {any[]} [rightArgs] - arguments to pass to the `stripRightCondition` function
64
122
  * - if `stripRightCondition(s, rightArgs)` is `true` or `stripRightCondition` is `undefined` (i.e. no conditions need to be met to strip right), the right side of `s` is stripped of `char`
65
123
  */
66
- export type StringStripOptions = {
124
+ export type DEP_StringStripOptions = {
67
125
  char: string;
68
126
  escape?: boolean;
69
127
  stripLeftCondition?: (s: string, ...args: any[]) => boolean;
@@ -71,17 +129,3 @@ export type StringStripOptions = {
71
129
  stripRightCondition?: (s: string, ...args: any[]) => boolean;
72
130
  rightArgs?: any[];
73
131
  };
74
- /**
75
- * @typedefn **`StringReplaceOptions`**
76
- * @property {StringReplaceParams[]} replacements - an array of objects containing `searchValue` and `replaceValue` properties
77
- */
78
- export type StringReplaceOptions = StringReplaceParams[];
79
- /**
80
- * @typedefn **`StringReplaceParams`**
81
- * @property {string | RegExp} searchValue - the string or regular expression to search for in the string
82
- * @property {string} replaceValue - the string to replace the `searchValue` with
83
- */
84
- export type StringReplaceParams = {
85
- searchValue: string | RegExp;
86
- replaceValue: string;
87
- };
@@ -3,7 +3,17 @@
3
3
  * @file src/utils/regex/types/StringOptions.ts
4
4
  */
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.RegExpFlagsEnum = void 0;
6
+ exports.RegExpFlagsEnum = exports.StringPadEnum = exports.StringCaseEnum = void 0;
7
+ exports.StringCaseEnum = {
8
+ UPPER: 'upper',
9
+ LOWER: 'lower',
10
+ TITLE: 'title',
11
+ };
12
+ exports.StringPadEnum = {
13
+ LEFT: 'left',
14
+ RIGHT: 'right',
15
+ BOTH: 'both'
16
+ };
7
17
  /**
8
18
  * @reference {@link https://javascript.info/regexp-introduction}
9
19
  * @enum {string} **`RegExpFlagsEnum`**
@@ -2,4 +2,4 @@
2
2
  * @file src/utils/regex/types/index.ts
3
3
  */
4
4
  export * from "./StringOptions";
5
- export * from "./typeGuards";
5
+ export * from "./StringOptions.TypeGuards";
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  * @file src/utils/regex/types/index.ts
19
19
  */
20
20
  __exportStar(require("./StringOptions"), exports);
21
- __exportStar(require("./typeGuards"), exports);
21
+ __exportStar(require("./StringOptions.TypeGuards"), exports);
@@ -29,11 +29,11 @@ export declare function isNullLike(value: any): value is '' | null | undefined |
29
29
  export declare function anyNull(...values: any[]): boolean;
30
30
  /**
31
31
  * @param value
32
- * @returns **`isNonEmptyArray`** `boolean` = `value is Array<any> & { length: number }`
32
+ * @returns **`isNonEmptyArray`** `boolean` = `value is Array<T> & { length: number }`
33
33
  * - **`true`** if `value` is an array and has at least one element,
34
34
  * - **`false`** otherwise.
35
35
  */
36
- export declare function isNonEmptyArray(value: any): value is Array<any> & {
36
+ export declare function isNonEmptyArray<T = any>(value: any): value is Array<T> & {
37
37
  length: number;
38
38
  };
39
39
  /**
@@ -42,7 +42,7 @@ export declare function isNonEmptyArray(value: any): value is Array<any> & {
42
42
  * - **`true`** if `value` is an array and has no elements,
43
43
  * - **`false`** `otherwise`
44
44
  */
45
- export declare function isEmptyArray(value: any): value is Array<any> & {
45
+ export declare function isEmptyArray<T = any>(value: any): value is Array<T> & {
46
46
  length: 0;
47
47
  };
48
48
  /**
@@ -113,11 +113,14 @@ export declare function areEquivalentObjects(objA: Record<string, any>, objB: Re
113
113
  export declare function isNumeric(value: any, requireInteger?: boolean, requireNonNegative?: boolean): value is string | number;
114
114
  /**
115
115
  * @param value `any`
116
+ * @param requireNonSpace `boolean (optional)` `default` = `false`
117
+ * - `if true` then `value.trim()` must not result in empty string
118
+ * - `if false` then allows for `value` to consist solely of whitespace characters
116
119
  * @returns **`isNonEmptyString`** `boolean`
117
- * - `true` `if` `value` is a non-empty string (not just whitespace),
120
+ * - `true` `if` `value` is a non-empty string
118
121
  * - `false` `otherwise`.
119
122
  */
120
- export declare function isNonEmptyString(value: any): value is string & {
123
+ export declare function isNonEmptyString(value: any, requireNonSpace?: boolean): value is string & {
121
124
  length: number;
122
125
  };
123
126
  export declare function isPrimitiveValue(value: any): value is string | number | boolean | null | undefined;
@@ -144,25 +147,47 @@ export declare function isPositveInteger(value: any): value is number;
144
147
  export declare const isType: <T>(value: any, guard: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T;
145
148
  /**
146
149
  * - calls {@link isUndefinedOrNull}`(value)` which allows for value to be `undefined` or `null`
147
- * - use {@link isUndefinedOr} if you want value is `T | undefined`
150
+ * - use {@link isUndefinedOr} if you want `value is T | undefined`
148
151
  */
149
152
  export declare class isOptional {
150
153
  static type: <T>(value: any, guard: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T | undefined | null;
151
154
  /**
155
+ * - allows for empty array
152
156
  * @param value
153
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that string have at least 1 non-whitespace character)
154
- * @returns
157
+ * @param elementGuard `function` checks that each element of array, when passed into this function, returns true
158
+ * - if not provided, then will only check that value is an array
159
+ * @param args `any[]` arguments that will be passed into `elementGuard` e.g. `elementGuard(value[i], ...args)`
155
160
  */
156
- static string: (value: any, requireNonEmpty?: boolean) => value is string | undefined | null;
161
+ static array: <T>(value: any, elementGuard?: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T[] | undefined | null;
157
162
  /**
158
163
  * @param value
159
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that array have at least 1 element)
164
+ * @param requireNonSpace `boolean` `default` = `false`
165
+ * - `if` `true`, require that string have at least 1 non-whitespace character
160
166
  * @returns
161
167
  */
168
+ static string: (value: any, requireNonSpace?: boolean) => value is string | undefined | null;
169
+ /**
170
+ * @param value
171
+ * @param requireNonEmpty `boolean` `default` = `false` (if `true`, require that array have at least 1 element)
172
+ */
162
173
  static stringArray: (value: any, requireNonEmpty?: boolean) => value is string[] | undefined | null;
174
+ /**
175
+ * @param value `any`
176
+ * @param requireInteger `boolean` `default = false`
177
+ * @param requireNonNegative `boolean` `default = false`
178
+ * @returns **`isNumeric`** `value is string | number`
179
+ * - **`true`** `if` `value` is either a `number` or a `string` that can be casted to a `number`
180
+ * while also meeting the boolean parameter requirements
181
+ * - **`false`** `otherwise`
182
+ */
163
183
  static numeric: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is string | number | undefined | null;
164
184
  static number: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is number | undefined | null;
165
185
  static positiveInteger: (value: any) => value is number | undefined | null;
186
+ /**
187
+ * @param value
188
+ * @param requireNonNegative `boolean (optional)` `default` = `false`
189
+ * @param requireNonEmpty `boolean (optional)` `default` = `false`
190
+ */
166
191
  static integerArray: (value: any, requireNonNegative?: boolean, requireNonEmpty?: boolean) => value is number[] | undefined | null;
167
192
  static boolean: (value: any) => value is boolean | undefined | null;
168
193
  static function: (value: any) => value is Function | undefined | null;
@@ -170,20 +195,42 @@ export declare class isOptional {
170
195
  export declare class isUndefinedOr {
171
196
  static type: <T>(value: any, guard: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T | undefined;
172
197
  /**
198
+ * - allows for empty array
173
199
  * @param value
174
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that string have at least 1 non-whitespace character)
175
- * @returns
200
+ * @param elementGuard `function` checks that each element of array, when passeed into this function, returns true
201
+ * - if not provided, then will only check that value is an array
202
+ * @param args `any[]` arguments that will be passed into `elementGuard` e.g. `elementGuard(value[i], ...args)`
176
203
  */
177
- static string: (value: any, requireNonEmpty?: boolean) => value is string | undefined;
204
+ static array: <T>(value: any, elementGuard?: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T[] | undefined;
178
205
  /**
179
206
  * @param value
180
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that array have at least 1 element)
181
- * @returns
207
+ * @param requireNonEmpty `boolean` `default` = `false`
208
+ * - `if` `true`, require that string have at least 1 non-whitespace character
209
+ */
210
+ static string: (value: any, requireNonSpace?: boolean) => value is string | undefined;
211
+ /**
212
+ * @param value
213
+ * @param requireNonEmpty `boolean` `default` = `false`
214
+ * - `if` `true`, require that array have at least 1 element
182
215
  */
183
216
  static stringArray: (value: any, requireNonEmpty?: boolean) => value is string[] | undefined;
217
+ /**
218
+ * @param value `any`
219
+ * @param requireInteger `boolean` `default = false`
220
+ * @param requireNonNegative `boolean` `default = false`
221
+ * @returns **`isNumeric`** `value is string | number`
222
+ * - **`true`** `if` `value` is either a `number` or a `string` that can be casted to a `number`
223
+ * while also meeting the boolean parameter requirements
224
+ * - **`false`** `otherwise`
225
+ */
184
226
  static numeric: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is string | number | undefined;
185
227
  static number: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is number | undefined;
186
228
  static positiveInteger: (value: any) => value is number | undefined;
229
+ /**
230
+ * @param value
231
+ * @param requireNonNegative `boolean (optional)` `default` = `false`
232
+ * @param requireNonEmpty `boolean (optional)` `default` = `false`
233
+ */
187
234
  static integerArray: (value: any, requireNonNegative?: boolean, requireNonEmpty?: boolean) => value is number[] | undefined;
188
235
  static boolean: (value: any) => value is boolean | undefined;
189
236
  static function: (value: any) => value is Function | undefined;
@@ -74,7 +74,7 @@ function anyNull(...values) {
74
74
  }
75
75
  /**
76
76
  * @param value
77
- * @returns **`isNonEmptyArray`** `boolean` = `value is Array<any> & { length: number }`
77
+ * @returns **`isNonEmptyArray`** `boolean` = `value is Array<T> & { length: number }`
78
78
  * - **`true`** if `value` is an array and has at least one element,
79
79
  * - **`false`** otherwise.
80
80
  */
@@ -244,12 +244,18 @@ function isNumeric(value, requireInteger = false, requireNonNegative = false) {
244
244
  }
245
245
  /**
246
246
  * @param value `any`
247
+ * @param requireNonSpace `boolean (optional)` `default` = `false`
248
+ * - `if true` then `value.trim()` must not result in empty string
249
+ * - `if false` then allows for `value` to consist solely of whitespace characters
247
250
  * @returns **`isNonEmptyString`** `boolean`
248
- * - `true` `if` `value` is a non-empty string (not just whitespace),
251
+ * - `true` `if` `value` is a non-empty string
249
252
  * - `false` `otherwise`.
250
253
  */
251
- function isNonEmptyString(value) {
252
- return typeof value === 'string' && value.trim() !== '';
254
+ function isNonEmptyString(value, requireNonSpace = false) {
255
+ return (typeof value === 'string'
256
+ && (requireNonSpace
257
+ ? value.trim() !== ''
258
+ : value.length > 0));
253
259
  }
254
260
  function isPrimitiveValue(value) {
255
261
  if (value === null || value === undefined) {
@@ -299,7 +305,7 @@ const isType = (value, guard, ...args) => {
299
305
  exports.isType = isType;
300
306
  /**
301
307
  * - calls {@link isUndefinedOrNull}`(value)` which allows for value to be `undefined` or `null`
302
- * - use {@link isUndefinedOr} if you want value is `T | undefined`
308
+ * - use {@link isUndefinedOr} if you want `value is T | undefined`
303
309
  */
304
310
  class isOptional {
305
311
  }
@@ -308,21 +314,41 @@ isOptional.type = (value, guard, ...args) => {
308
314
  return isUndefinedOrNull(value) || (0, exports.isType)(value, guard, ...args);
309
315
  };
310
316
  /**
317
+ * - allows for empty array
311
318
  * @param value
312
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that string have at least 1 non-whitespace character)
313
- * @returns
319
+ * @param elementGuard `function` checks that each element of array, when passed into this function, returns true
320
+ * - if not provided, then will only check that value is an array
321
+ * @param args `any[]` arguments that will be passed into `elementGuard` e.g. `elementGuard(value[i], ...args)`
314
322
  */
315
- isOptional.string = (value, requireNonEmpty = true) => {
316
- return isUndefinedOrNull(value) || requireNonEmpty ? isNonEmptyString(value) : typeof value === "string";
323
+ isOptional.array = (value, elementGuard, ...args) => {
324
+ return isUndefinedOrNull(value) || (Array.isArray(value)
325
+ && (!elementGuard || value.every(v => elementGuard(v, ...args))));
317
326
  };
318
327
  /**
319
328
  * @param value
320
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that array have at least 1 element)
329
+ * @param requireNonSpace `boolean` `default` = `false`
330
+ * - `if` `true`, require that string have at least 1 non-whitespace character
321
331
  * @returns
322
332
  */
323
- isOptional.stringArray = (value, requireNonEmpty = true) => {
333
+ isOptional.string = (value, requireNonSpace = false) => {
334
+ return isUndefinedOrNull(value) || isNonEmptyString(value, requireNonSpace);
335
+ };
336
+ /**
337
+ * @param value
338
+ * @param requireNonEmpty `boolean` `default` = `false` (if `true`, require that array have at least 1 element)
339
+ */
340
+ isOptional.stringArray = (value, requireNonEmpty = false) => {
324
341
  return isUndefinedOrNull(value) || isStringArray(value, requireNonEmpty);
325
342
  };
343
+ /**
344
+ * @param value `any`
345
+ * @param requireInteger `boolean` `default = false`
346
+ * @param requireNonNegative `boolean` `default = false`
347
+ * @returns **`isNumeric`** `value is string | number`
348
+ * - **`true`** `if` `value` is either a `number` or a `string` that can be casted to a `number`
349
+ * while also meeting the boolean parameter requirements
350
+ * - **`false`** `otherwise`
351
+ */
326
352
  isOptional.numeric = (value, requireInteger = false, requireNonNegative = false) => {
327
353
  return isUndefinedOrNull(value) || isNumeric(value, requireInteger, requireNonNegative);
328
354
  };
@@ -333,7 +359,12 @@ isOptional.number = (value, requireInteger = false, requireNonNegative = false)
333
359
  isOptional.positiveInteger = (value) => {
334
360
  return (isUndefinedOrNull(value) || isPositveInteger(value));
335
361
  };
336
- isOptional.integerArray = (value, requireNonNegative = false, requireNonEmpty = true) => {
362
+ /**
363
+ * @param value
364
+ * @param requireNonNegative `boolean (optional)` `default` = `false`
365
+ * @param requireNonEmpty `boolean (optional)` `default` = `false`
366
+ */
367
+ isOptional.integerArray = (value, requireNonNegative = false, requireNonEmpty = false) => {
337
368
  return isUndefinedOrNull(value) || isIntegerArray(value, requireNonNegative, requireNonEmpty);
338
369
  };
339
370
  isOptional.boolean = (value) => {
@@ -349,21 +380,41 @@ isUndefinedOr.type = (value, guard, ...args) => {
349
380
  return isUndefined(value) || (0, exports.isType)(value, guard, ...args);
350
381
  };
351
382
  /**
383
+ * - allows for empty array
352
384
  * @param value
353
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that string have at least 1 non-whitespace character)
354
- * @returns
385
+ * @param elementGuard `function` checks that each element of array, when passeed into this function, returns true
386
+ * - if not provided, then will only check that value is an array
387
+ * @param args `any[]` arguments that will be passed into `elementGuard` e.g. `elementGuard(value[i], ...args)`
355
388
  */
356
- isUndefinedOr.string = (value, requireNonEmpty = true) => {
357
- return isUndefined(value) || requireNonEmpty ? isNonEmptyString(value) : typeof value === "string";
389
+ isUndefinedOr.array = (value, elementGuard, ...args) => {
390
+ return isUndefined(value) || (Array.isArray(value)
391
+ && (!elementGuard || value.every(v => elementGuard(v, ...args))));
358
392
  };
359
393
  /**
360
394
  * @param value
361
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that array have at least 1 element)
362
- * @returns
395
+ * @param requireNonEmpty `boolean` `default` = `false`
396
+ * - `if` `true`, require that string have at least 1 non-whitespace character
397
+ */
398
+ isUndefinedOr.string = (value, requireNonSpace = false) => {
399
+ return isUndefined(value) || isNonEmptyString(value, requireNonSpace);
400
+ };
401
+ /**
402
+ * @param value
403
+ * @param requireNonEmpty `boolean` `default` = `false`
404
+ * - `if` `true`, require that array have at least 1 element
363
405
  */
364
- isUndefinedOr.stringArray = (value, requireNonEmpty = true) => {
406
+ isUndefinedOr.stringArray = (value, requireNonEmpty = false) => {
365
407
  return isUndefined(value) || isStringArray(value, requireNonEmpty);
366
408
  };
409
+ /**
410
+ * @param value `any`
411
+ * @param requireInteger `boolean` `default = false`
412
+ * @param requireNonNegative `boolean` `default = false`
413
+ * @returns **`isNumeric`** `value is string | number`
414
+ * - **`true`** `if` `value` is either a `number` or a `string` that can be casted to a `number`
415
+ * while also meeting the boolean parameter requirements
416
+ * - **`false`** `otherwise`
417
+ */
367
418
  isUndefinedOr.numeric = (value, requireInteger = false, requireNonNegative = false) => {
368
419
  return isUndefined(value) || isNumeric(value, requireInteger, requireNonNegative);
369
420
  };
@@ -374,7 +425,12 @@ isUndefinedOr.number = (value, requireInteger = false, requireNonNegative = fals
374
425
  isUndefinedOr.positiveInteger = (value) => {
375
426
  return (isUndefined(value) || isPositveInteger(value));
376
427
  };
377
- isUndefinedOr.integerArray = (value, requireNonNegative = false, requireNonEmpty = true) => {
428
+ /**
429
+ * @param value
430
+ * @param requireNonNegative `boolean (optional)` `default` = `false`
431
+ * @param requireNonEmpty `boolean (optional)` `default` = `false`
432
+ */
433
+ isUndefinedOr.integerArray = (value, requireNonNegative = false, requireNonEmpty = false) => {
378
434
  return isUndefined(value) || isIntegerArray(value, requireNonNegative, requireNonEmpty);
379
435
  };
380
436
  isUndefinedOr.boolean = (value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeshi",
3
- "version": "1.7.19",
3
+ "version": "2.0.1",
4
4
  "description": "TypeScript utility modules",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,20 +24,21 @@
24
24
  "author": "Andrew Garwood",
25
25
  "license": "MIT",
26
26
  "dependencies": {
27
- "rimraf": "^5.0.0",
28
- "ts-jest": "^29.3.4",
29
- "ts-node": "^10.9.2",
30
- "tslog": "^4.9.3",
31
- "lodash": "^4.17.21",
32
27
  "addresser": "^1.1.20",
33
28
  "csv-parser": "^3.2.0",
34
29
  "fastest-levenshtein": "^1.0.16",
30
+ "lodash": "^4.17.21",
31
+ "rimraf": "^5.0.0",
32
+ "ts-node": "^10.9.2",
33
+ "tslog": "^4.9.3",
35
34
  "xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
36
35
  },
37
36
  "devDependencies": {
37
+ "@jest/globals": "^30.2.0",
38
38
  "@types/jest": "^29.5.14",
39
39
  "@types/node": "^22.15.15",
40
40
  "jest": "^29.7.0",
41
+ "ts-jest": "^29.4.6",
41
42
  "tsconfig-paths": "^4.2.0",
42
43
  "typescript": "^5.0.0"
43
44
  },
@@ -1,12 +0,0 @@
1
- /**
2
- * @file src/utils/regex/types/typeGuards.ts
3
- */
4
- import { CleanStringOptions } from ".";
5
- /**
6
- * - {@link CleanStringOptions}
7
- * @param value `any`
8
- * @returns **`isCleanStringOptions`** `boolean`
9
- * - **`true`** if the `value` is an object with at least one key in `['strip', 'case', 'pad', 'replace']` and no other keys,
10
- * - **`false`** `otherwise`.
11
- */
12
- export declare function isCleanStringOptions(value: any): value is CleanStringOptions;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCleanStringOptions = isCleanStringOptions;
4
- const typeValidation_1 = require("../../typeValidation");
5
- /**
6
- * - {@link CleanStringOptions}
7
- * @param value `any`
8
- * @returns **`isCleanStringOptions`** `boolean`
9
- * - **`true`** if the `value` is an object with at least one key in `['strip', 'case', 'pad', 'replace']` and no other keys,
10
- * - **`false`** `otherwise`.
11
- */
12
- function isCleanStringOptions(value) {
13
- return (value && typeof value === 'object'
14
- && (0, typeValidation_1.hasKeys)(value, ['strip', 'case', 'pad', 'replace'], false, true));
15
- }