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.
@@ -810,22 +810,3 @@ function getSourceString(fileName, func, funcInfo, startLine, endLine) {
810
810
  let funcName = typeof func === 'string' ? func : func.name;
811
811
  return `[${fileName}.${funcName}(${(0, typeValidation_1.isNonEmptyString)(funcInfo) ? ` ${funcInfo} ` : ''})${lineNumberText}]`;
812
812
  }
813
- // isEnumArgumentOptions,
814
- // isEnumObject,
815
- // isObjectArgumentOptions,
816
- // const validate = {
817
- // stringArgument,
818
- // multipleStringArguments,
819
- // numericStringArgument,
820
- // booleanArgument,
821
- // numberArgument,
822
- // arrayArgument,
823
- // enumArgument,
824
- // objectArgument,
825
- // functionArgument,
826
- // existingPathArgument,
827
- // existingDirectoryArgument,
828
- // existingFileArgument,
829
- // multipleExistingFileArguments
830
- // }
831
- // export default validate;
@@ -107,20 +107,20 @@ function autoFormatLogsOnExit(filePaths) {
107
107
  * @returns `void`
108
108
  */
109
109
  function formatDebugLogFile(inputPath, outputPath) {
110
- validate.existingPathArgument(`logging.formatDebugLogFile`, { inputPath });
111
- // Generate output path if not provided
112
- if (!outputPath) {
113
- const parsedPath = node_path_1.default.parse(inputPath);
114
- outputPath = node_path_1.default.join(parsedPath.dir, `${parsedPath.name}.FORMATTED${parsedPath.ext}`);
115
- }
110
+ const source = getSourceString(__filename, formatAllDebugLogs.name);
116
111
  try {
112
+ validate.existingPathArgument(source, { inputPath });
113
+ if (!outputPath) { // Generate output path if not provided
114
+ const parsedPath = node_path_1.default.parse(inputPath);
115
+ outputPath = node_path_1.default.join(parsedPath.dir, `${parsedPath.name}.FORMATTED${parsedPath.ext}`);
116
+ }
117
117
  const fileContent = fs.readFileSync(inputPath, 'utf-8');
118
118
  const formattedContent = formatLogContent(fileContent);
119
119
  fs.writeFileSync(outputPath, formattedContent, { encoding: 'utf-8' });
120
120
  // mlog.info(`[formatDebugLogFile()] Formatted log file saved to '${outputPath}'`);
121
121
  }
122
122
  catch (error) {
123
- setupLog_1.typeshiLogger.error('[formatDebugLogFile()] Error formatting log file:', error);
123
+ setupLog_1.typeshiLogger.error(`${source} Error formatting log file:'`, error);
124
124
  throw error;
125
125
  }
126
126
  }
@@ -130,7 +130,7 @@ function formatDebugLogFile(inputPath, outputPath) {
130
130
  * @returns `string` - the formatted content
131
131
  */
132
132
  function formatLogContent(content) {
133
- const lines = content.split('\n');
133
+ const lines = content.split('\n'); //.map(s=>applyStripOptions(s, {char: `"`}));
134
134
  const formattedLines = [];
135
135
  let currentJsonObject = '';
136
136
  let insideJsonObject = false;
@@ -1,4 +1,4 @@
1
- import { StringCaseOptions, StringPadOptions, StringStripOptions, CleanStringOptions } from "../regex";
1
+ import { DEP_StringCaseOptions, DEP_StringStripOptions, DEP_CleanStringOptions, DEP_StringPadOptions } from "../regex";
2
2
  import { DirectoryFileOptions, FileData, FileExtension } from "./types/Io";
3
3
  import { DelimiterCharacterEnum } from "./types";
4
4
  /** checks if `pathString (value)` points to an existing directory */
@@ -95,7 +95,7 @@ export declare function getCsvRows(arg1: FileData | string): Promise<Record<stri
95
95
  * @param valueColumn `string` - the column name whose contents will be used as values in the dictionary.
96
96
  * @returns **`dict`** `Record<string, string>`
97
97
  */
98
- export declare function getOneToOneDictionary(arg1: string | Record<string, any>[] | FileData, keyColumn: string, valueColumn: string, keyOptions?: CleanStringOptions, valueOptions?: CleanStringOptions, requireIncludeAllRows?: boolean): Promise<Record<string, string>>;
98
+ export declare function getOneToOneDictionary(arg1: string | Record<string, any>[] | FileData, keyColumn: string, valueColumn: string, keyOptions?: DEP_CleanStringOptions, valueOptions?: DEP_CleanStringOptions, requireIncludeAllRows?: boolean): Promise<Record<string, string>>;
99
99
  /**
100
100
  * @param arg1 `string | FileData | Record<string, any>[]` - the `filePath` to a CSV file or an array of rows.
101
101
  * @param columnName `string` - the column name whose values will be returned.
@@ -159,12 +159,12 @@ export declare function getDirectoryFiles(dir: string, options: DirectoryFileOpt
159
159
  * @param dataSource `string | FileData | Record<string, any>[]`
160
160
  * @param keyColumn `string`
161
161
  * @param valueColumn `string`
162
- * @param keyOptions {@link CleanStringOptions} `(optional)`
163
- * @param valueOptions {@link CleanStringOptions}`(optional)`
162
+ * @param keyOptions {@link DEP_CleanStringOptions} `(optional)`
163
+ * @param valueOptions {@link DEP_CleanStringOptions}`(optional)`
164
164
  * @param sheetName `string`
165
165
  * @returns **`dict`** `Promise<Record<string, string[]>>`
166
166
  */
167
- export declare function getOneToManyDictionary(dataSource: string | FileData | Record<string, any>[], keyColumn: string, valueColumn: string, keyOptions?: CleanStringOptions, valueOptions?: CleanStringOptions, sheetName?: string): Promise<Record<string, string[]>>;
167
+ export declare function getOneToManyDictionary(dataSource: string | FileData | Record<string, any>[], keyColumn: string, valueColumn: string, keyOptions?: DEP_CleanStringOptions, valueOptions?: DEP_CleanStringOptions, sheetName?: string): Promise<Record<string, string[]>>;
168
168
  /**
169
169
  * @deprecated `use `{@link getOneToManyDictionary}
170
170
  * @param filePath `string`
@@ -172,19 +172,19 @@ export declare function getOneToManyDictionary(dataSource: string | FileData | R
172
172
  * @param keyColumn `string`
173
173
  * @param valueColumn `string`
174
174
  * @param options - {@link ParseOneToManyOptions}
175
- * = `{ keyStripOptions`?: {@link StringStripOptions}, `valueStripOptions`?: {@link StringStripOptions}, keyCaseOptions`?: {@link StringCaseOptions}, `valueCaseOptions`?: {@link StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
176
- * - {@link StringStripOptions} = `{ char`: `string`, `escape`?: `boolean`, `stripLeftCondition`?: `(s: string, ...args: any[]) => boolean`, `leftArgs`?: `any[]`, `stripRightCondition`?: `(s: string, ...args: any[]) => boolean`, `rightArgs`?: `any[] }`
177
- * - {@link StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
175
+ * = `{ keyStripOptions`?: {@link DEP_StringStripOptions}, `valueStripOptions`?: {@link DEP_StringStripOptions}, keyCaseOptions`?: {@link StringCaseOptions}, `valueCaseOptions`?: {@link StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
176
+ * - {@link DEP_StringStripOptions} = `{ char`: `string`, `escape`?: `boolean`, `stripLeftCondition`?: `(s: string, ...args: any[]) => boolean`, `leftArgs`?: `any[]`, `stripRightCondition`?: `(s: string, ...args: any[]) => boolean`, `rightArgs`?: `any[] }`
177
+ * - {@link DEP_StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
178
178
  * - {@link StringPadOptions} = `{ padLength`: `number`, `padChar`?: `string`, `padLeft`?: `boolean`, `padRight`?: `boolean }`
179
179
  * @returns **`dict`** `Record<string, Array<string>>` — key-value pairs where key is from `keyColumn` and value is an array of values from `valueColumn`
180
180
  */
181
181
  export declare function parseExcelForOneToMany(filePath: string, sheetName: string, keyColumn: string, valueColumn: string, options?: {
182
- keyStripOptions?: StringStripOptions;
183
- valueStripOptions?: StringStripOptions;
184
- keyCaseOptions?: StringCaseOptions;
185
- valueCaseOptions?: StringCaseOptions;
186
- keyPadOptions?: StringPadOptions;
187
- valuePadOptions?: StringPadOptions;
182
+ keyStripOptions?: DEP_StringStripOptions;
183
+ valueStripOptions?: DEP_StringStripOptions;
184
+ keyCaseOptions?: DEP_StringCaseOptions;
185
+ valueCaseOptions?: DEP_StringCaseOptions;
186
+ keyPadOptions?: DEP_StringPadOptions;
187
+ valuePadOptions?: DEP_StringPadOptions;
188
188
  }): Record<string, Array<string>>;
189
189
  /**
190
190
  * @deprecated -> use {@link getOneToManyDictionary}
@@ -193,18 +193,18 @@ export declare function parseExcelForOneToMany(filePath: string, sheetName: stri
193
193
  * @param valueColumn `string`
194
194
  * @param delimiter {@link DelimiterCharacters} | `string`
195
195
  * @param options {@link ParseOneToManyOptions}
196
- * = `{ keyCaseOptions`?: {@link StringCaseOptions}, `valueCaseOptions`?: {@link StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
197
- * - {@link StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
196
+ * = `{ keyCaseOptions`?: {@link DEP_StringCaseOptions}, `valueCaseOptions`?: {@link DEP_StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
197
+ * - {@link DEP_StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
198
198
  * - {@link StringPadOptions} = `{ padLength`: `number`, `padChar`?: `string`, `padLeft`?: `boolean`, `padRight`?: `boolean }`
199
199
  * @returns `Record<string, Array<string>>` - key-value pairs where key is from `keyColumn` and value is an array of values from `valueColumn`
200
200
  */
201
201
  export declare function parseCsvForOneToMany(filePath: string, keyColumn: string, valueColumn: string, delimiter?: DelimiterCharacterEnum | string, options?: {
202
- keyStripOptions?: StringStripOptions;
203
- valueStripOptions?: StringStripOptions;
204
- keyCaseOptions?: StringCaseOptions;
205
- valueCaseOptions?: StringCaseOptions;
206
- keyPadOptions?: StringPadOptions;
207
- valuePadOptions?: StringPadOptions;
202
+ keyStripOptions?: DEP_StringStripOptions;
203
+ valueStripOptions?: DEP_StringStripOptions;
204
+ keyCaseOptions?: DEP_StringCaseOptions;
205
+ valueCaseOptions?: DEP_StringCaseOptions;
206
+ keyPadOptions?: DEP_StringPadOptions;
207
+ valuePadOptions?: DEP_StringPadOptions;
208
208
  }): Record<string, Array<string>>;
209
209
  export interface CsvValidationOptions {
210
210
  allowEmptyRows?: boolean;
@@ -446,8 +446,8 @@ async function getOneToOneDictionary(arg1, keyColumn, valueColumn, keyOptions, v
446
446
  config_1.typeshiLogger.warn(msg);
447
447
  continue;
448
448
  }
449
- const key = (0, regex_1.clean)(String(row[keyColumn]), keyOptions);
450
- const value = (0, regex_1.clean)(String(row[valueColumn]), valueOptions);
449
+ const key = (0, regex_1.DEP_clean)(String(row[keyColumn]), keyOptions);
450
+ const value = (0, regex_1.DEP_clean)(String(row[valueColumn]), valueOptions);
451
451
  if (!key || !value) {
452
452
  let msg = [`${source} Row @ index ${i} missing key or value.`,
453
453
  ` keyColumn: '${keyColumn}' in row ? ${keyColumn in row}`,
@@ -639,8 +639,8 @@ function getDirectoryFiles(dir, arg2, ...targetExtensions) {
639
639
  * @param dataSource `string | FileData | Record<string, any>[]`
640
640
  * @param keyColumn `string`
641
641
  * @param valueColumn `string`
642
- * @param keyOptions {@link CleanStringOptions} `(optional)`
643
- * @param valueOptions {@link CleanStringOptions}`(optional)`
642
+ * @param keyOptions {@link DEP_CleanStringOptions} `(optional)`
643
+ * @param valueOptions {@link DEP_CleanStringOptions}`(optional)`
644
644
  * @param sheetName `string`
645
645
  * @returns **`dict`** `Promise<Record<string, string[]>>`
646
646
  */
@@ -648,18 +648,18 @@ async function getOneToManyDictionary(dataSource, keyColumn, valueColumn, keyOpt
648
648
  const source = (0, logging_1.getSourceString)(__filename, getOneToManyDictionary.name);
649
649
  validate.multipleStringArguments(source, { keyColumn, valueColumn });
650
650
  if (keyOptions)
651
- validate.objectArgument(source, { keyOptions, isCleanStringOptions: regex_1.isCleanStringOptions });
651
+ validate.objectArgument(source, { keyOptions, DEP_isCleanStringOptions: regex_1.DEP_isCleanStringOptions });
652
652
  if (valueOptions)
653
- validate.objectArgument(source, { valueOptions, isCleanStringOptions: regex_1.isCleanStringOptions });
653
+ validate.objectArgument(source, { valueOptions, DEP_isCleanStringOptions: regex_1.DEP_isCleanStringOptions });
654
654
  const rows = await handleFileArgument(dataSource, source, [keyColumn, valueColumn], sheetName);
655
655
  const dict = {};
656
656
  for (let i = 0; i < rows.length; i++) {
657
657
  let row = rows[i];
658
- let key = (0, regex_1.clean)(row[keyColumn], keyOptions).trim().replace(/\.$/, '');
658
+ let key = (0, regex_1.DEP_clean)(row[keyColumn], keyOptions).trim().replace(/\.$/, '');
659
659
  if (!dict[key]) {
660
660
  dict[key] = [];
661
661
  }
662
- let value = (0, regex_1.clean)(row[valueColumn], valueOptions).trim().replace(/\.$/, '');
662
+ let value = (0, regex_1.DEP_clean)(row[valueColumn], valueOptions).trim().replace(/\.$/, '');
663
663
  if (!dict[key].includes(value)) {
664
664
  dict[key].push(value);
665
665
  }
@@ -673,9 +673,9 @@ async function getOneToManyDictionary(dataSource, keyColumn, valueColumn, keyOpt
673
673
  * @param keyColumn `string`
674
674
  * @param valueColumn `string`
675
675
  * @param options - {@link ParseOneToManyOptions}
676
- * = `{ keyStripOptions`?: {@link StringStripOptions}, `valueStripOptions`?: {@link StringStripOptions}, keyCaseOptions`?: {@link StringCaseOptions}, `valueCaseOptions`?: {@link StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
677
- * - {@link StringStripOptions} = `{ char`: `string`, `escape`?: `boolean`, `stripLeftCondition`?: `(s: string, ...args: any[]) => boolean`, `leftArgs`?: `any[]`, `stripRightCondition`?: `(s: string, ...args: any[]) => boolean`, `rightArgs`?: `any[] }`
678
- * - {@link StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
676
+ * = `{ keyStripOptions`?: {@link DEP_StringStripOptions}, `valueStripOptions`?: {@link DEP_StringStripOptions}, keyCaseOptions`?: {@link StringCaseOptions}, `valueCaseOptions`?: {@link StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
677
+ * - {@link DEP_StringStripOptions} = `{ char`: `string`, `escape`?: `boolean`, `stripLeftCondition`?: `(s: string, ...args: any[]) => boolean`, `leftArgs`?: `any[]`, `stripRightCondition`?: `(s: string, ...args: any[]) => boolean`, `rightArgs`?: `any[] }`
678
+ * - {@link DEP_StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
679
679
  * - {@link StringPadOptions} = `{ padLength`: `number`, `padChar`?: `string`, `padLeft`?: `boolean`, `padRight`?: `boolean }`
680
680
  * @returns **`dict`** `Record<string, Array<string>>` — key-value pairs where key is from `keyColumn` and value is an array of values from `valueColumn`
681
681
  */
@@ -689,8 +689,8 @@ function parseExcelForOneToMany(filePath, sheetName, keyColumn, valueColumn, opt
689
689
  const jsonData = xlsx_1.default.utils.sheet_to_json(sheet);
690
690
  const dict = {};
691
691
  jsonData.forEach(row => {
692
- let key = (0, regex_1.clean)(String(row[keyColumn]), keyStripOptions, keyCaseOptions, keyPadOptions).trim().replace(/\.$/, '');
693
- let val = (0, regex_1.clean)(String(row[valueColumn]), valueStripOptions, valueCaseOptions, valuePadOptions).trim().replace(/\.$/, '');
692
+ let key = (0, regex_1.DEP_clean)(String(row[keyColumn]), keyStripOptions, keyCaseOptions, keyPadOptions).trim().replace(/\.$/, '');
693
+ let val = (0, regex_1.DEP_clean)(String(row[valueColumn]), valueStripOptions, valueCaseOptions, valuePadOptions).trim().replace(/\.$/, '');
694
694
  if (!dict[key]) {
695
695
  dict[key] = [];
696
696
  }
@@ -712,17 +712,17 @@ function parseExcelForOneToMany(filePath, sheetName, keyColumn, valueColumn, opt
712
712
  * @param valueColumn `string`
713
713
  * @param delimiter {@link DelimiterCharacters} | `string`
714
714
  * @param options {@link ParseOneToManyOptions}
715
- * = `{ keyCaseOptions`?: {@link StringCaseOptions}, `valueCaseOptions`?: {@link StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
716
- * - {@link StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
715
+ * = `{ keyCaseOptions`?: {@link DEP_StringCaseOptions}, `valueCaseOptions`?: {@link DEP_StringCaseOptions}, `keyPadOptions`?: {@link StringPadOptions}, `valuePadOptions`?: {@link StringPadOptions} `}`
716
+ * - {@link DEP_StringCaseOptions} = `{ toUpper`?: `boolean`, `toLower`?: `boolean`, `toTitle`?: `boolean }`
717
717
  * - {@link StringPadOptions} = `{ padLength`: `number`, `padChar`?: `string`, `padLeft`?: `boolean`, `padRight`?: `boolean }`
718
718
  * @returns `Record<string, Array<string>>` - key-value pairs where key is from `keyColumn` and value is an array of values from `valueColumn`
719
719
  */
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');
@@ -736,8 +736,8 @@ function parseCsvForOneToMany(filePath, keyColumn, valueColumn, delimiter = type
736
736
  for (let i = 1; i < lines.length; i++) {
737
737
  const line = lines[i].split(delimiter).map(col => col.trim());
738
738
  if (line.length > 1) {
739
- let key = (0, regex_1.clean)(line[keyIndex], keyStripOptions, keyCaseOptions, keyPadOptions);
740
- let val = (0, regex_1.clean)(line[valueIndex], valueStripOptions, valueCaseOptions, valuePadOptions);
739
+ let key = (0, regex_1.DEP_clean)(line[keyIndex], keyStripOptions, keyCaseOptions, keyPadOptions);
740
+ let val = (0, regex_1.DEP_clean)(line[valueIndex], valueStripOptions, valueCaseOptions, valuePadOptions);
741
741
  if (!dict[key]) {
742
742
  dict[key] = [];
743
743
  }
@@ -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
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @file src/utils/io/Io.ts
3
3
  */
4
- import { StringCaseOptions, StringPadOptions, StringStripOptions } from "../../regex/index";
4
+ import { DEP_StringCaseOptions, StringPadOptions, DEP_StringStripOptions } from "../../regex/index";
5
5
  export type WriteJsonOptions = {
6
6
  data: Record<string, any> | string;
7
7
  filePath: string;
@@ -26,7 +26,7 @@ export type RowDictionary = {
26
26
  [rowIndex: number]: Record<string, any>;
27
27
  };
28
28
  /**
29
- * @deprecated use `CleanStringOptions` instead
29
+ * @deprecated
30
30
  * @typedefn **`ParseOneToManyOptions`**
31
31
  * @property {StringStripOptions} keyStripOptions - options for stripping characters from the key
32
32
  * @property {StringStripOptions} valueStripOptions - options for stripping characters from the value
@@ -35,15 +35,15 @@ export type RowDictionary = {
35
35
  * @property {StringPadOptions} keyPadOptions - options for padding values read from the `keyColumn`
36
36
  * @property {StringPadOptions} valuePadOptions - options for padding values read from the `valueColumn`
37
37
  *
38
- * - {@link StringStripOptions} = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
39
- * - {@link StringCaseOptions} = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
38
+ * - {@link DEP_StringStripOptions} = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
39
+ * - {@link DEP_StringCaseOptions} = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
40
40
  * - {@link StringPadOptions} = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
41
41
  */
42
42
  export type ParseOneToManyOptions = {
43
- keyStripOptions?: StringStripOptions;
44
- valueStripOptions?: StringStripOptions;
45
- keyCaseOptions?: StringCaseOptions;
46
- valueCaseOptions?: StringCaseOptions;
43
+ keyStripOptions?: DEP_StringStripOptions;
44
+ valueStripOptions?: DEP_StringStripOptions;
45
+ keyCaseOptions?: DEP_StringCaseOptions;
46
+ valueCaseOptions?: DEP_StringCaseOptions;
47
47
  keyPadOptions?: StringPadOptions;
48
48
  valuePadOptions?: StringPadOptions;
49
49
  };
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @file src/utils/regex/Str.ts
3
+ */
4
+ import { stringStartsWithAnyOf, stringEndsWithAnyOf, stringContainsAnyOf, equivalentAlphanumericStrings } from "./stringOperations";
5
+ import { applyCaseOptions, applyReplaceParams, clean as cleanString, applyStripOptions, applyPadOptions } from "./cleaning";
6
+ export declare class Str {
7
+ /**
8
+ * @param s `string`
9
+ * @param prefixes `string | string[] | RegExp` possible starting string(s).
10
+ * @param flags `RegExpFlagsEnum[] (Optional)` regex flags to use when creating the {@link RegExp} object. see {@link RegExpFlagsEnum}
11
+ * @returns **`true`** if the string starts with any of the prefixes, **`false`** otherwise.
12
+ */
13
+ static startsWith: typeof stringStartsWithAnyOf;
14
+ /**
15
+ * Checks if a string ends with any of the specified suffixes.
16
+ * @param s `string`
17
+ * @param suffixes `string | string[] | RegExp` possible ending strings.
18
+ * @param flags `RegExpFlagsEnum[] (Optional)` regex flags to use when creating the {@link RegExp} object. see {@link RegExpFlagsEnum}
19
+ * @returns **`true`** if the string ends with any of the suffixes, **`false`** otherwise.
20
+ */
21
+ static endsWith: typeof stringEndsWithAnyOf;
22
+ /**
23
+ * @param s `string`
24
+ * @param substrings `string | string[] | RegExp`
25
+ * @param flags `RegExpFlagsEnum[] (Optional)` regex flags to use when creating the {@link RegExp} object. see {@link RegExpFlagsEnum}
26
+ * @returns **`true`** if the string contains any of the substrings, **`false`** otherwise.
27
+ */
28
+ static contains: typeof stringContainsAnyOf;
29
+ /**
30
+ * Ignores case by default:
31
+ * - converts `s1` & `s2` to lowercase and removes all non-alphanumeric characters from both strings,
32
+ * - sorts the characters in both strings,
33
+ * - then compares the two strings for equivalence.
34
+ * @param s1 `string`
35
+ * @param s2 `string`
36
+ * @param tolerance `number` - a number between 0 and 1, default is `0.90`
37
+ * @returns **`boolean`**
38
+ * - **`true`** `if` the two alphanumeric strings are equivalent,
39
+ * - **`false`** `otherwise`.
40
+ */
41
+ static equivalentAlphanumeric: typeof equivalentAlphanumericStrings;
42
+ /**
43
+ * @param s `string`
44
+ * @param options {@link StringCleanOptions} `(optional)`
45
+ * @param options.useDefault `boolean (optional)` `default` = `true`
46
+ * - `if true` - calls `s.trim()` and replaces `/\s{2,}/g` with single space, `/\.{2,}/g` with single period, and `/,{2,}/g` with single comma
47
+ * *before* proceeding with remaining operations
48
+ * @returns **`s`** `string` = the modified string after applying operations specified in `options`
49
+ */
50
+ static clean: typeof cleanString;
51
+ /**
52
+ * @param s `string`
53
+ * @param caseOptions {@link StringCaseEnum} = 'upper' | 'lower' | 'title'
54
+ * @returns **`s`** `string` with case option applied
55
+ */
56
+ static toCase: typeof applyCaseOptions;
57
+ /**
58
+ * @param s `string`
59
+ * @param options {@link StringPadOptions}
60
+ * @param options.side `'left' | 'right' | 'both'`
61
+ * - `left` -> use `s.padStart()`
62
+ * - `right` -> use `s.padEnd()`
63
+ * - `both` -> apply half padding to both sides
64
+ * @returns **`s`** `string` padded to length = `options.maxLength`
65
+ */
66
+ static pad: typeof applyPadOptions;
67
+ /**
68
+ * @param s `string`
69
+ * @param replaceParams `Array<`{@link StringReplaceParams}`>`
70
+ * @returns **`s`** `string` with replace options applied
71
+ */
72
+ static replace: typeof applyReplaceParams;
73
+ /**
74
+ * @param s `string`
75
+ * @param options {@link StringStripOptions} = `{ char?: string, left?: StringStripCondition, right?: StringStripCondition }`
76
+ * @returns **`s`**
77
+ */
78
+ static strip: typeof applyStripOptions;
79
+ }
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ /**
3
+ * @file src/utils/regex/Str.ts
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Str = void 0;
7
+ const stringOperations_1 = require("./stringOperations");
8
+ const cleaning_1 = require("./cleaning");
9
+ class Str {
10
+ }
11
+ exports.Str = Str;
12
+ /**
13
+ * @param s `string`
14
+ * @param prefixes `string | string[] | RegExp` possible starting string(s).
15
+ * @param flags `RegExpFlagsEnum[] (Optional)` regex flags to use when creating the {@link RegExp} object. see {@link RegExpFlagsEnum}
16
+ * @returns **`true`** if the string starts with any of the prefixes, **`false`** otherwise.
17
+ */
18
+ Str.startsWith = stringOperations_1.stringStartsWithAnyOf;
19
+ /**
20
+ * Checks if a string ends with any of the specified suffixes.
21
+ * @param s `string`
22
+ * @param suffixes `string | string[] | RegExp` possible ending strings.
23
+ * @param flags `RegExpFlagsEnum[] (Optional)` regex flags to use when creating the {@link RegExp} object. see {@link RegExpFlagsEnum}
24
+ * @returns **`true`** if the string ends with any of the suffixes, **`false`** otherwise.
25
+ */
26
+ Str.endsWith = stringOperations_1.stringEndsWithAnyOf;
27
+ /**
28
+ * @param s `string`
29
+ * @param substrings `string | string[] | RegExp`
30
+ * @param flags `RegExpFlagsEnum[] (Optional)` regex flags to use when creating the {@link RegExp} object. see {@link RegExpFlagsEnum}
31
+ * @returns **`true`** if the string contains any of the substrings, **`false`** otherwise.
32
+ */
33
+ Str.contains = stringOperations_1.stringContainsAnyOf;
34
+ /**
35
+ * Ignores case by default:
36
+ * - converts `s1` & `s2` to lowercase and removes all non-alphanumeric characters from both strings,
37
+ * - sorts the characters in both strings,
38
+ * - then compares the two strings for equivalence.
39
+ * @param s1 `string`
40
+ * @param s2 `string`
41
+ * @param tolerance `number` - a number between 0 and 1, default is `0.90`
42
+ * @returns **`boolean`**
43
+ * - **`true`** `if` the two alphanumeric strings are equivalent,
44
+ * - **`false`** `otherwise`.
45
+ */
46
+ Str.equivalentAlphanumeric = stringOperations_1.equivalentAlphanumericStrings;
47
+ /**
48
+ * @param s `string`
49
+ * @param options {@link StringCleanOptions} `(optional)`
50
+ * @param options.useDefault `boolean (optional)` `default` = `true`
51
+ * - `if true` - calls `s.trim()` and replaces `/\s{2,}/g` with single space, `/\.{2,}/g` with single period, and `/,{2,}/g` with single comma
52
+ * *before* proceeding with remaining operations
53
+ * @returns **`s`** `string` = the modified string after applying operations specified in `options`
54
+ */
55
+ Str.clean = cleaning_1.clean;
56
+ /**
57
+ * @param s `string`
58
+ * @param caseOptions {@link StringCaseEnum} = 'upper' | 'lower' | 'title'
59
+ * @returns **`s`** `string` with case option applied
60
+ */
61
+ Str.toCase = cleaning_1.applyCaseOptions;
62
+ /**
63
+ * @param s `string`
64
+ * @param options {@link StringPadOptions}
65
+ * @param options.side `'left' | 'right' | 'both'`
66
+ * - `left` -> use `s.padStart()`
67
+ * - `right` -> use `s.padEnd()`
68
+ * - `both` -> apply half padding to both sides
69
+ * @returns **`s`** `string` padded to length = `options.maxLength`
70
+ */
71
+ Str.pad = cleaning_1.applyPadOptions;
72
+ /**
73
+ * @param s `string`
74
+ * @param replaceParams `Array<`{@link StringReplaceParams}`>`
75
+ * @returns **`s`** `string` with replace options applied
76
+ */
77
+ Str.replace = cleaning_1.applyReplaceParams;
78
+ /**
79
+ * @param s `string`
80
+ * @param options {@link StringStripOptions} = `{ char?: string, left?: StringStripCondition, right?: StringStripCondition }`
81
+ * @returns **`s`**
82
+ */
83
+ Str.strip = cleaning_1.applyStripOptions;
@@ -1,48 +1,43 @@
1
- import { CleanStringOptions, StringCaseOptions, StringPadOptions, StringReplaceOptions, StringStripOptions } from "./";
2
- export declare function clean(s: string, options?: CleanStringOptions): string;
1
+ import { DEP_CleanStringOptions, DEP_StringCaseOptions, DEP_StringPadOptions, StringCaseEnum, StringPadOptions, StringReplaceOptions, DEP_StringStripOptions, StringCleanOptions, StringReplaceParams, StringStripOptions } from "./types";
3
2
  /**
4
- * @description
5
- * - converts to string and trims, then:
6
- * - applies options in this order: `StringReplaceOptions`, `StringStripOptions`, `StringCaseOptions`, `StringPadOptions`
7
- * - Removes leading+trailing spaces, extra spaces, commas, and dots from a string (e.g. `'..'` becomes `'.'`)
8
- * - optionally applies 4 option params with: {@link string.replace}, {@link applyStripOptions}, {@link applyCaseOptions}, and {@link applyPadOptions}.
9
- * @param s `string` to clean
10
- * @param stripOptions {@link StringStripOptions}
11
- * - `optional` strip options to apply to the string
12
- * - = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
13
- * @param caseOptions {@link StringCaseOptions}
14
- * - `optional` case options to apply to the string
15
- * - = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
16
- * @param padOptions {@link StringPadOptions}
17
- * - `optional` padding options to apply to the string
18
- * - = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
19
- * @param replaceOptions {@link StringReplaceOptions}
20
- * - `optional` replace options to apply to the string
21
- * - = `Array<`{@link StringReplaceParams}`>` = `{ searchValue: string | RegExp, replaceValue: string }[]`
22
- * @returns **`s`** `string`
3
+ * @param s `string`
4
+ * @param options {@link StringCleanOptions} `(optional)`
5
+ * @param options.useDefault `boolean (optional)` `default` = `true`
6
+ * - `if true` - calls `s.trim()` and replaces `/\s{2,}/g` with single space, `/\.{2,}/g` with single period, and `/,{2,}/g` with single comma
7
+ * *before* proceeding with remaining operations
8
+ * @returns **`s`** `string` = the modified string after applying operations specified in `options`
23
9
  */
24
- export declare function clean(s: string, stripOptions?: StringStripOptions, caseOptions?: StringCaseOptions, padOptions?: StringPadOptions, replaceOptions?: StringReplaceOptions): string;
10
+ export declare function clean(s: string, options?: StringCleanOptions): string;
25
11
  /**
26
- * @param s `string` - the string to convert to title case
27
- * @returns **`s`** `string` - the string in title case
28
- * (i.e. first letter of each word, determined by the `\b` boundary metacharacter, is capitalized)
12
+ * @param s `string`
13
+ * @param options {@link StringStripOptions} = `{ char?: string, left?: StringStripCondition, right?: StringStripCondition }`
14
+ * @returns **`s`**
29
15
  */
30
- export declare function toTitleCase(s: string): string;
16
+ export declare function applyStripOptions(s: string, options: StringStripOptions): string;
31
17
  /**
32
18
  * @param s `string`
33
- * @param replaceOptions `Array<`{@link StringReplaceParams}`>`
19
+ * @param replaceParams `Array<`{@link StringReplaceParams}`>`
34
20
  * @returns **`s`** `string` with replace options applied
35
21
  */
36
- export declare function applyReplaceOptions(s: string, replaceOptions: StringReplaceOptions): string;
22
+ export declare function applyReplaceParams(s: string, replaceParams: StringReplaceParams[]): string;
37
23
  /**
38
- * @param s `string` - the string to handle case options for
39
- * @param caseOptions {@link StringCaseOptions} - `optional` case options to apply to the string
40
- * = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
41
- * - applies the first case option that is `true` and ignores the rest
42
- * @returns **`s`** - the string with case options applied
24
+ * @param s `string`
25
+ * @param options {@link StringPadOptions}
26
+ * @param options.side `'left' | 'right' | 'both'`
27
+ * - `left` -> use `s.padStart()`
28
+ * - `right` -> use `s.padEnd()`
29
+ * - `both` -> apply half padding to both sides
30
+ * @returns **`s`** `string` padded to length = `options.maxLength`
31
+ */
32
+ export declare function applyPadOptions(s: string, options: StringPadOptions): string;
33
+ /**
34
+ * @param s `string`
35
+ * @param caseOptions {@link StringCaseEnum} = `'upper' | 'lower' | 'title'`
36
+ * @returns **`s`** `string` with case option applied
43
37
  */
44
- export declare function applyCaseOptions(s: string, caseOptions?: StringCaseOptions): string;
38
+ export declare function applyCaseOptions(s: string, caseOptions: StringCaseEnum): string;
45
39
  /**
40
+ * @deprecated
46
41
  * @param s `string` - the string to handle padding options for
47
42
  * @param padOptions — {@link StringPadOptions} - `optional` padding options to apply to the string
48
43
  * = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
@@ -50,10 +45,10 @@ export declare function applyCaseOptions(s: string, caseOptions?: StringCaseOpti
50
45
  * @returns **`s`** - the string with padding options applied
51
46
  * @note `if` `s.length >= padLength`, no padding is applied
52
47
  */
53
- export declare function applyPadOptions(s: string, padOptions?: StringPadOptions): string;
48
+ export declare function DEP_applyPadOptions(s: string, padOptions?: DEP_StringPadOptions): string;
54
49
  /**
55
50
  * @param s `string`
56
- * @param stripOptions — {@link StringStripOptions}
51
+ * @param stripOptions — {@link DEP_StringStripOptions}
57
52
  * = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
58
53
  * - if `stripLeftCondition(s, leftArgs)` is `true` or `stripLeftCondition` is `undefined` (i.e. no conditions need to be met to strip left):
59
54
  * - - then the left side of the `s` is stripped of `char`
@@ -62,4 +57,42 @@ export declare function applyPadOptions(s: string, padOptions?: StringPadOptions
62
57
  * @param stripOptions.escape escape special regex characters in `char` with `char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')`
63
58
  * @returns `string` - the string with leading and trailing characters removed
64
59
  */
65
- export declare function applyStripOptions(s: string, stripOptions: StringStripOptions): string;
60
+ export declare function DEP_applyStripOptions(s: string, stripOptions: DEP_StringStripOptions): string;
61
+ /**
62
+ * @param s `string` - the string to convert to title case
63
+ * @returns **`s`** `string` - the string in title case
64
+ * (i.e. first letter of each word, determined by the `\b` boundary metacharacter, is capitalized)
65
+ */
66
+ export declare function toTitleCase(s: string): string;
67
+ /**
68
+ * @deprecated use {@link applyCaseOptions} with {@link StringCaseEnum} instead
69
+ * @param s `string` - the string to handle case options for
70
+ * @param caseOptions — {@link DEP_StringCaseOptions} - `optional` case options to apply to the string
71
+ * = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
72
+ * - applies the first case option that is `true` and ignores the rest
73
+ * @returns **`s`** - the string with case options applied
74
+ */
75
+ export declare function DEP_applyCaseOptions(s: string, caseOptions?: DEP_StringCaseOptions): string;
76
+ export declare function DEP_clean(s: string, options?: DEP_CleanStringOptions): string;
77
+ /**
78
+ * @description
79
+ * - converts to string and trims, then:
80
+ * - applies options in this order: `StringReplaceOptions`, `StringStripOptions`, `StringCaseOptions`, `StringPadOptions`
81
+ * - Removes leading+trailing spaces, extra spaces, commas, and dots from a string (e.g. `'..'` becomes `'.'`)
82
+ * - optionally applies 4 option params with: {@link string.replace}, {@link DEP_applyStripOptions}, {@link DEP_applyCaseOptions}, and {@link DEP_applyPadOptions}.
83
+ * @param s `string` to clean
84
+ * @param stripOptions {@link DEP_StringStripOptions}
85
+ * - `optional` strip options to apply to the string
86
+ * - = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
87
+ * @param caseOptions {@link DEP_StringCaseOptions}
88
+ * - `optional` case options to apply to the string
89
+ * - = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
90
+ * @param padOptions {@link StringPadOptions}
91
+ * - `optional` padding options to apply to the string
92
+ * - = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
93
+ * @param replaceOptions {@link StringReplaceOptions}
94
+ * - `optional` replace options to apply to the string
95
+ * - = `Array<`{@link StringReplaceParams}`>` = `{ searchValue: string | RegExp, replaceValue: string }[]`
96
+ * @returns **`s`** `string`
97
+ */
98
+ export declare function DEP_clean(s: string, stripOptions?: DEP_StringStripOptions, caseOptions?: DEP_StringCaseOptions, padOptions?: DEP_StringPadOptions, replaceOptions?: StringReplaceOptions): string;