typeshi 1.7.15 → 1.7.16

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.
@@ -119,10 +119,21 @@ export declare function getIndexedColumnValues(arg1: string | FileData | Record<
119
119
  export declare function handleFileArgument(arg1: string | FileData | Record<string, any>[], invocationSource: string, requiredHeaders?: string[], sheetName?: string): Promise<Record<string, any>[]>;
120
120
  /**
121
121
  * @param dir `string` path to target directory
122
- * @param targetExtensions `string[] optional` - array of file extensions to filter files by.
122
+ * @param basenameOnly `boolean (optional)` `default` = `false`
123
+ * - `if true`, returned array elements are of form: `path.basename(file)`
124
+ * - `if false`, returned array elements are of form: `path.join(dir, file)`
125
+ * @param targetExtensions `string[] (optional)` - array of file extensions to filter files by.
123
126
  * - `If` not provided, all files in the directory will be returned.
124
127
  * - `If` provided, only files with extensions matching the array will be returned.
125
- * @returns **`targetFiles`** `string[]` array of full file paths
128
+ * @returns **`targetFiles`** `string[]` array of file paths
129
+ */
130
+ export declare function getDirectoryFiles(dir: string, basenameOnly: boolean, ...targetExtensions: string[]): string[];
131
+ /**
132
+ * @param dir `string` path to target directory
133
+ * @param targetExtensions `string[] (optional)` - array of file extensions to filter files by.
134
+ * - `If` not provided, all files in the directory will be returned.
135
+ * - `If` provided, only files with extensions matching the array will be returned.
136
+ * @returns **`targetFiles`** `string[]` array of `full` file paths
126
137
  */
127
138
  export declare function getDirectoryFiles(dir: string, ...targetExtensions: string[]): string[];
128
139
  /**
@@ -136,7 +147,7 @@ export declare function getDirectoryFiles(dir: string, ...targetExtensions: stri
136
147
  */
137
148
  export declare function getOneToManyDictionary(dataSource: string | FileData | Record<string, any>[], keyColumn: string, valueColumn: string, keyOptions?: CleanStringOptions, valueOptions?: CleanStringOptions, sheetName?: string): Promise<Record<string, string[]>>;
138
149
  /**
139
- * @deprecated -> use {@link getOneToManyDictionary}
150
+ * @deprecated `use `{@link getOneToManyDictionary}
140
151
  * @param filePath `string`
141
152
  * @param sheetName `string`
142
153
  * @param keyColumn `string`
@@ -572,25 +572,41 @@ async function handleFileArgument(arg1, invocationSource, requiredHeaders = [],
572
572
  }
573
573
  /**
574
574
  * @param dir `string` path to target directory
575
- * @param targetExtensions `string[] optional` - array of file extensions to filter files by.
575
+ * @param arg2 `boolean (optional)` `default` = `false`
576
+ * - `if true`, returned array elements are of form: `path.basename(file)`
577
+ * - `if false`, returned array elements are of form: `path.join(dir, file)`
578
+ * @param targetExtensions `string[] (optional)` - array of file extensions to filter files by.
576
579
  * - `If` not provided, all files in the directory will be returned.
577
580
  * - `If` provided, only files with extensions matching the array will be returned.
578
- * @returns **`targetFiles`** `string[]` array of full file paths
581
+ * @returns **`targetFiles`** `string[]` array of file paths
579
582
  */
580
- function getDirectoryFiles(dir, ...targetExtensions) {
583
+ function getDirectoryFiles(dir, arg2, ...targetExtensions) {
581
584
  const source = (0, logging_1.getSourceString)(__filename, getDirectoryFiles.name);
582
- validate.existingPathArgument(source, { dir });
583
- validate.arrayArgument(source, { targetExtensions, isNonEmptyString: typeValidation_1.isNonEmptyString }, true);
584
- // ensure all target extensions start with period
585
- for (let i = 0; i < targetExtensions.length; i++) {
586
- const ext = targetExtensions[i];
587
- if (!ext.startsWith('.')) {
588
- targetExtensions[i] = `.${ext}`;
585
+ let basenameOnly = false;
586
+ if ((0, typeValidation_1.isBoolean)(arg2)) {
587
+ basenameOnly = arg2;
588
+ }
589
+ else if ((0, typeValidation_1.isNonEmptyString)(arg2)) {
590
+ targetExtensions = [arg2, ...targetExtensions];
591
+ }
592
+ const targetFiles = [];
593
+ try {
594
+ validate.existingDirectoryArgument(source, { dir });
595
+ validate.arrayArgument(source, { targetExtensions, isNonEmptyString: typeValidation_1.isNonEmptyString }, true);
596
+ // ensure all target extensions start with period
597
+ for (let i = 0; i < targetExtensions.length; i++) {
598
+ const ext = targetExtensions[i];
599
+ if (!ext.startsWith('.')) {
600
+ targetExtensions[i] = `.${ext}`;
601
+ }
589
602
  }
603
+ targetFiles.push(...fs_1.default.readdirSync(dir)
604
+ .filter(f => (0, typeValidation_1.isNonEmptyArray)(targetExtensions)
605
+ ? true // get all files in dir, regardless of extension
606
+ : (0, regex_1.stringEndsWithAnyOf)(f, targetExtensions, regex_1.RegExpFlagsEnum.IGNORE_CASE)).map(f => basenameOnly ? f : node_path_1.default.join(dir, f)));
607
+ }
608
+ catch (error) {
590
609
  }
591
- const targetFiles = fs_1.default.readdirSync(dir).filter(f => (0, typeValidation_1.isNonEmptyArray)(targetExtensions)
592
- ? true // get all files in dir, regardless of extension
593
- : (0, regex_1.stringEndsWithAnyOf)(f, targetExtensions, regex_1.RegExpFlagsEnum.IGNORE_CASE)).map(file => node_path_1.default.join(dir, file));
594
610
  return targetFiles;
595
611
  }
596
612
  /**
@@ -625,7 +641,7 @@ async function getOneToManyDictionary(dataSource, keyColumn, valueColumn, keyOpt
625
641
  return dict;
626
642
  }
627
643
  /**
628
- * @deprecated -> use {@link getOneToManyDictionary}
644
+ * @deprecated `use `{@link getOneToManyDictionary}
629
645
  * @param filePath `string`
630
646
  * @param sheetName `string`
631
647
  * @param keyColumn `string`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "typeshi",
3
- "version": "1.7.15",
3
+ "version": "1.7.16",
4
4
  "description": "TypeScript utility modules",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",