typeshi 2.0.2 → 2.1.0

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.
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * @file src/utils/io/Io.ts
3
3
  */
4
- import { DEP_StringCaseOptions, StringPadOptions, DEP_StringStripOptions } from "../../regex/index";
5
4
  export type WriteJsonOptions = {
6
5
  data: Record<string, any> | string;
7
6
  filePath: string;
@@ -25,32 +24,10 @@ export type NodeLeaves = number[] | RowDictionary;
25
24
  export type RowDictionary = {
26
25
  [rowIndex: number]: Record<string, any>;
27
26
  };
28
- /**
29
- * @deprecated
30
- * @typedefn **`ParseOneToManyOptions`**
31
- * @property {StringStripOptions} keyStripOptions - options for stripping characters from the key
32
- * @property {StringStripOptions} valueStripOptions - options for stripping characters from the value
33
- * @property {StringCaseOptions} keyCaseOptions - options for changing the case of the key
34
- * @property {StringCaseOptions} valueCaseOptions - options for changing the case of the value
35
- * @property {StringPadOptions} keyPadOptions - options for padding values read from the `keyColumn`
36
- * @property {StringPadOptions} valuePadOptions - options for padding values read from the `valueColumn`
37
- *
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
- * - {@link StringPadOptions} = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
41
- */
42
- export type ParseOneToManyOptions = {
43
- keyStripOptions?: DEP_StringStripOptions;
44
- valueStripOptions?: DEP_StringStripOptions;
45
- keyCaseOptions?: DEP_StringCaseOptions;
46
- valueCaseOptions?: DEP_StringCaseOptions;
47
- keyPadOptions?: StringPadOptions;
48
- valuePadOptions?: StringPadOptions;
49
- };
50
27
  /**
51
28
  * common file extensions handled as input/output
52
29
  */
53
- export type FileExtension = '.csv' | '.tsv' | '.txt' | '.json' | '.xlsx' | '.xls' | '.xml' | '.yaml' | '.yml';
30
+ export type FileExtension = '.csv' | '.tsv' | '.txt' | '.json' | '.xlsx' | '.xls' | '.xml' | '.yaml' | '.yml' | (string & {});
54
31
  /**
55
32
  * @interface **`DirectoryFileOptions`** `getDirectoryFiles(parentDir: string, options: DirectoryFileOptions)`
56
33
  */
@@ -1,2 +1,5 @@
1
1
  "use strict";
2
+ /**
3
+ * @file src/utils/io/Io.ts
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -13,7 +13,7 @@ import { WriteJsonOptions } from "./types";
13
13
  * @param options.enableOverwrite `boolean` - `optional`, default=`true` If `enableOverwrite` is `true`, the file will be overwritten. If `false`, the `data` will be appended to the file.
14
14
  * @returns {void}
15
15
  */
16
- export declare function writeObjectToJsonSync(options: WriteJsonOptions): void;
16
+ export declare function writeJsonSync(options: WriteJsonOptions): void;
17
17
  /**
18
18
  * Output JSON data to a file with `fs.writeFileSync` or `fs.appendFileSync`.
19
19
  * @param data `Record<string, any> | string` - JSON data to write to file
@@ -23,16 +23,15 @@ export declare function writeObjectToJsonSync(options: WriteJsonOptions): void;
23
23
  * @param enableOverwrite `boolean` - `optional`, default=`true` If `enableOverwrite` is `true`, the file will be overwritten. If `false`, the `data` will be appended to the file.
24
24
  * @returns {void}
25
25
  */
26
- export declare function writeObjectToJsonSync(data: Record<string, any> | string, filePath: string, indent?: number, enableOverwrite?: boolean): void;
27
- export declare const writeJsonSync: typeof writeObjectToJsonSync;
28
- export declare const writeArraysToCsvSync: typeof writeListsToCsvSync;
26
+ export declare function writeJsonSync(data: Record<string, any> | string, filePath: string, indent?: number, enableOverwrite?: boolean): void;
29
27
  /**
28
+ * `writeListsToCsvSync`
30
29
  * @param listData `Record<string, Array<string>>` map col names to col values
31
30
  * @param outputPath `string`
32
31
  * @param delimiter `string` - optional, default=`'\t'`
33
32
  * @param columnDelimiter `string` - optional, default=`''`
34
33
  */
35
- export declare function writeListsToCsvSync(listData: Record<string, Array<string>>, outputPath: string, delimiter?: string, columnDelimiter?: string): void;
34
+ export declare function writeArraysToCsvSync(listData: Record<string, Array<string>>, outputPath: string, delimiter?: string, columnDelimiter?: string): void;
36
35
  /**
37
36
  * @param arr `T[]`
38
37
  * @param outputPath `string`
@@ -33,9 +33,8 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.writeArraysToCsvSync = exports.writeJsonSync = void 0;
37
- exports.writeObjectToJsonSync = writeObjectToJsonSync;
38
- exports.writeListsToCsvSync = writeListsToCsvSync;
36
+ exports.writeJsonSync = writeJsonSync;
37
+ exports.writeArraysToCsvSync = writeArraysToCsvSync;
39
38
  exports.writeArrayToFileSync = writeArrayToFileSync;
40
39
  exports.writeRowsToCsvSync = writeRowsToCsvSync;
41
40
  exports.trimFileSync = trimFileSync;
@@ -54,10 +53,11 @@ const reading_1 = require("./reading");
54
53
  const types_1 = require("./types");
55
54
  const typeValidation_1 = require("../typeValidation");
56
55
  const logging_1 = require("./logging");
57
- function writeObjectToJsonSync(
56
+ /** `writeObjectToJsonSync` */
57
+ function writeJsonSync(
58
58
  /** {@link WriteJsonOptions} `| Record<string, any> | string`, */
59
59
  arg1, filePath, indent = 4, enableOverwrite = true) {
60
- const source = (0, logging_1.getSourceString)(__filename, writeObjectToJsonSync.name);
60
+ const source = (0, logging_1.getSourceString)(__filename, writeJsonSync.name);
61
61
  if (!arg1) {
62
62
  setupLog_1.typeshiLogger.error(`${source} No data to write to JSON file'`);
63
63
  return;
@@ -106,22 +106,21 @@ arg1, filePath, indent = 4, enableOverwrite = true) {
106
106
  else {
107
107
  fs.appendFileSync(outputPath, jsonData, { flag: 'a' });
108
108
  }
109
- // mlog.info(`[writing.writeObjectToJson()] file saved to '${outputPath}'`)
109
+ setupLog_1.typeshiHiddenLogger.info(`${source} file saved to '${outputPath}'`);
110
110
  }
111
111
  catch (error) {
112
112
  setupLog_1.typeshiLogger.error(`${source} Error writing to JSON file'`, error);
113
113
  throw error;
114
114
  }
115
115
  }
116
- exports.writeJsonSync = writeObjectToJsonSync;
117
- exports.writeArraysToCsvSync = writeListsToCsvSync;
118
116
  /**
117
+ * `writeListsToCsvSync`
119
118
  * @param listData `Record<string, Array<string>>` map col names to col values
120
119
  * @param outputPath `string`
121
120
  * @param delimiter `string` - optional, default=`'\t'`
122
121
  * @param columnDelimiter `string` - optional, default=`''`
123
122
  */
124
- function writeListsToCsvSync(listData, outputPath, delimiter = types_1.DelimiterCharacterEnum.TAB, columnDelimiter = '') {
123
+ function writeArraysToCsvSync(listData, outputPath, delimiter = types_1.DelimiterCharacterEnum.TAB, columnDelimiter = '') {
125
124
  const listNames = Object.keys(listData);
126
125
  const listValues = Object.values(listData);
127
126
  const maxLength = Math.max(...listValues.map(list => list.length));
@@ -220,7 +219,7 @@ function trimFileSync(maxMB = 5, ...filePaths) {
220
219
  }
221
220
  catch (e) {
222
221
  setupLog_1.typeshiLogger.error('Error trimming file to last 10MB', e);
223
- throw e;
222
+ // throw e;
224
223
  }
225
224
  }
226
225
  }
@@ -248,7 +247,7 @@ async function trimFile(maxMB = 5, ...filePaths) {
248
247
  }
249
248
  catch (e) {
250
249
  setupLog_1.typeshiLogger.error('Error trimming file to last 10MB', e);
251
- throw e;
250
+ // throw e;
252
251
  }
253
252
  }
254
253
  await (0, env_1.DELAY)(1000, `[trimFile()] Releasing file handles...`);
@@ -72,7 +72,8 @@ export declare class Str {
72
72
  static replace: typeof applyReplaceParams;
73
73
  /**
74
74
  * @param s `string`
75
- * @param options {@link StringStripOptions} = `{ char?: string, left?: StringStripCondition, right?: StringStripCondition }`
75
+ * @param options {@link StringStripOptions}
76
+ * = `{ char?: string, left?: `{@link StringStripCondition}`, right?: StringStripCondition }`
76
77
  * @returns **`s`**
77
78
  */
78
79
  static strip: typeof applyStripOptions;
@@ -77,7 +77,8 @@ Str.pad = cleaning_1.applyPadOptions;
77
77
  Str.replace = cleaning_1.applyReplaceParams;
78
78
  /**
79
79
  * @param s `string`
80
- * @param options {@link StringStripOptions} = `{ char?: string, left?: StringStripCondition, right?: StringStripCondition }`
80
+ * @param options {@link StringStripOptions}
81
+ * = `{ char?: string, left?: `{@link StringStripCondition}`, right?: StringStripCondition }`
81
82
  * @returns **`s`**
82
83
  */
83
84
  Str.strip = cleaning_1.applyStripOptions;
@@ -1,4 +1,4 @@
1
- import { DEP_CleanStringOptions, DEP_StringCaseOptions, DEP_StringPadOptions, StringCaseEnum, StringPadOptions, StringReplaceOptions, DEP_StringStripOptions, StringCleanOptions, StringReplaceParams, StringStripOptions } from "./types";
1
+ import { StringCaseEnum, StringPadOptions, StringCleanOptions, StringReplaceParams, StringStripOptions } from "./types";
2
2
  /**
3
3
  * @param s `string`
4
4
  * @param options {@link StringCleanOptions} `(optional)`
@@ -36,63 +36,9 @@ export declare function applyPadOptions(s: string, options: StringPadOptions): s
36
36
  * @returns **`s`** `string` with case option applied
37
37
  */
38
38
  export declare function applyCaseOptions(s: string, caseOptions: StringCaseEnum): string;
39
- /**
40
- * @deprecated
41
- * @param s `string` - the string to handle padding options for
42
- * @param padOptions — {@link StringPadOptions} - `optional` padding options to apply to the string
43
- * = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
44
- * - applies the first padding option that is `true` and ignores the rest
45
- * @returns **`s`** - the string with padding options applied
46
- * @note `if` `s.length >= padLength`, no padding is applied
47
- */
48
- export declare function DEP_applyPadOptions(s: string, padOptions?: DEP_StringPadOptions): string;
49
- /**
50
- * @param s `string`
51
- * @param stripOptions — {@link DEP_StringStripOptions}
52
- * = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
53
- * - if `stripLeftCondition(s, leftArgs)` is `true` or `stripLeftCondition` is `undefined` (i.e. no conditions need to be met to strip left):
54
- * - - then the left side of the `s` is stripped of `char`
55
- * - if `stripRightCondition(s, rightArgs)` is `true` or `stripRightCondition` is `undefined` (i.e. no conditions need to be met to strip right):
56
- * - - then the right side of the `s` is stripped of `char`
57
- * @param stripOptions.escape escape special regex characters in `char` with `char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')`
58
- * @returns `string` - the string with leading and trailing characters removed
59
- */
60
- export declare function DEP_applyStripOptions(s: string, stripOptions: DEP_StringStripOptions): string;
61
39
  /**
62
40
  * @param s `string` - the string to convert to title case
63
41
  * @returns **`s`** `string` - the string in title case
64
42
  * (i.e. first letter of each word, determined by the `\b` boundary metacharacter, is capitalized)
65
43
  */
66
44
  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;
@@ -5,11 +5,7 @@ exports.applyStripOptions = applyStripOptions;
5
5
  exports.applyReplaceParams = applyReplaceParams;
6
6
  exports.applyPadOptions = applyPadOptions;
7
7
  exports.applyCaseOptions = applyCaseOptions;
8
- exports.DEP_applyPadOptions = DEP_applyPadOptions;
9
- exports.DEP_applyStripOptions = DEP_applyStripOptions;
10
8
  exports.toTitleCase = toTitleCase;
11
- exports.DEP_applyCaseOptions = DEP_applyCaseOptions;
12
- exports.DEP_clean = DEP_clean;
13
9
  /**
14
10
  * @file src/utils/regex/cleaning.ts
15
11
  */
@@ -154,7 +150,7 @@ function applyPadOptions(s, options) {
154
150
  s = s.padEnd(maxLength, char);
155
151
  return s;
156
152
  default:
157
- config_1.typeshiLogger.error([`[Str.applyPadOptions()] Invalid argument 'options.side'`,
153
+ config_1.typeshiLogger.error([`[applyPadOptions()] Invalid argument 'options.side'`,
158
154
  `Expected: 'left' | 'right' | 'both'`,
159
155
  `Received: '${side}'`,
160
156
  `Returing unaltered string...`
@@ -179,77 +175,13 @@ function applyCaseOptions(s, caseOptions) {
179
175
  return toTitleCase(s);
180
176
  default:
181
177
  config_1.typeshiLogger.warn([
182
- '[applyCase()] Invalid case option. Returning original string.',
183
- `Expected one of: ${Object.values(types_1.StringCaseEnum).join(', ')}`,
184
- `Received: ${caseOptions}`
178
+ '[applyCaseOptions()] Unsupported case option. Returning original string.',
179
+ `Expected: 'upper' | 'lower' | 'title'`,
180
+ `Received: '${caseOptions}'`
185
181
  ].join(config_1.INDENT_LOG_LINE));
186
182
  return s;
187
183
  }
188
184
  }
189
- /**
190
- * @deprecated
191
- * @param s `string` - the string to handle padding options for
192
- * @param padOptions — {@link StringPadOptions} - `optional` padding options to apply to the string
193
- * = `{ padLength: number, padChar: string, padLeft: boolean, padRight: boolean }`
194
- * - applies the first padding option that is `true` and ignores the rest
195
- * @returns **`s`** - the string with padding options applied
196
- * @note `if` `s.length >= padLength`, no padding is applied
197
- */
198
- function DEP_applyPadOptions(s, padOptions = { padLength: 24, padChar: ' ', padLeft: false, padRight: false }) {
199
- if (!s)
200
- return '';
201
- const { padLength, padChar, padLeft, padRight } = padOptions;
202
- if (typeof padLength !== 'number' || padLength < 0) {
203
- config_1.typeshiLogger.warn('handlePadOptions() Invalid padLength. Expected a positive integer, but received:', padLength);
204
- return s;
205
- }
206
- if (s.length >= padLength) {
207
- return s; // No padding needed
208
- }
209
- if (padLeft) {
210
- s = s.padStart(padLength, padChar);
211
- }
212
- else if (padRight) {
213
- s = s.padEnd(padLength, padChar);
214
- }
215
- return s;
216
- }
217
- /**
218
- * @param s `string`
219
- * @param stripOptions — {@link DEP_StringStripOptions}
220
- * = `{ char: string, escape?: boolean, stripLeftCondition?: (s: string, ...args: any[]) => boolean, leftArgs?: any[], stripRightCondition?: (s: string, ...args: any[]) => boolean, rightArgs?: any[] }`
221
- * - if `stripLeftCondition(s, leftArgs)` is `true` or `stripLeftCondition` is `undefined` (i.e. no conditions need to be met to strip left):
222
- * - - then the left side of the `s` is stripped of `char`
223
- * - if `stripRightCondition(s, rightArgs)` is `true` or `stripRightCondition` is `undefined` (i.e. no conditions need to be met to strip right):
224
- * - - then the right side of the `s` is stripped of `char`
225
- * @param stripOptions.escape escape special regex characters in `char` with `char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')`
226
- * @returns `string` - the string with leading and trailing characters removed
227
- */
228
- function DEP_applyStripOptions(s, stripOptions) {
229
- if (!s)
230
- return '';
231
- let { char, escape = false, stripLeftCondition = false, leftArgs, stripRightCondition = false, rightArgs } = stripOptions;
232
- if (escape) {
233
- char = char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
234
- }
235
- let regexSource = '';
236
- const leftSideUnconditionalOrMeetsCondition = !stripLeftCondition || (stripLeftCondition && stripLeftCondition(s, leftArgs));
237
- const rightSideUnconditionalOrMeetsCondition = !stripRightCondition || (stripRightCondition && stripRightCondition(s, rightArgs));
238
- if (leftSideUnconditionalOrMeetsCondition) {
239
- regexSource = regexSource + `^${char}+`;
240
- }
241
- if (regexSource.length > 0) {
242
- regexSource = regexSource + '|';
243
- }
244
- if (rightSideUnconditionalOrMeetsCondition) {
245
- regexSource = regexSource + `${char}+$`;
246
- }
247
- if (!stripLeftCondition && !stripRightCondition) { // assume strip both sides
248
- regexSource = `^${char}+|${char}+$`;
249
- }
250
- const regex = new RegExp(regexSource, 'g');
251
- return s.replace(regex, '');
252
- }
253
185
  /**
254
186
  * @param s `string` - the string to convert to title case
255
187
  * @returns **`s`** `string` - the string in title case
@@ -262,61 +194,3 @@ function toTitleCase(s) {
262
194
  .replace(/\b\w/g, char => char.toUpperCase())
263
195
  .replace(/(?<=\b[A-Z]{1})\w*\b/g, char => char.toLowerCase());
264
196
  }
265
- /**
266
- * @deprecated use {@link applyCaseOptions} with {@link StringCaseEnum} instead
267
- * @param s `string` - the string to handle case options for
268
- * @param caseOptions — {@link DEP_StringCaseOptions} - `optional` case options to apply to the string
269
- * = `{ toUpper: boolean, toLower: boolean, toTitle: boolean }`
270
- * - applies the first case option that is `true` and ignores the rest
271
- * @returns **`s`** - the string with case options applied
272
- */
273
- function DEP_applyCaseOptions(s, caseOptions = { toUpper: false, toLower: false, toTitle: false }) {
274
- if (!s)
275
- return '';
276
- const { toUpper, toLower, toTitle } = caseOptions;
277
- if (toUpper) {
278
- s = s.toUpperCase();
279
- }
280
- else if (toLower) {
281
- s = s.toLowerCase();
282
- }
283
- else if (toTitle) {
284
- s = toTitleCase(s);
285
- }
286
- return s;
287
- }
288
- function DEP_clean(s, arg2, arg3, arg4, arg5) {
289
- if (!s)
290
- return '';
291
- const { strip: stripOptions, case: caseOptions, pad: padOptions, replace: replaceOptions } = ((0, types_1.DEP_isCleanStringOptions)(arg2)
292
- ? arg2
293
- : {
294
- strip: arg2,
295
- case: arg3,
296
- pad: arg4,
297
- replace: arg5
298
- });
299
- s = String(s).trim() || '';
300
- s = s.replace(/\s+/g, ' ')
301
- .replace(/\.{2,}/g, '.')
302
- .replace(/,{2,}/g, ',');
303
- if ((0, typeValidation_1.isNonEmptyArray)(replaceOptions)) {
304
- s = applyReplaceParams(s, replaceOptions);
305
- }
306
- if (stripOptions) {
307
- s = DEP_applyStripOptions(s, stripOptions);
308
- }
309
- if (caseOptions) {
310
- s = DEP_applyCaseOptions(s, caseOptions);
311
- }
312
- if (padOptions && padOptions.padLength) {
313
- s = DEP_applyPadOptions(s, padOptions);
314
- }
315
- return s.trim().replace(/,$/g, '');
316
- }
317
- /**
318
- * @TODO convert
319
- * `s = s.replace(/\s+/g, ' ').replace(/\.{2,}/g, '.').replace(/,{2,}/g, ',');`
320
- * to StringReplaceOptions and test to ensure consistent output
321
- * */
322
- const CLEAN_BASIC_REPLACE_OPTIONS = [];
@@ -1,15 +1,14 @@
1
1
  /**
2
2
  * @file src/utils/regex/configureParameters.ts
3
3
  */
4
- import { DEP_StringStripOptions, StringReplaceParams } from ".";
4
+ import { StringReplaceParams, StringStripOptions } from ".";
5
5
  /**
6
6
  * @param {string} s - `string` - the string to check
7
7
  * @returns `!s.endsWith('Ph.D.') && !`{@link stringEndsWithAnyOf}`(s`, {@link COMPANY_ABBREVIATION_PATTERN} as RegExp, `[`{@link RegExpFlagsEnum.IGNORE_CASE}`]) && !stringEndsWithAnyOf(s, /\b[A-Z]\.?\b/, [RegExpFlagsEnum.IGNORE_CASE]);` */
8
8
  export declare function doesNotEndWithKnownAbbreviation(s: string): boolean;
9
- /** strip leading `.` and (trailing `.` if satisfy stripRightCondition: {@link doesNotEndWithKnownAbbreviation}) */
10
- export declare const STRIP_DOT_IF_NOT_END_WITH_ABBREVIATION: DEP_StringStripOptions;
11
- /** always strip leading and trailing `.` from a `string` */
12
- export declare const UNCONDITIONAL_STRIP_DOT_OPTIONS: DEP_StringStripOptions;
9
+ /** strip leading `.` and (trailing `.` if satisfy right.condition: {@link doesNotEndWithKnownAbbreviation}) */
10
+ export declare const STRIP_DOT_IF_NOT_ABBREVIATION: StringStripOptions;
11
+ export declare const STRIP_DOT_UNCONDITIONAL: StringStripOptions;
13
12
  /**
14
13
  * add space around hyphen if it already has one on a single side,
15
14
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.REPLACE_EM_HYPHEN = exports.ENSURE_SPACE_AROUND_HYPHEN = exports.UNCONDITIONAL_STRIP_DOT_OPTIONS = exports.STRIP_DOT_IF_NOT_END_WITH_ABBREVIATION = void 0;
3
+ exports.REPLACE_EM_HYPHEN = exports.ENSURE_SPACE_AROUND_HYPHEN = exports.STRIP_DOT_UNCONDITIONAL = exports.STRIP_DOT_IF_NOT_ABBREVIATION = void 0;
4
4
  exports.doesNotEndWithKnownAbbreviation = doesNotEndWithKnownAbbreviation;
5
5
  /**
6
6
  * @file src/utils/regex/configureParameters.ts
@@ -21,22 +21,16 @@ function doesNotEndWithKnownAbbreviation(s) {
21
21
  && !(0, _1.stringEndsWithAnyOf)(s, _1.COMPANY_ABBREVIATION_PATTERN, _1.RegExpFlagsEnum.IGNORE_CASE)
22
22
  && !(0, _1.stringEndsWithAnyOf)(s, initialsPattern, _1.RegExpFlagsEnum.IGNORE_CASE));
23
23
  }
24
- /** strip leading `.` and (trailing `.` if satisfy stripRightCondition: {@link doesNotEndWithKnownAbbreviation}) */
25
- exports.STRIP_DOT_IF_NOT_END_WITH_ABBREVIATION = {
24
+ /** strip leading `.` and (trailing `.` if satisfy right.condition: {@link doesNotEndWithKnownAbbreviation}) */
25
+ exports.STRIP_DOT_IF_NOT_ABBREVIATION = {
26
26
  char: '.',
27
- escape: true,
28
- stripLeftCondition: undefined,
29
- leftArgs: undefined,
30
- stripRightCondition: doesNotEndWithKnownAbbreviation,
27
+ left: undefined,
28
+ right: {
29
+ condition: doesNotEndWithKnownAbbreviation
30
+ }
31
31
  };
32
- /** always strip leading and trailing `.` from a `string` */
33
- exports.UNCONDITIONAL_STRIP_DOT_OPTIONS = {
34
- char: '.',
35
- escape: true,
36
- stripLeftCondition: undefined,
37
- leftArgs: undefined,
38
- stripRightCondition: undefined,
39
- rightArgs: undefined
32
+ exports.STRIP_DOT_UNCONDITIONAL = {
33
+ char: '.'
40
34
  };
41
35
  /**
42
36
  * add space around hyphen if it already has one on a single side,
@@ -22,10 +22,5 @@ function isValidEmail(email, excludeSubstrings) {
22
22
  function extractEmail(email) {
23
23
  if (!email)
24
24
  return null;
25
- email = email.trim();
26
- const match = email.match(exports.EMAIL_REGEX);
27
- if (match) {
28
- return match;
29
- }
30
- return null;
25
+ return email.trim().match(exports.EMAIL_REGEX);
31
26
  }
@@ -60,7 +60,7 @@ function extractName(name, includeJobTitleSuffix = true) {
60
60
  return { first: '', middle: '', last: '' };
61
61
  const originalName = name;
62
62
  const jobTitleSuffix = extractJobTitleSuffix(name);
63
- name = (0, cleaning_1.DEP_clean)(name, { replace: exports.CLEAN_NAME_REPLACE_OPTIONS })
63
+ name = (0, cleaning_1.clean)(name, { replace: exports.CLEAN_NAME_REPLACE_OPTIONS })
64
64
  .replace(exports.JOB_TITLE_SUFFIX_PATTERN, ''); // redundant
65
65
  const containsInvalidCharsOrCompanyKeywords = ((0, stringOperations_1.stringContainsAnyOf)(name, /[0-9!#&@]/)
66
66
  || (0, stringOperations_1.stringContainsAnyOf)(name, exports.COMPANY_KEYWORDS_PATTERN, StringOptions_1.RegExpFlagsEnum.IGNORE_CASE));
@@ -81,8 +81,8 @@ function extractName(name, includeJobTitleSuffix = true) {
81
81
  // move last name to the end
82
82
  nameSplit.push(nameSplit.shift() || '');
83
83
  }
84
- nameSplit.map((namePart) => (0, cleaning_1.DEP_clean)(namePart, {
85
- strip: _1.STRIP_DOT_IF_NOT_END_WITH_ABBREVIATION,
84
+ nameSplit.map((namePart) => (0, cleaning_1.clean)(namePart, {
85
+ strip: _1.STRIP_DOT_IF_NOT_ABBREVIATION,
86
86
  replace: [{ searchValue: /(^[-+])*/g, replaceValue: '' }]
87
87
  }));
88
88
  config_1.typeshiHiddenLogger.debug([`nameSplit.length === ${nameSplit.length},`,
@@ -149,7 +149,7 @@ function extractName(name, includeJobTitleSuffix = true) {
149
149
  function extractJobTitleSuffix(s) {
150
150
  if (!s || typeof s !== 'string')
151
151
  return '';
152
- s = (0, cleaning_1.DEP_clean)(s, { replace: [
152
+ s = (0, cleaning_1.clean)(s, { replace: [
153
153
  exports.REMOVE_ATTN_SALUTATION_PREFIX,
154
154
  { searchValue: /,$/g, replaceValue: '' }
155
155
  ] });
@@ -20,7 +20,10 @@ export declare const FILE_NAME_WITH_EXTENSION_PATTERN: RegExp;
20
20
  * 2. matches `MM/DD/YYYY` format. assumes `MM/DD/YYYY` format if the first part is less than or equal to 12 I think.
21
21
  */
22
22
  export declare const DATE_STRING_PATTERN: RegExp;
23
- /** e.g. `"Pangyo-ro, Bundag-Gu, Seongnam-si"` */
23
+ /**
24
+ * - e.g. `"Pangyo-ro, Bundag-Gu, Seongnam-si"`
25
+ * `re` = `/^\s*([a-zA-Z]{2,}-[a-zA-Z]{2,},\s*){1,}[a-zA-Z]{2,}-[a-zA-Z]{2,}\s*$/`
26
+ * */
24
27
  export declare const KOREA_ADDRESS_LATIN_TEXT_PATTERN: RegExp;
25
28
  /**
26
29
  * @param value `string` - the string value from which to extract `leaf`
@@ -39,7 +39,10 @@ exports.FILE_NAME_WITH_EXTENSION_PATTERN = /^[^/\\:*?"<>|]+(\.[^/\\:*?"<>|]+)$/;
39
39
  * 2. matches `MM/DD/YYYY` format. assumes `MM/DD/YYYY` format if the first part is less than or equal to 12 I think.
40
40
  */
41
41
  exports.DATE_STRING_PATTERN = new RegExp(/^\s*(\d{4}-\d{2}-\d{2}|\d{1,2}[\/-]\d{1,2}[\/-]\d{4})\s*$/);
42
- /** e.g. `"Pangyo-ro, Bundag-Gu, Seongnam-si"` */
42
+ /**
43
+ * - e.g. `"Pangyo-ro, Bundag-Gu, Seongnam-si"`
44
+ * `re` = `/^\s*([a-zA-Z]{2,}-[a-zA-Z]{2,},\s*){1,}[a-zA-Z]{2,}-[a-zA-Z]{2,}\s*$/`
45
+ * */
43
46
  exports.KOREA_ADDRESS_LATIN_TEXT_PATTERN = new RegExp(/^\s*([a-zA-Z]{2,}-[a-zA-Z]{2,},\s*){1,}[a-zA-Z]{2,}-[a-zA-Z]{2,}\s*$/);
44
47
  /**
45
48
  * @param value `string` - the string value from which to extract `leaf`
@@ -3,7 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PHONE_REGEX_LIST = exports.KOREA_PHONE_REGEX = exports.JAPAN_PHONE_REGEX = exports.CHINA_PHONE_REGEX = exports.HONG_KONG_PHONE_REGEX = exports.PHONE_REGEX = void 0;
4
4
  exports.extractPhone = extractPhone;
5
5
  exports.formatPhone = formatPhone;
6
- const cleaning_1 = require("./cleaning");
6
+ /**
7
+ * @file src/utils/regex/phone.ts
8
+ */
9
+ const _1 = require(".");
7
10
  const StringOptions_1 = require("./types/StringOptions");
8
11
  /**
9
12
  * @param phone - `string` - phone number to test
@@ -68,8 +71,9 @@ function formatPhone(phone, re, groupFormat) {
68
71
  if (groupFormat) {
69
72
  result = result.replace(re, groupFormat);
70
73
  }
71
- return (0, cleaning_1.DEP_clean)(result, { char: '-', escape: false })
72
- .replace(/([a-zA-Z]+\s*$)/, '').trim();
74
+ return (0, _1.clean)(result, { strip: { char: '-' } })
75
+ .replace(/([a-zA-Z]+\s*$)/, '')
76
+ .trim();
73
77
  }
74
78
  // https://en.wikipedia.org/wiki/List_of_telephone_country_codes
75
79
  /**
@@ -9,7 +9,7 @@ exports.extractSource = extractSource;
9
9
  * @file src/utils/regex/stringOperations.ts
10
10
  */
11
11
  const config_1 = require("../../config");
12
- const cleaning_1 = require("./cleaning");
12
+ const _1 = require(".");
13
13
  const fastest_levenshtein_1 = require("fastest-levenshtein");
14
14
  const typeValidation_1 = require("../typeValidation");
15
15
  /**
@@ -30,9 +30,8 @@ function stringEndsWithAnyOf(s, suffixes, ...flags) {
30
30
  return false;
31
31
  }
32
32
  let regex = undefined;
33
- if (typeof suffixes === 'string') {
33
+ if (typeof suffixes === 'string')
34
34
  suffixes = [suffixes];
35
- }
36
35
  let flagString = ((0, typeValidation_1.isNonEmptyArray)(flags)
37
36
  ? flags.join('')
38
37
  : suffixes instanceof RegExp && (0, typeValidation_1.isNonEmptyString)(suffixes.flags)
@@ -150,13 +149,11 @@ function equivalentAlphanumericStrings(s1, s2, tolerance = 0.90) {
150
149
  if (!s1 || !s2)
151
150
  return false;
152
151
  const cleanOptions = {
153
- case: { toLower: true },
154
- replace: [
155
- { searchValue: /[^A-Za-z0-9]/g, replaceValue: '' }
156
- ]
152
+ case: 'lower',
153
+ replace: [{ searchValue: /[^A-Za-z0-9]/g, replaceValue: '' }]
157
154
  };
158
- let s1Alphabetical = (0, cleaning_1.DEP_clean)(s1, cleanOptions).split('').sort().join('');
159
- let s2Alphabetical = (0, cleaning_1.DEP_clean)(s2, cleanOptions).split('').sort().join('');
155
+ let s1Alphabetical = (0, _1.clean)(s1, cleanOptions).split('').sort().join('');
156
+ let s2Alphabetical = (0, _1.clean)(s2, cleanOptions).split('').sort().join('');
160
157
  if (s1Alphabetical.length === 0 || s2Alphabetical.length === 0) {
161
158
  return false;
162
159
  }
@@ -198,7 +195,7 @@ function extractSource(regex) {
198
195
  const REMOVE_UNESCAPED_QUESTION_MARK = {
199
196
  searchValue: /(?<!\\)\?/g, replaceValue: ''
200
197
  };
201
- let source = (0, cleaning_1.DEP_clean)(regex.source, {
198
+ let source = (0, _1.clean)(regex.source, {
202
199
  replace: [
203
200
  REMOVE_ENDPOINT_CHARS,
204
201
  REPLACE_ESCAPED_DOT,
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @file src/utils/regex/types/StringOptions.TypeGuards.ts
3
3
  */
4
- import { DEP_CleanStringOptions, StringCaseEnum, StringCleanOptions, StringPadEnum, StringPadOptions, StringReplaceParams, StringStripOptions, StringCondition, StringStripCondition } from "./StringOptions";
4
+ import { StringCaseEnum, StringCleanOptions, StringPadEnum, StringPadOptions, StringReplaceParams, StringStripOptions, StringCondition, StringStripCondition } from "./StringOptions";
5
5
  export declare function isStringCleanOptions(value: unknown): value is StringCleanOptions;
6
6
  export declare function isStringStripOptions(value: unknown): value is StringStripOptions;
7
7
  export declare function isStringPadOptions(value: unknown): value is StringPadOptions;
@@ -10,11 +10,3 @@ export declare function isStringPadEnum(value: unknown): value is StringPadEnum;
10
10
  export declare function isStringReplaceParams(value: unknown): value is StringReplaceParams;
11
11
  export declare function isStringCondition(value: unknown): value is StringCondition;
12
12
  export declare function isStringStripCondition(value: unknown): value is StringStripCondition;
13
- /**
14
- * - {@link DEP_CleanStringOptions}
15
- * @param value `any`
16
- * @returns **`isCleanStringOptions`** `boolean`
17
- * - **`true`** if the `value` is an object with at least one key in `['strip', 'case', 'pad', 'replace']` and no other keys,
18
- * - **`false`** `otherwise`.
19
- */
20
- export declare function DEP_isCleanStringOptions(value: any): value is DEP_CleanStringOptions;