typeshi 1.4.0 → 1.6.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.
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.js +5 -28
- package/dist/utils/argumentValidation.d.ts +19 -20
- package/dist/utils/argumentValidation.js +23 -2
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +23 -0
- package/dist/utils/io/index.d.ts +2 -2
- package/dist/utils/io/index.js +2 -2
- package/dist/utils/regex/email.d.ts +2 -2
- package/dist/utils/regex/email.js +3 -9
- package/dist/utils/regex/entity.js +0 -3
- package/dist/utils/regex/index.d.ts +5 -5
- package/dist/utils/regex/index.js +5 -5
- package/dist/utils/regex/misc.d.ts +1 -6
- package/dist/utils/regex/misc.js +2 -19
- package/dist/utils/typeValidation.d.ts +0 -16
- package/dist/utils/typeValidation.js +1 -18
- package/package.json +13 -14
package/dist/config/index.d.ts
CHANGED
package/dist/config/index.js
CHANGED
|
@@ -17,5 +17,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
17
17
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
__exportStar(require("./setupLog"), exports);
|
|
21
20
|
__exportStar(require("./env"), exports);
|
|
21
|
+
__exportStar(require("./setupLog"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file src/index.ts
|
|
3
3
|
*/
|
|
4
|
-
export *
|
|
5
|
-
export *
|
|
6
|
-
export * as config from "./config";
|
|
7
|
-
export * as TypeValidation from "./utils/typeValidation";
|
|
8
|
-
export * as ArgumentValidation from "./utils/argumentValidation";
|
|
4
|
+
export * from "./config";
|
|
5
|
+
export * from "./utils";
|
package/dist/index.js
CHANGED
|
@@ -13,32 +13,9 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
if (k2 === undefined) k2 = k;
|
|
14
14
|
o[k2] = m[k];
|
|
15
15
|
}));
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
o["default"] = v;
|
|
20
|
-
});
|
|
21
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
-
var ownKeys = function(o) {
|
|
23
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
-
var ar = [];
|
|
25
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
-
return ar;
|
|
27
|
-
};
|
|
28
|
-
return ownKeys(o);
|
|
29
|
-
};
|
|
30
|
-
return function (mod) {
|
|
31
|
-
if (mod && mod.__esModule) return mod;
|
|
32
|
-
var result = {};
|
|
33
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
-
__setModuleDefault(result, mod);
|
|
35
|
-
return result;
|
|
36
|
-
};
|
|
37
|
-
})();
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
38
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
exports.io = __importStar(require("./utils/io"));
|
|
42
|
-
exports.config = __importStar(require("./config"));
|
|
43
|
-
exports.TypeValidation = __importStar(require("./utils/typeValidation"));
|
|
44
|
-
exports.ArgumentValidation = __importStar(require("./utils/argumentValidation"));
|
|
20
|
+
__exportStar(require("./config"), exports);
|
|
21
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @file src/utils/argumentValidation.ts
|
|
3
|
-
* @description moved the content of parameter type checks at the start of
|
|
4
|
-
* functions to here. use these when you want your function to throw a fit when
|
|
5
|
-
* it receives bad input.
|
|
6
|
-
* @example
|
|
7
|
-
* import * as validate from "@typeshi/argumentValidation";
|
|
8
|
-
* @TODO add boolean value configurable by a setter function that specifies if errors should be thrown or only logged
|
|
9
|
-
* - maybe add a configurable value that the validation functions should return if the validation test fails
|
|
10
|
-
* - change the validation functions such that they return the validated value, if possible?
|
|
11
|
-
* - or maybe have them return boolean type predicates ?
|
|
12
|
-
* - -> maybe have to make a class
|
|
13
|
-
* - research the thingy where a type is after the function name and before parens
|
|
14
|
-
* @consideration add a default export named 'validate'
|
|
15
|
-
*/
|
|
16
|
-
import { TypeOfEnum } from "./typeValidation";
|
|
17
1
|
/**
|
|
18
2
|
* - {@link isNonEmptyString}`(value: any): value is string & { length: number; }`
|
|
19
3
|
* @param source `string` indicating what called `stringArgument()`
|
|
@@ -93,8 +77,8 @@ export declare function functionArgument(source: string, arg2: string | {
|
|
|
93
77
|
* @param label `string` the argument/parameter name
|
|
94
78
|
* @param value `any` the value passed into the `source`
|
|
95
79
|
* for the argument corresponding to `label`
|
|
96
|
-
* @param elementType `
|
|
97
|
-
* - `if` provided, must be
|
|
80
|
+
* @param elementType `string` `(optional)`, the expected type of each element in the array
|
|
81
|
+
* - `if` provided, must be a string representing the type
|
|
98
82
|
* @param elementTypeGuard `(value: any) => boolean` `(optional)`, a type guard function that checks if each element in the array is of a specific type
|
|
99
83
|
* - `if` provided, must be a function that takes a value and returns a boolean indicating if the value is of the expected type
|
|
100
84
|
* - `if` both `elementType` and `elementTypeGuard` are provided, both must be satisfied
|
|
@@ -107,7 +91,7 @@ export declare function functionArgument(source: string, arg2: string | {
|
|
|
107
91
|
* - `Expected '${label}' to be: non-empty array`
|
|
108
92
|
* - `Received '${label}' value: ${typeof value} = '${value}'`
|
|
109
93
|
*/
|
|
110
|
-
export declare function arrayArgument(source: string, label: string, value: any, elementType?:
|
|
94
|
+
export declare function arrayArgument(source: string, label: string, value: any, elementType?: string, elementTypeGuard?: (value: any) => boolean, allowEmpty?: boolean): void;
|
|
111
95
|
/**
|
|
112
96
|
* @note `if` `elementTypeGuard`'s name or its label includes 'Array' then only check `elementTypeGuard(value)`
|
|
113
97
|
* instead of checking `value.every(el => elementTypeGuard(el))`
|
|
@@ -192,4 +176,19 @@ export declare function existingPathArgument(source: string, arg2: string | {
|
|
|
192
176
|
* @returns **`bracketedString`** `string`
|
|
193
177
|
*/
|
|
194
178
|
export declare const bracketed: (s: string) => string;
|
|
195
|
-
|
|
179
|
+
declare const validate: {
|
|
180
|
+
stringArgument: typeof stringArgument;
|
|
181
|
+
multipleStringArguments: typeof multipleStringArguments;
|
|
182
|
+
numericStringArgument: typeof numericStringArgument;
|
|
183
|
+
booleanArgument: typeof booleanArgument;
|
|
184
|
+
numberArgument: typeof numberArgument;
|
|
185
|
+
arrayArgument: typeof arrayArgument;
|
|
186
|
+
enumArgument: typeof enumArgument;
|
|
187
|
+
objectArgument: typeof objectArgument;
|
|
188
|
+
functionArgument: typeof functionArgument;
|
|
189
|
+
existingPathArgument: typeof existingPathArgument;
|
|
190
|
+
existingDirectoryArgument: typeof existingDirectoryArgument;
|
|
191
|
+
existingFileArgument: typeof existingFileArgument;
|
|
192
|
+
multipleExistingFileArguments: typeof multipleExistingFileArguments;
|
|
193
|
+
};
|
|
194
|
+
export default validate;
|
|
@@ -63,7 +63,6 @@ exports.existingPathArgument = existingPathArgument;
|
|
|
63
63
|
* - or maybe have them return boolean type predicates ?
|
|
64
64
|
* - -> maybe have to make a class
|
|
65
65
|
* - research the thingy where a type is after the function name and before parens
|
|
66
|
-
* @consideration add a default export named 'validate'
|
|
67
66
|
*/
|
|
68
67
|
const typeValidation_1 = require("./typeValidation");
|
|
69
68
|
const setupLog_1 = require("../config/setupLog");
|
|
@@ -315,6 +314,9 @@ function functionArgument(source, arg2, value) {
|
|
|
315
314
|
throw new Error(msg);
|
|
316
315
|
}
|
|
317
316
|
}
|
|
317
|
+
/**
|
|
318
|
+
* `re = /(?<=^is).*$/i`
|
|
319
|
+
*/
|
|
318
320
|
const typeGuardNamePattern = /(?<=^is).*$/i;
|
|
319
321
|
/**
|
|
320
322
|
* @note `if` `elementTypeGuard`'s name or its label includes 'Array' then only check `elementTypeGuard(value)`
|
|
@@ -337,7 +339,7 @@ function arrayArgument(source,
|
|
|
337
339
|
arg2,
|
|
338
340
|
/** `value (any) | allowEmpty (boolean)` */
|
|
339
341
|
arg3,
|
|
340
|
-
/** elementType (
|
|
342
|
+
/** elementType (string) | undefined */
|
|
341
343
|
elementType,
|
|
342
344
|
/** elementTypeGuard | allowEmpty (boolean) */
|
|
343
345
|
elementTypeGuard, allowEmpty) {
|
|
@@ -808,3 +810,22 @@ function getSourceString(fileName, func, funcInfo, startLine, endLine) {
|
|
|
808
810
|
let funcName = typeof func === 'string' ? func : func.name;
|
|
809
811
|
return `[${fileName}.${funcName}(${(0, typeValidation_1.isNonEmptyString)(funcInfo) ? ` ${funcInfo} ` : ''})${lineNumberText}]`;
|
|
810
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
|
+
exports.default = validate;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @file src/utils/index.ts
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./io"), exports);
|
|
21
|
+
__exportStar(require("./regex"), exports);
|
|
22
|
+
__exportStar(require("./argumentValidation"), exports);
|
|
23
|
+
__exportStar(require("./typeValidation"), exports);
|
package/dist/utils/io/index.d.ts
CHANGED
package/dist/utils/io/index.js
CHANGED
|
@@ -17,8 +17,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
/**
|
|
18
18
|
* @file src/utils/io/index.ts
|
|
19
19
|
*/
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
20
21
|
__exportStar(require("./dateTime"), exports);
|
|
22
|
+
__exportStar(require("./logging"), exports);
|
|
21
23
|
__exportStar(require("./reading"), exports);
|
|
22
24
|
__exportStar(require("./writing"), exports);
|
|
23
|
-
__exportStar(require("./logging"), exports);
|
|
24
|
-
__exportStar(require("./types"), exports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** `re` = `/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/` */
|
|
2
2
|
export declare const EMAIL_REGEX: RegExp;
|
|
3
|
-
/**return true if matches {@link EMAIL_REGEX} and does not include
|
|
4
|
-
export declare function isValidEmail(email: string): boolean;
|
|
3
|
+
/**return true if matches {@link EMAIL_REGEX} and does not include pattern/string specified in `excludeSubstrings` */
|
|
4
|
+
export declare function isValidEmail(email: string, excludeSubstrings?: string | RegExp | string[]): boolean;
|
|
5
5
|
/** @returns **`email`**: `string` - the first email that matches {@link EMAIL_REGEX} or an empty string `''`*/
|
|
6
6
|
export declare function extractEmail(email: string): RegExpMatchArray | null;
|
|
@@ -10,13 +10,13 @@ const stringOperations_1 = require("./stringOperations");
|
|
|
10
10
|
const StringOptions_1 = require("./types/StringOptions");
|
|
11
11
|
/** `re` = `/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/` */
|
|
12
12
|
exports.EMAIL_REGEX = new RegExp(/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/, StringOptions_1.RegExpFlagsEnum.GLOBAL);
|
|
13
|
-
/**return true if matches {@link EMAIL_REGEX} and does not include
|
|
14
|
-
function isValidEmail(email) {
|
|
13
|
+
/**return true if matches {@link EMAIL_REGEX} and does not include pattern/string specified in `excludeSubstrings` */
|
|
14
|
+
function isValidEmail(email, excludeSubstrings) {
|
|
15
15
|
if (!email)
|
|
16
16
|
return false;
|
|
17
17
|
email = email.trim();
|
|
18
18
|
return exports.EMAIL_REGEX.test(email)
|
|
19
|
-
&& !(0, stringOperations_1.stringContainsAnyOf)(email,
|
|
19
|
+
&& (excludeSubstrings ? !(0, stringOperations_1.stringContainsAnyOf)(email, excludeSubstrings) : true);
|
|
20
20
|
}
|
|
21
21
|
/** @returns **`email`**: `string` - the first email that matches {@link EMAIL_REGEX} or an empty string `''`*/
|
|
22
22
|
function extractEmail(email) {
|
|
@@ -24,14 +24,8 @@ function extractEmail(email) {
|
|
|
24
24
|
return null;
|
|
25
25
|
email = email.trim();
|
|
26
26
|
const match = email.match(exports.EMAIL_REGEX);
|
|
27
|
-
// DEBUG.push(
|
|
28
|
-
// NL + `extractEmail() EMAIL_REGEX.test("${email}") = ${EMAIL_REGEX.test(email)}`,
|
|
29
|
-
// TAB + `match=${JSON.stringify(match)}`
|
|
30
|
-
// );
|
|
31
27
|
if (match) {
|
|
32
|
-
// DEBUG.push(NL+`-> match not null -> returning ${JSON.stringify(match)}`);
|
|
33
28
|
return match;
|
|
34
29
|
}
|
|
35
|
-
// DEBUG.push(NL+`-> match is null -> returning null`);
|
|
36
30
|
return null;
|
|
37
31
|
}
|
|
@@ -167,8 +167,5 @@ function extractJobTitleSuffix(s) {
|
|
|
167
167
|
/**
|
|
168
168
|
* - `re` = `/\b(?:company|corp|inc|co\.?,? ltd\.?|ltd|\.?l\.?lc|plc . . .)\b/` `i`
|
|
169
169
|
* */
|
|
170
|
-
// export const COMPANY_KEYWORDS_PATTERN = new RegExp(
|
|
171
|
-
// `\\b(?:` + getCompanyKeywordList().join('|') + `)\\b`, RegExpFlagsEnum.IGNORE_CASE
|
|
172
|
-
// );
|
|
173
170
|
exports.COMPANY_KEYWORDS_PATTERN = /\b(?:compan(y|ies)|[+@&]+|corporation|corporate|(drop)?box|corp|inc|co\.|co\.?,? ltd\.?|ltd|(p\.)?l\.?l\.?c|plc|llp|(un)?limited|nys|oc|mc|pr|local|group|consulting|consultant(s)?|vcc|bcp|center|(in)?pack(aging|age)?|electric|chemical|Exhibit(s)?|business|Factory|employee|print(s|ing)?|Pharmaceutical(s)?|vista ?print|associates|association|account(s)?|art(s)?|AMZ|independent|beauty|beautiful(ly)?|meditech|medaesthetic|partners|Acupuncture|Affiliate(s)?|telecom|maps|cosmetic(s)?|connections|practice|computer|service(s)?|skincare|skin|face|facial|body|artisan(s)?|Alchemy|plastic|advanced|surgical|surgery|surgeons|administrators|laser|practice|scientific|science|health|healthcare|medical|med|med( |i)?spa|spa|SpaMedica|perfect|surgeons|(med)?(a)?esthetic(s|a)?|salon|lounge|studio|wellness|courier|capital|financ(e|ing)|collector|dept(\.)?|HVAC|insurance|ins|surety|freight|fine art|solution(s)?|trad(e|ing)|renewal|department|inst\.|institute|instant|university|college|America(n)?|US(A)?|global|digital|virtual|orange|coast(al)?|tree|franchise|orthopedic(s)?|academy|advertising|travel|technologies|flash|international|tech|clinic(s|al)?|Exterminator|Nightclub|management|foundation|aid|product(ions|ion|s)?|industr(y|ies|ial)|biomed|bio|bio-chem|lubian|technology|technical|special(ist(s)?|ities)?|support|innovat(e|ive|ion(s)?)|county|united|state(s)?|the|one|of|for|by|and|on|or|at|it|the|about|plan|legal|valley|republic|recruit(ing)?|media|southern|office|post office|clean(er|ers)|transport|law|contract|high|food|meal|therapy|therapeutic(s)?|dental|laboratory|instrument|southwest|ingredient(s)?|commerce|city|Laboratories|lab|logistics|newport|radio|video|photo(graphy)?|korea|communication(s)|derm(atology|atologist(s)?)|new|express|goods|mission|depot|treasur(e|er|y)|revenue|biolab|Orders|staff(ing|ed)?|investors|envelope|refresh|Anti|AgingMajestic|motors|museum|event|Kaiser|pacific|visa|platinum|level|Rejuvenation|bespoke|Cardio|speed|pro|tax|firm|DC|square|store|weight|group|Buy|balance(d)?|buckhead|market(s)?|Bulk|perks|GPT|Boutique|supplement(s)?|vitamin(s)?|plus|sales|salesforce|precision|fitness|image|premier|Fulfillment|final|elite|elase|sculpt(ing)?|botox|south|Hills|symposium|wifi|online|worldwide|tv|derm([a-z]+)|wine|rent(al(s)?)?|mail|plumber(s)?|Sociedade|card|\.com)\b/i;
|
|
174
171
|
exports.COMPANY_ABBREVIATION_PATTERN = /\b(?:corp|inc|co\.?,? ltd\.?|ltd|(p\.)?l\.?l\.?c|p\.?c|plc|llp|s\.c)\.?\s*$/i;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @file src/utils/regex/index.ts
|
|
3
3
|
*/
|
|
4
|
-
export * from "./
|
|
4
|
+
export * from "./types";
|
|
5
5
|
export * from "./cleaning";
|
|
6
|
-
export * from "./
|
|
6
|
+
export * from "./configureParameters";
|
|
7
7
|
export * from "./email";
|
|
8
|
-
export * from "./phone";
|
|
9
|
-
export * from "./misc";
|
|
10
8
|
export * from "./entity";
|
|
11
|
-
export * from "./
|
|
9
|
+
export * from "./misc";
|
|
10
|
+
export * from "./phone";
|
|
11
|
+
export * from "./stringOperations";
|
|
@@ -17,11 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
/**
|
|
18
18
|
* @file src/utils/regex/index.ts
|
|
19
19
|
*/
|
|
20
|
-
__exportStar(require("./
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
21
|
__exportStar(require("./cleaning"), exports);
|
|
22
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./configureParameters"), exports);
|
|
23
23
|
__exportStar(require("./email"), exports);
|
|
24
|
-
__exportStar(require("./phone"), exports);
|
|
25
|
-
__exportStar(require("./misc"), exports);
|
|
26
24
|
__exportStar(require("./entity"), exports);
|
|
27
|
-
__exportStar(require("./
|
|
25
|
+
__exportStar(require("./misc"), exports);
|
|
26
|
+
__exportStar(require("./phone"), exports);
|
|
27
|
+
__exportStar(require("./stringOperations"), exports);
|
|
@@ -23,15 +23,10 @@ export declare const DATE_STRING_PATTERN: RegExp;
|
|
|
23
23
|
/** e.g. `"Pangyo-ro, Bundag-Gu, Seongnam-si"` */
|
|
24
24
|
export declare const KOREA_ADDRESS_LATIN_TEXT_PATTERN: RegExp;
|
|
25
25
|
/**
|
|
26
|
-
* @consideration `removeClasses` is unnecessary, can assume true if a value for
|
|
27
|
-
* classDelimiter is provided -> have to remove default value for classDelimiter
|
|
28
26
|
* @param value `string` - the string value from which to extract `leaf`
|
|
29
|
-
* @param removeClasses `boolean` - remove string prefixes from result `leaf`
|
|
30
|
-
* - `Default` = `true`
|
|
31
27
|
* - e.g. `'CLASSA:SKU-1'` -> `sku` with classes removed = `'SKU-1'`
|
|
32
28
|
* @param classDelimiter `string` - the character used to delimit the item's classes
|
|
33
|
-
* - `Default` = `':'` (colon character)
|
|
34
29
|
* - e.g. `classDelimiter` of `'CLASSA:SKU-1'` = `':'`
|
|
35
30
|
* @returns **`leaf`**: `string` - the extracted `leaf` or the original value if no extraction performed
|
|
36
31
|
*/
|
|
37
|
-
export declare function extractLeaf(value: string,
|
|
32
|
+
export declare function extractLeaf(value: string, classDelimiter: string): string;
|
package/dist/utils/regex/misc.js
CHANGED
|
@@ -42,34 +42,17 @@ exports.DATE_STRING_PATTERN = new RegExp(/^\s*(\d{4}-\d{2}-\d{2}|\d{1,2}[\/-]\d{
|
|
|
42
42
|
/** e.g. `"Pangyo-ro, Bundag-Gu, Seongnam-si"` */
|
|
43
43
|
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
44
|
/**
|
|
45
|
-
* @consideration `removeClasses` is unnecessary, can assume true if a value for
|
|
46
|
-
* classDelimiter is provided -> have to remove default value for classDelimiter
|
|
47
45
|
* @param value `string` - the string value from which to extract `leaf`
|
|
48
|
-
* @param removeClasses `boolean` - remove string prefixes from result `leaf`
|
|
49
|
-
* - `Default` = `true`
|
|
50
46
|
* - e.g. `'CLASSA:SKU-1'` -> `sku` with classes removed = `'SKU-1'`
|
|
51
47
|
* @param classDelimiter `string` - the character used to delimit the item's classes
|
|
52
|
-
* - `Default` = `':'` (colon character)
|
|
53
48
|
* - e.g. `classDelimiter` of `'CLASSA:SKU-1'` = `':'`
|
|
54
49
|
* @returns **`leaf`**: `string` - the extracted `leaf` or the original value if no extraction performed
|
|
55
50
|
*/
|
|
56
|
-
function extractLeaf(value,
|
|
51
|
+
function extractLeaf(value, classDelimiter) {
|
|
57
52
|
let result = value;
|
|
58
|
-
if (
|
|
59
|
-
result = value.split(' (')[0];
|
|
60
|
-
// const match = skuValue.match(skuPattern);
|
|
61
|
-
// if (isNonEmptyArray(match)) {
|
|
62
|
-
// return match[0].trim();
|
|
63
|
-
// }
|
|
64
|
-
}
|
|
65
|
-
if (removeClasses && result.includes(classDelimiter)) {
|
|
53
|
+
if (result.includes(classDelimiter)) {
|
|
66
54
|
let classifierSplit = result.split(classDelimiter);
|
|
67
55
|
result = classifierSplit[classifierSplit.length - 1];
|
|
68
56
|
}
|
|
69
|
-
// if (value.includes(':')) {mlog.debug([`[regex.misc.extractLeaf()]`,
|
|
70
|
-
// ` initial value: '${value}'`,
|
|
71
|
-
// `after removeClasses: '${result}'`,
|
|
72
|
-
// ].join(TAB));
|
|
73
|
-
// STOP_RUNNING(0)}
|
|
74
57
|
return result || value;
|
|
75
58
|
}
|
|
@@ -145,19 +145,3 @@ export declare function isObject(value: any, requireNonEmpty?: boolean, requireN
|
|
|
145
145
|
* @returns **`isBoolean`** `boolean`
|
|
146
146
|
*/
|
|
147
147
|
export declare function isBoolean(value: any): value is boolean;
|
|
148
|
-
/**
|
|
149
|
-
* @TODO deprecate and remove this
|
|
150
|
-
* @enum {string} **`TypeOfEnum`**
|
|
151
|
-
* @property **`STRING`** = `'string'`
|
|
152
|
-
* @property **`NUMBER`** = `'number'`
|
|
153
|
-
* @property **`BOOLEAN`** = `'boolean'`
|
|
154
|
-
* @property **`OBJECT`** = `'object'`
|
|
155
|
-
* @property **`FUNCTION`** = `'function'`
|
|
156
|
-
*/
|
|
157
|
-
export declare enum TypeOfEnum {
|
|
158
|
-
STRING = "string",
|
|
159
|
-
NUMBER = "number",
|
|
160
|
-
BOOLEAN = "boolean",
|
|
161
|
-
OBJECT = "object",
|
|
162
|
-
FUNCTION = "function"
|
|
163
|
-
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @file src/utils/typeValidation.ts
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.isEmpty = void 0;
|
|
7
7
|
exports.isNullLike = isNullLike;
|
|
8
8
|
exports.anyNull = anyNull;
|
|
9
9
|
exports.isNonEmptyArray = isNonEmptyArray;
|
|
@@ -289,20 +289,3 @@ function isObject(value, requireNonEmpty = true, requireNonArray = true) {
|
|
|
289
289
|
function isBoolean(value) {
|
|
290
290
|
return (typeof value === 'boolean');
|
|
291
291
|
}
|
|
292
|
-
/**
|
|
293
|
-
* @TODO deprecate and remove this
|
|
294
|
-
* @enum {string} **`TypeOfEnum`**
|
|
295
|
-
* @property **`STRING`** = `'string'`
|
|
296
|
-
* @property **`NUMBER`** = `'number'`
|
|
297
|
-
* @property **`BOOLEAN`** = `'boolean'`
|
|
298
|
-
* @property **`OBJECT`** = `'object'`
|
|
299
|
-
* @property **`FUNCTION`** = `'function'`
|
|
300
|
-
*/
|
|
301
|
-
var TypeOfEnum;
|
|
302
|
-
(function (TypeOfEnum) {
|
|
303
|
-
TypeOfEnum["STRING"] = "string";
|
|
304
|
-
TypeOfEnum["NUMBER"] = "number";
|
|
305
|
-
TypeOfEnum["BOOLEAN"] = "boolean";
|
|
306
|
-
TypeOfEnum["OBJECT"] = "object";
|
|
307
|
-
TypeOfEnum["FUNCTION"] = "function";
|
|
308
|
-
})(TypeOfEnum || (exports.TypeOfEnum = TypeOfEnum = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeshi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"description": "TypeScript utility modules",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -23,25 +23,24 @@
|
|
|
23
23
|
],
|
|
24
24
|
"author": "Andrew Garwood",
|
|
25
25
|
"license": "MIT",
|
|
26
|
-
"
|
|
27
|
-
"@types/jest": "^29.5.14",
|
|
28
|
-
"@types/node": "^22.15.15",
|
|
29
|
-
"addresser": "^1.1.20",
|
|
30
|
-
"axios": "^1.9.0",
|
|
31
|
-
"csv-parser": "^3.2.0",
|
|
32
|
-
"fastest-levenshtein": "^1.0.16",
|
|
33
|
-
"fs": "^0.0.1-security",
|
|
34
|
-
"jest": "^29.7.0",
|
|
35
|
-
"lodash": "^4.17.21",
|
|
36
|
-
"puppeteer-core": "^24.9.0",
|
|
26
|
+
"dependencies": {
|
|
37
27
|
"rimraf": "^5.0.0",
|
|
38
28
|
"ts-jest": "^29.3.4",
|
|
39
29
|
"ts-node": "^10.9.2",
|
|
40
|
-
"tsconfig-paths": "^4.2.0",
|
|
41
30
|
"tslog": "^4.9.3",
|
|
42
|
-
"
|
|
31
|
+
"lodash": "^4.17.21",
|
|
32
|
+
"addresser": "^1.1.20",
|
|
33
|
+
"csv-parser": "^3.2.0",
|
|
34
|
+
"fastest-levenshtein": "^1.0.16",
|
|
43
35
|
"xlsx": "https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz"
|
|
44
36
|
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/jest": "^29.5.14",
|
|
39
|
+
"@types/node": "^22.15.15",
|
|
40
|
+
"jest": "^29.7.0",
|
|
41
|
+
"tsconfig-paths": "^4.2.0",
|
|
42
|
+
"typescript": "^5.0.0"
|
|
43
|
+
},
|
|
45
44
|
"engines": {
|
|
46
45
|
"node": ">=16.0.0"
|
|
47
46
|
},
|