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.
- package/dist/utils/argumentValidation.js +0 -19
- package/dist/utils/io/logging.js +8 -8
- package/dist/utils/io/reading.d.ts +22 -22
- package/dist/utils/io/reading.js +19 -19
- package/dist/utils/io/types/Io.TypeGuards.js +1 -1
- package/dist/utils/io/types/Io.d.ts +8 -8
- package/dist/utils/regex/Str.d.ts +79 -0
- package/dist/utils/regex/Str.js +83 -0
- package/dist/utils/regex/cleaning.d.ts +70 -37
- package/dist/utils/regex/cleaning.js +217 -57
- package/dist/utils/regex/configureParameters.d.ts +3 -3
- package/dist/utils/regex/entity.js +3 -3
- package/dist/utils/regex/index.d.ts +1 -0
- package/dist/utils/regex/index.js +1 -0
- package/dist/utils/regex/phone.js +1 -1
- package/dist/utils/regex/stringOperations.d.ts +0 -37
- package/dist/utils/regex/stringOperations.js +16 -46
- package/dist/utils/regex/types/StringOptions.TypeGuards.d.ts +20 -0
- package/dist/utils/regex/types/StringOptions.TypeGuards.js +77 -0
- package/dist/utils/regex/types/StringOptions.d.ts +65 -21
- package/dist/utils/regex/types/StringOptions.js +11 -1
- package/dist/utils/regex/types/index.d.ts +1 -1
- package/dist/utils/regex/types/index.js +1 -1
- package/dist/utils/typeValidation.d.ts +62 -15
- package/dist/utils/typeValidation.js +76 -20
- package/package.json +7 -6
- package/dist/utils/regex/types/typeGuards.d.ts +0 -12
- package/dist/utils/regex/types/typeGuards.js +0 -15
|
@@ -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;
|
package/dist/utils/io/logging.js
CHANGED
|
@@ -107,20 +107,20 @@ function autoFormatLogsOnExit(filePaths) {
|
|
|
107
107
|
* @returns `void`
|
|
108
108
|
*/
|
|
109
109
|
function formatDebugLogFile(inputPath, outputPath) {
|
|
110
|
-
|
|
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(
|
|
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 {
|
|
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?:
|
|
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
|
|
163
|
-
* @param valueOptions {@link
|
|
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?:
|
|
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
|
|
176
|
-
* - {@link
|
|
177
|
-
* - {@link
|
|
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?:
|
|
183
|
-
valueStripOptions?:
|
|
184
|
-
keyCaseOptions?:
|
|
185
|
-
valueCaseOptions?:
|
|
186
|
-
keyPadOptions?:
|
|
187
|
-
valuePadOptions?:
|
|
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
|
|
197
|
-
* - {@link
|
|
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?:
|
|
203
|
-
valueStripOptions?:
|
|
204
|
-
keyCaseOptions?:
|
|
205
|
-
valueCaseOptions?:
|
|
206
|
-
keyPadOptions?:
|
|
207
|
-
valuePadOptions?:
|
|
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;
|
package/dist/utils/io/reading.js
CHANGED
|
@@ -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.
|
|
450
|
-
const value = (0, regex_1.
|
|
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
|
|
643
|
-
* @param valueOptions {@link
|
|
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,
|
|
651
|
+
validate.objectArgument(source, { keyOptions, DEP_isCleanStringOptions: regex_1.DEP_isCleanStringOptions });
|
|
652
652
|
if (valueOptions)
|
|
653
|
-
validate.objectArgument(source, { valueOptions,
|
|
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.
|
|
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.
|
|
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
|
|
677
|
-
* - {@link
|
|
678
|
-
* - {@link
|
|
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.
|
|
693
|
-
let val = (0, regex_1.
|
|
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
|
|
716
|
-
* - {@link
|
|
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.
|
|
740
|
-
let val = (0, regex_1.
|
|
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 {
|
|
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
|
|
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
|
|
39
|
-
* - {@link
|
|
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?:
|
|
44
|
-
valueStripOptions?:
|
|
45
|
-
keyCaseOptions?:
|
|
46
|
-
valueCaseOptions?:
|
|
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 {
|
|
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
|
-
* @
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
8
|
-
*
|
|
9
|
-
* @
|
|
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,
|
|
10
|
+
export declare function clean(s: string, options?: StringCleanOptions): string;
|
|
25
11
|
/**
|
|
26
|
-
* @param s `string`
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
12
|
+
* @param s `string`
|
|
13
|
+
* @param options {@link StringStripOptions} = `{ char?: string, left?: StringStripCondition, right?: StringStripCondition }`
|
|
14
|
+
* @returns **`s`**
|
|
29
15
|
*/
|
|
30
|
-
export declare function
|
|
16
|
+
export declare function applyStripOptions(s: string, options: StringStripOptions): string;
|
|
31
17
|
/**
|
|
32
18
|
* @param s `string`
|
|
33
|
-
* @param
|
|
19
|
+
* @param replaceParams `Array<`{@link StringReplaceParams}`>`
|
|
34
20
|
* @returns **`s`** `string` with replace options applied
|
|
35
21
|
*/
|
|
36
|
-
export declare function
|
|
22
|
+
export declare function applyReplaceParams(s: string, replaceParams: StringReplaceParams[]): string;
|
|
37
23
|
/**
|
|
38
|
-
* @param s `string`
|
|
39
|
-
* @param
|
|
40
|
-
*
|
|
41
|
-
* -
|
|
42
|
-
*
|
|
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
|
|
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
|
|
48
|
+
export declare function DEP_applyPadOptions(s: string, padOptions?: DEP_StringPadOptions): string;
|
|
54
49
|
/**
|
|
55
50
|
* @param s `string`
|
|
56
|
-
* @param stripOptions — {@link
|
|
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
|
|
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;
|