typeshi 2.0.0 → 2.0.2

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.
@@ -720,9 +720,9 @@ function parseExcelForOneToMany(filePath, sheetName, keyColumn, valueColumn, opt
720
720
  function parseCsvForOneToMany(filePath, keyColumn, valueColumn, delimiter = types_1.DelimiterCharacterEnum.COMMA, options = {}) {
721
721
  filePath = coerceFileExtension(filePath, (delimiter === types_1.DelimiterCharacterEnum.TAB) ? 'tsv' : 'csv');
722
722
  const source = `[reading.parseCsvForOneToMany()]`;
723
- validate.existingFileArgument(source, ['.tsv', '.csv'], { filePath });
724
- validate.multipleStringArguments(source, { keyColumn, valueColumn });
725
723
  try {
724
+ validate.existingFileArgument(source, ['.tsv', '.csv'], { filePath });
725
+ validate.multipleStringArguments(source, { keyColumn, valueColumn });
726
726
  const { keyStripOptions, valueStripOptions, keyCaseOptions, valueCaseOptions, keyPadOptions, valuePadOptions } = options;
727
727
  const data = fs_1.default.readFileSync(filePath, 'utf8');
728
728
  const lines = data.split('\n');
@@ -71,7 +71,7 @@ function isFileData(value) {
71
71
  function isDirectoryFileOptions(value) {
72
72
  const candidate = value;
73
73
  return ((0, typeValidation_1.isObject)(candidate, false)
74
- && typeValidation_1.isOptional.stringArray(candidate.targetExtensions)
74
+ && typeValidation_1.isOptional.stringArray(candidate.targetExtensions, false)
75
75
  && typeValidation_1.isOptional.boolean(candidate.basenameOnly)
76
76
  && typeValidation_1.isOptional.boolean(candidate.recursive));
77
77
  }
@@ -151,7 +151,7 @@ function writeListsToCsvSync(listData, outputPath, delimiter = types_1.Delimiter
151
151
  function writeArrayToFileSync(arr, outputPath, separator = '\n', options = { encoding: 'utf-8', flag: 'w' }) {
152
152
  const source = (0, logging_1.getSourceString)(__filename, writeArrayToFileSync.name);
153
153
  try {
154
- const content = arr.map(el => JSON.stringify(el)).join(separator);
154
+ const content = arr.map(el => typeof el === 'string' ? el : JSON.stringify(el)).join(separator);
155
155
  fs.writeFileSync(outputPath, content, options);
156
156
  }
157
157
  catch (error) {
@@ -147,7 +147,7 @@ export declare function isPositveInteger(value: any): value is number;
147
147
  export declare const isType: <T>(value: any, guard: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T;
148
148
  /**
149
149
  * - calls {@link isUndefinedOrNull}`(value)` which allows for value to be `undefined` or `null`
150
- * - use {@link isUndefinedOr} if you want value is `T | undefined`
150
+ * - use {@link isUndefinedOr} if you want `value is T | undefined`
151
151
  */
152
152
  export declare class isOptional {
153
153
  static type: <T>(value: any, guard: (v: any, ...args: any[]) => v is T, ...args: any[]) => value is T | undefined | null;
@@ -168,7 +168,7 @@ export declare class isOptional {
168
168
  static string: (value: any, requireNonSpace?: boolean) => value is string | undefined | null;
169
169
  /**
170
170
  * @param value
171
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that array have at least 1 element)
171
+ * @param requireNonEmpty `boolean` `default` = `false` (if `true`, require that array have at least 1 element)
172
172
  */
173
173
  static stringArray: (value: any, requireNonEmpty?: boolean) => value is string[] | undefined | null;
174
174
  /**
@@ -183,6 +183,11 @@ export declare class isOptional {
183
183
  static numeric: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is string | number | undefined | null;
184
184
  static number: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is number | undefined | null;
185
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
+ */
186
191
  static integerArray: (value: any, requireNonNegative?: boolean, requireNonEmpty?: boolean) => value is number[] | undefined | null;
187
192
  static boolean: (value: any) => value is boolean | undefined | null;
188
193
  static function: (value: any) => value is Function | undefined | null;
@@ -205,7 +210,7 @@ export declare class isUndefinedOr {
205
210
  static string: (value: any, requireNonSpace?: boolean) => value is string | undefined;
206
211
  /**
207
212
  * @param value
208
- * @param requireNonEmpty `boolean` `default` = `true`
213
+ * @param requireNonEmpty `boolean` `default` = `false`
209
214
  * - `if` `true`, require that array have at least 1 element
210
215
  */
211
216
  static stringArray: (value: any, requireNonEmpty?: boolean) => value is string[] | undefined;
@@ -221,6 +226,11 @@ export declare class isUndefinedOr {
221
226
  static numeric: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is string | number | undefined;
222
227
  static number: (value: any, requireInteger?: boolean, requireNonNegative?: boolean) => value is number | undefined;
223
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
+ */
224
234
  static integerArray: (value: any, requireNonNegative?: boolean, requireNonEmpty?: boolean) => value is number[] | undefined;
225
235
  static boolean: (value: any) => value is boolean | undefined;
226
236
  static function: (value: any) => value is Function | undefined;
@@ -305,7 +305,7 @@ const isType = (value, guard, ...args) => {
305
305
  exports.isType = isType;
306
306
  /**
307
307
  * - calls {@link isUndefinedOrNull}`(value)` which allows for value to be `undefined` or `null`
308
- * - use {@link isUndefinedOr} if you want value is `T | undefined`
308
+ * - use {@link isUndefinedOr} if you want `value is T | undefined`
309
309
  */
310
310
  class isOptional {
311
311
  }
@@ -335,9 +335,9 @@ isOptional.string = (value, requireNonSpace = false) => {
335
335
  };
336
336
  /**
337
337
  * @param value
338
- * @param requireNonEmpty `boolean` `default` = `true` (if `true`, require that array have at least 1 element)
338
+ * @param requireNonEmpty `boolean` `default` = `false` (if `true`, require that array have at least 1 element)
339
339
  */
340
- isOptional.stringArray = (value, requireNonEmpty = true) => {
340
+ isOptional.stringArray = (value, requireNonEmpty = false) => {
341
341
  return isUndefinedOrNull(value) || isStringArray(value, requireNonEmpty);
342
342
  };
343
343
  /**
@@ -359,7 +359,12 @@ isOptional.number = (value, requireInteger = false, requireNonNegative = false)
359
359
  isOptional.positiveInteger = (value) => {
360
360
  return (isUndefinedOrNull(value) || isPositveInteger(value));
361
361
  };
362
- 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) => {
363
368
  return isUndefinedOrNull(value) || isIntegerArray(value, requireNonNegative, requireNonEmpty);
364
369
  };
365
370
  isOptional.boolean = (value) => {
@@ -395,10 +400,10 @@ isUndefinedOr.string = (value, requireNonSpace = false) => {
395
400
  };
396
401
  /**
397
402
  * @param value
398
- * @param requireNonEmpty `boolean` `default` = `true`
403
+ * @param requireNonEmpty `boolean` `default` = `false`
399
404
  * - `if` `true`, require that array have at least 1 element
400
405
  */
401
- isUndefinedOr.stringArray = (value, requireNonEmpty = true) => {
406
+ isUndefinedOr.stringArray = (value, requireNonEmpty = false) => {
402
407
  return isUndefined(value) || isStringArray(value, requireNonEmpty);
403
408
  };
404
409
  /**
@@ -420,7 +425,12 @@ isUndefinedOr.number = (value, requireInteger = false, requireNonNegative = fals
420
425
  isUndefinedOr.positiveInteger = (value) => {
421
426
  return (isUndefined(value) || isPositveInteger(value));
422
427
  };
423
- 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) => {
424
434
  return isUndefined(value) || isIntegerArray(value, requireNonNegative, requireNonEmpty);
425
435
  };
426
436
  isUndefinedOr.boolean = (value) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeshi",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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
  },