topkat-utils 1.2.41 → 1.2.42
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/.eslintrc +13 -2
- package/CHANGELOG.md +3 -0
- package/README.md +6 -3
- package/dist/src/env-utils.d.ts +2 -2
- package/dist/src/env-utils.js +2 -2
- package/dist/src/string-utils.d.ts +10 -16
- package/dist/src/string-utils.js +43 -6
- package/dist/src/string-utils.js.map +1 -1
- package/package.json +4 -2
- package/src/env-utils.ts +2 -2
- package/src/string-utils.ts +38 -27
package/.eslintrc
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"parser": "@typescript-eslint/parser",
|
|
2
3
|
"env": {
|
|
3
4
|
"es6": true,
|
|
4
5
|
"node": true,
|
|
@@ -6,7 +7,8 @@
|
|
|
6
7
|
"browser": true
|
|
7
8
|
},
|
|
8
9
|
"extends": [
|
|
9
|
-
"eslint:recommended"
|
|
10
|
+
"eslint:recommended",
|
|
11
|
+
"plugin:@typescript-eslint/recommended"
|
|
10
12
|
],
|
|
11
13
|
"parserOptions": {
|
|
12
14
|
"ecmaVersion": 2018,
|
|
@@ -42,6 +44,15 @@
|
|
|
42
44
|
{
|
|
43
45
|
"allowSingleLine": true
|
|
44
46
|
}
|
|
45
|
-
]
|
|
47
|
+
],
|
|
48
|
+
"@typescript-eslint/indent": [
|
|
49
|
+
"warn",
|
|
50
|
+
4
|
|
51
|
+
],
|
|
52
|
+
"@typescript-eslint/no-explicit-any": 0,
|
|
53
|
+
"@typescript-eslint/no-unused-vars": 1,
|
|
54
|
+
"@typescript-eslint/no-empty-function": 1,
|
|
55
|
+
"@typescript-eslint/triple-slash-reference": 0,
|
|
56
|
+
"@typescript-eslint/ban-types": 0
|
|
46
57
|
}
|
|
47
58
|
}
|
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -6,10 +6,11 @@ It's strength is that it has a straight functional naming and is fast and lightw
|
|
|
6
6
|
|
|
7
7
|
``` javascript
|
|
8
8
|
const topkatUtils = {
|
|
9
|
-
isset, //
|
|
9
|
+
isset, // check undefined or null values but not falsey
|
|
10
10
|
random, // random number between two values
|
|
11
11
|
cln, // clean string for print. Eg: undefined, null, NaN => '-'
|
|
12
12
|
pad, // simple padStart for numbers
|
|
13
|
+
isObject, // check is value is a "straight" object (not null, not date, not an array, not undefined...)
|
|
13
14
|
/** return the number or the closest number of the range
|
|
14
15
|
* * nb min max => returns
|
|
15
16
|
* * 7 5 10 => 7 // in the range
|
|
@@ -26,13 +27,14 @@ const topkatUtils = {
|
|
|
26
27
|
sortUrlsByDeepnessInArrayOrObject,
|
|
27
28
|
// like nodeJs path.join() but for urls
|
|
28
29
|
urlPathJoin,
|
|
29
|
-
// miniTemplater(`Hello {{
|
|
30
|
+
// miniTemplater(`Hello {{name}}`, { name: 'John' }) => `Hello John`
|
|
30
31
|
miniTemplater,
|
|
31
|
-
// is number between
|
|
32
32
|
asArray,
|
|
33
33
|
compareArrays,
|
|
34
|
+
// is number between
|
|
34
35
|
isBetween,
|
|
35
36
|
simpleObjectMaskOrSelect,
|
|
37
|
+
// get the environment variables (Eg. NODE_ENV) with parsed values ("true" => true, "4" => 4). On env variables all values are strings
|
|
36
38
|
ENV,
|
|
37
39
|
parseBool,
|
|
38
40
|
|
|
@@ -98,6 +100,7 @@ const topkatUtils = {
|
|
|
98
100
|
upperCase,
|
|
99
101
|
capitalize1st,
|
|
100
102
|
camelCaseToWords,
|
|
103
|
+
nbOccurenceInString,
|
|
101
104
|
|
|
102
105
|
firstMatch,
|
|
103
106
|
allMatches,
|
package/dist/src/env-utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** Parse one dimention object undefined, true, false, null represented as string will be converted to primitives */
|
|
2
2
|
export declare function parseEnv(env: any): {};
|
|
3
|
-
/** READ ONLY,
|
|
4
|
-
* use it like ENV().
|
|
3
|
+
/** READ ONLY, get the environment variables (Eg. NODE_ENV) with parsed values ("true" => true, "4" => 4, "null" => null). On env variables all values are strings
|
|
4
|
+
* use it like ENV().NODE_ENV
|
|
5
5
|
*/
|
|
6
6
|
export declare function ENV(): {
|
|
7
7
|
[key: string]: any;
|
package/dist/src/env-utils.js
CHANGED
|
@@ -23,8 +23,8 @@ function parseEnv(env) {
|
|
|
23
23
|
return newEnv;
|
|
24
24
|
}
|
|
25
25
|
exports.parseEnv = parseEnv;
|
|
26
|
-
/** READ ONLY,
|
|
27
|
-
* use it like ENV().
|
|
26
|
+
/** READ ONLY, get the environment variables (Eg. NODE_ENV) with parsed values ("true" => true, "4" => 4, "null" => null). On env variables all values are strings
|
|
27
|
+
* use it like ENV().NODE_ENV
|
|
28
28
|
*/
|
|
29
29
|
function ENV() {
|
|
30
30
|
const throwErr = () => { throw new Error('Please use process.env to write to env'); };
|
|
@@ -1,30 +1,23 @@
|
|
|
1
1
|
import { ObjectGeneric } from "./types";
|
|
2
2
|
/**Eg: camelCase */
|
|
3
|
-
export declare function camelCase(wordBits: string[]): string;
|
|
4
|
-
export declare function camelCase(...wordBits: string[]): string;
|
|
3
|
+
export declare function camelCase(...wordBits: string[] | [string[]]): string;
|
|
5
4
|
/**Eg: snake_case
|
|
6
5
|
* trimmed but not lowerCased
|
|
7
6
|
*/
|
|
8
|
-
export declare function snakeCase(wordBits: string[]): string;
|
|
9
|
-
export declare function snakeCase(...wordBits: string[]): string;
|
|
7
|
+
export declare function snakeCase(...wordBits: string[] | [string[]]): string;
|
|
10
8
|
/**Eg: kebab-case
|
|
11
9
|
* trimmed AND lowerCased
|
|
12
10
|
* undefined, null... => ''
|
|
13
11
|
*/
|
|
14
|
-
export declare function kebabCase(wordBits: string[]): string;
|
|
15
|
-
export declare function kebabCase(...wordBits: string[]): string;
|
|
12
|
+
export declare function kebabCase(...wordBits: string[] | [string[]]): string;
|
|
16
13
|
/**Eg: PascalCase undefined, null... => '' */
|
|
17
|
-
export declare function pascalCase(wordBits: string[]): string;
|
|
18
|
-
export declare function pascalCase(...wordBits: string[]): string;
|
|
14
|
+
export declare function pascalCase(...wordBits: string[] | [string[]]): string;
|
|
19
15
|
/**Eg: Titlecase undefined, null... => '' */
|
|
20
|
-
export declare function titleCase(wordBits: string[]): string;
|
|
21
|
-
export declare function titleCase(...wordBits: string[]): string;
|
|
16
|
+
export declare function titleCase(...wordBits: string[] | [string[]]): string;
|
|
22
17
|
/**Eg: UPPERCASE undefined, null... => '' */
|
|
23
|
-
export declare function upperCase(wordBits: string[]): string;
|
|
24
|
-
export declare function upperCase(...wordBits: string[]): string;
|
|
18
|
+
export declare function upperCase(...wordBits: string[] | [string[]]): string;
|
|
25
19
|
/**Eg: lowercase undefined, null... => '' */
|
|
26
|
-
export declare function lowerCase(wordBits: string[]): string;
|
|
27
|
-
export declare function lowerCase(...wordBits: string[]): string;
|
|
20
|
+
export declare function lowerCase(...wordBits: string[] | [string[]]): string;
|
|
28
21
|
export declare function capitalize1st(str?: string): string;
|
|
29
22
|
export declare function camelCaseToWords(str: string): string[];
|
|
30
23
|
/** GIVEN A STRING '{ blah;2}, ['nested,(what,ever)']' AND A SEPARATOR ",""
|
|
@@ -63,11 +56,11 @@ export declare function convertAccentedCharacters(str: string, config?: {
|
|
|
63
56
|
export declare function generateToken(length?: number, unique?: boolean, mode?: 'alphanumeric' | 'hexadecimal'): any;
|
|
64
57
|
export declare function generateObjectId(): any;
|
|
65
58
|
/** Useful to join differents bits of url with normalizing slashes
|
|
66
|
-
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2
|
|
59
|
+
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2
|
|
67
60
|
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
68
61
|
*/
|
|
69
62
|
export declare function urlPathJoin(...bits: string[]): string;
|
|
70
|
-
/** file path using ONLY SLASH and not antislash on windows. Remove also starting and trailing slashes */
|
|
63
|
+
/** @deprecated use urlPathJoin instead // file path using ONLY SLASH and not antislash on windows. Remove also starting and trailing slashes */
|
|
71
64
|
export declare function pathJoinSafe(...pathBits: string[]): string;
|
|
72
65
|
export type MiniTemplaterOptions = {
|
|
73
66
|
valueWhenNotSet: string;
|
|
@@ -84,3 +77,4 @@ export type MiniTemplaterOptions = {
|
|
|
84
77
|
export declare function miniTemplater(content: string, varz: ObjectGeneric, options?: Partial<MiniTemplaterOptions>): string;
|
|
85
78
|
/** Clean output for outside world. All undefined / null / NaN / Infinity values are changed to '-' */
|
|
86
79
|
export declare function cln(val: any, replacerInCaseItIsUndefinNaN?: string): any;
|
|
80
|
+
export declare function nbOccurenceInString(baseString: string, searchedString: string, allowOverlapping?: boolean): number;
|
package/dist/src/string-utils.js
CHANGED
|
@@ -1,42 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cln = exports.miniTemplater = exports.pathJoinSafe = exports.urlPathJoin = exports.generateObjectId = exports.generateToken = exports.convertAccentedCharacters = exports.getValuesBetweenStrings = exports.getValuesBetweenSeparator = exports.camelCaseToWords = exports.capitalize1st = exports.lowerCase = exports.upperCase = exports.titleCase = exports.pascalCase = exports.kebabCase = exports.snakeCase = exports.camelCase = void 0;
|
|
3
|
+
exports.nbOccurenceInString = exports.cln = exports.miniTemplater = exports.pathJoinSafe = exports.urlPathJoin = exports.generateObjectId = exports.generateToken = exports.convertAccentedCharacters = exports.getValuesBetweenStrings = exports.getValuesBetweenSeparator = exports.camelCaseToWords = exports.capitalize1st = exports.lowerCase = exports.upperCase = exports.titleCase = exports.pascalCase = exports.kebabCase = exports.snakeCase = exports.camelCase = void 0;
|
|
4
4
|
//----------------------------------------
|
|
5
5
|
// STRING UTILS
|
|
6
6
|
//----------------------------------------
|
|
7
7
|
const error_utils_1 = require("./error-utils");
|
|
8
8
|
const isset_1 = require("./isset");
|
|
9
|
-
const getWordBits = wb => Array.isArray(wb[0]) ? wb[0] : wb;
|
|
9
|
+
const getWordBits = (wb) => Array.isArray(wb[0]) ? wb[0] : wb;
|
|
10
|
+
/**Eg: camelCase */
|
|
10
11
|
function camelCase(...wordBits) {
|
|
11
12
|
const wordBitsReal = getWordBits(wordBits);
|
|
12
13
|
return wordBitsReal.filter(e => e).map((w, i) => i === 0 ? w : capitalize1st(w)).join('');
|
|
13
14
|
}
|
|
14
15
|
exports.camelCase = camelCase;
|
|
16
|
+
/**Eg: snake_case
|
|
17
|
+
* trimmed but not lowerCased
|
|
18
|
+
*/
|
|
15
19
|
function snakeCase(...wordBits) {
|
|
16
20
|
const wordBitsReal = getWordBits(wordBits);
|
|
17
21
|
return wordBitsReal.filter(e => e).map(w => w.trim()).join('_');
|
|
18
22
|
}
|
|
19
23
|
exports.snakeCase = snakeCase;
|
|
24
|
+
/**Eg: kebab-case
|
|
25
|
+
* trimmed AND lowerCased
|
|
26
|
+
* undefined, null... => ''
|
|
27
|
+
*/
|
|
20
28
|
function kebabCase(...wordBits) {
|
|
21
29
|
const wordBitsReal = getWordBits(wordBits);
|
|
22
30
|
return wordBitsReal.filter(e => e).map(w => w.trim().toLowerCase()).join('-');
|
|
23
31
|
}
|
|
24
32
|
exports.kebabCase = kebabCase;
|
|
33
|
+
/**Eg: PascalCase undefined, null... => '' */
|
|
25
34
|
function pascalCase(...wordBits) {
|
|
26
35
|
const wordBitsReal = getWordBits(wordBits);
|
|
27
36
|
return wordBitsReal.filter(e => e).map((w, i) => capitalize1st(w)).join('');
|
|
28
37
|
}
|
|
29
38
|
exports.pascalCase = pascalCase;
|
|
39
|
+
/**Eg: Titlecase undefined, null... => '' */
|
|
30
40
|
function titleCase(...wordBits) {
|
|
31
41
|
const wordBitsReal = getWordBits(wordBits);
|
|
32
42
|
return capitalize1st(wordBitsReal.filter(e => e).map(w => w.trim()).join(''));
|
|
33
43
|
}
|
|
34
44
|
exports.titleCase = titleCase;
|
|
45
|
+
/**Eg: UPPERCASE undefined, null... => '' */
|
|
35
46
|
function upperCase(...wordBits) {
|
|
36
47
|
const wordBitsReal = getWordBits(wordBits);
|
|
37
48
|
return wordBitsReal.filter(e => e).map(w => w.trim().toUpperCase()).join('');
|
|
38
49
|
}
|
|
39
50
|
exports.upperCase = upperCase;
|
|
51
|
+
/**Eg: lowercase undefined, null... => '' */
|
|
40
52
|
function lowerCase(...wordBits) {
|
|
41
53
|
const wordBitsReal = getWordBits(wordBits);
|
|
42
54
|
return wordBitsReal.filter(e => e).map(w => w.trim().toLowerCase()).join('');
|
|
@@ -186,16 +198,23 @@ function generateObjectId() {
|
|
|
186
198
|
}
|
|
187
199
|
exports.generateObjectId = generateObjectId;
|
|
188
200
|
/** Useful to join differents bits of url with normalizing slashes
|
|
189
|
-
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2
|
|
201
|
+
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2
|
|
190
202
|
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
191
203
|
*/
|
|
192
204
|
function urlPathJoin(...bits) {
|
|
193
|
-
return bits
|
|
205
|
+
return bits
|
|
206
|
+
.join('/')
|
|
207
|
+
.replace(/\/+/g, '/') // replace double slash
|
|
208
|
+
.replace(/(^\/|\/$)/g, '') // remove starting and trailing slash
|
|
209
|
+
.replace(/(https?:)\/\/?/, '$1//'); // make sure there is 2 slashes after http(s)
|
|
194
210
|
}
|
|
195
211
|
exports.urlPathJoin = urlPathJoin;
|
|
196
|
-
/** file path using ONLY SLASH and not antislash on windows. Remove also starting and trailing slashes */
|
|
212
|
+
/** @deprecated use urlPathJoin instead // file path using ONLY SLASH and not antislash on windows. Remove also starting and trailing slashes */
|
|
197
213
|
function pathJoinSafe(...pathBits) {
|
|
198
|
-
return pathBits
|
|
214
|
+
return pathBits
|
|
215
|
+
.join('/')
|
|
216
|
+
.replace(/\/+/g, '/') // replace double slash
|
|
217
|
+
.replace(/(^\/|\/$)/g, ''); // remove starting and trailing slash
|
|
199
218
|
}
|
|
200
219
|
exports.pathJoinSafe = pathJoinSafe;
|
|
201
220
|
/** Replace variables in a string like: `Hello {{userName}}!`
|
|
@@ -213,4 +232,22 @@ exports.miniTemplater = miniTemplater;
|
|
|
213
232
|
/** Clean output for outside world. All undefined / null / NaN / Infinity values are changed to '-' */
|
|
214
233
|
function cln(val, replacerInCaseItIsUndefinNaN = '-') { return ['undefined', undefined, 'indéfini', 'NaN', NaN, Infinity, null].includes(val) ? replacerInCaseItIsUndefinNaN : val; }
|
|
215
234
|
exports.cln = cln;
|
|
235
|
+
function nbOccurenceInString(baseString, searchedString, allowOverlapping = false) {
|
|
236
|
+
if (searchedString.length === 0)
|
|
237
|
+
return baseString.length + 1;
|
|
238
|
+
let n = 0;
|
|
239
|
+
let pos = 0;
|
|
240
|
+
let step = allowOverlapping ? 1 : searchedString.length;
|
|
241
|
+
while (true) {
|
|
242
|
+
pos = baseString.indexOf(searchedString, pos);
|
|
243
|
+
if (pos >= 0) {
|
|
244
|
+
++n;
|
|
245
|
+
pos += step;
|
|
246
|
+
}
|
|
247
|
+
else
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
return n;
|
|
251
|
+
}
|
|
252
|
+
exports.nbOccurenceInString = nbOccurenceInString;
|
|
216
253
|
//# sourceMappingURL=string-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-utils.js","sourceRoot":"","sources":["../../src/string-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,eAAe;AACf,0CAA0C;AAC1C,+CAAqD;AAErD,mCAA+B;AAE/B,MAAM,WAAW,GAAG,
|
|
1
|
+
{"version":3,"file":"string-utils.js","sourceRoot":"","sources":["../../src/string-utils.ts"],"names":[],"mappings":";;;AAAA,0CAA0C;AAC1C,eAAe;AACf,0CAA0C;AAC1C,+CAAqD;AAErD,mCAA+B;AAE/B,MAAM,WAAW,GAAG,CAAC,EAAyB,EAAY,EAAE,CAAC,KAAK,CAAC,O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AAE3L,SAAgB,mBAAmB,CAAC,UAAkB,EAAE,cAAqB,EAAE,mBAA4B,KAAK;IAE5G,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,UAAU,CAAC,MAAM,GAAG,CAAC,CAAA;IAE7D,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,IAAI,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,MAAM,CAAA;IAEvD,OAAO,IAAI,EAAE;QACT,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC,CAAC;QAC9C,IAAI,GAAG,IAAI,CAAC,EAAE;YACV,EAAE,CAAC,CAAC;YACJ,GAAG,IAAI,IAAI,CAAC;SACf;;YAAM,MAAM;KAChB;IACD,OAAO,CAAC,CAAC;AACb,CAAC;AAhBD,kDAgBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "topkat-utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.42",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"types": "index.ts",
|
|
6
6
|
"main": "dist",
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"@types/node": "^18.11.18",
|
|
23
23
|
"bump-simple": "^1.0.0",
|
|
24
24
|
"eslint": "^8.0.0",
|
|
25
|
-
"typescript": "^4.9.5"
|
|
25
|
+
"typescript": "^4.9.5",
|
|
26
|
+
"@typescript-eslint/eslint-plugin": "latest",
|
|
27
|
+
"@typescript-eslint/parser": "latest"
|
|
26
28
|
}
|
|
27
29
|
}
|
package/src/env-utils.ts
CHANGED
|
@@ -16,8 +16,8 @@ export function parseEnv(env) {
|
|
|
16
16
|
return newEnv
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
/** READ ONLY,
|
|
20
|
-
* use it like ENV().
|
|
19
|
+
/** READ ONLY, get the environment variables (Eg. NODE_ENV) with parsed values ("true" => true, "4" => 4, "null" => null). On env variables all values are strings
|
|
20
|
+
* use it like ENV().NODE_ENV
|
|
21
21
|
*/
|
|
22
22
|
export function ENV(): { [key: string]: any } {
|
|
23
23
|
const throwErr = () => { throw new Error('Please use process.env to write to env') }
|
package/src/string-utils.ts
CHANGED
|
@@ -5,12 +5,10 @@ import { err500IfEmptyOrNotSet } from "./error-utils"
|
|
|
5
5
|
import { ObjectGeneric } from "./types"
|
|
6
6
|
import { isset } from "./isset"
|
|
7
7
|
|
|
8
|
-
const getWordBits = wb => Array.isArray(wb[0]) ? wb[0] : wb
|
|
8
|
+
const getWordBits = (wb: string[] | [string[]]): string[] => Array.isArray(wb[0]) ? wb[0] : wb as any
|
|
9
9
|
|
|
10
10
|
/**Eg: camelCase */
|
|
11
|
-
export function camelCase(wordBits: string[]): string
|
|
12
|
-
export function camelCase(...wordBits: string[]): string
|
|
13
|
-
export function camelCase(...wordBits): string {
|
|
11
|
+
export function camelCase(...wordBits: string[] | [string[]]): string {
|
|
14
12
|
const wordBitsReal = getWordBits(wordBits)
|
|
15
13
|
return wordBitsReal.filter(e => e).map((w, i) => i === 0 ? w : capitalize1st(w)).join('')
|
|
16
14
|
}
|
|
@@ -18,9 +16,7 @@ export function camelCase(...wordBits): string {
|
|
|
18
16
|
/**Eg: snake_case
|
|
19
17
|
* trimmed but not lowerCased
|
|
20
18
|
*/
|
|
21
|
-
export function snakeCase(wordBits: string[]): string
|
|
22
|
-
export function snakeCase(...wordBits: string[]): string
|
|
23
|
-
export function snakeCase(...wordBits): string {
|
|
19
|
+
export function snakeCase(...wordBits: string[] | [string[]]): string {
|
|
24
20
|
const wordBitsReal = getWordBits(wordBits)
|
|
25
21
|
return wordBitsReal.filter(e => e).map(w => w.trim()).join('_')
|
|
26
22
|
}
|
|
@@ -28,40 +24,30 @@ export function snakeCase(...wordBits): string {
|
|
|
28
24
|
* trimmed AND lowerCased
|
|
29
25
|
* undefined, null... => ''
|
|
30
26
|
*/
|
|
31
|
-
export function kebabCase(wordBits: string[]): string
|
|
32
|
-
export function kebabCase(...wordBits: string[]): string
|
|
33
|
-
export function kebabCase(...wordBits): string {
|
|
27
|
+
export function kebabCase(...wordBits: string[] | [string[]]): string {
|
|
34
28
|
const wordBitsReal = getWordBits(wordBits)
|
|
35
29
|
return wordBitsReal.filter(e => e).map(w => w.trim().toLowerCase()).join('-')
|
|
36
30
|
}
|
|
37
31
|
/**Eg: PascalCase undefined, null... => '' */
|
|
38
|
-
export function pascalCase(wordBits: string[]): string
|
|
39
|
-
export function pascalCase(...wordBits: string[]): string
|
|
40
|
-
export function pascalCase(...wordBits): string {
|
|
32
|
+
export function pascalCase(...wordBits: string[] | [string[]]): string {
|
|
41
33
|
const wordBitsReal = getWordBits(wordBits)
|
|
42
34
|
return wordBitsReal.filter(e => e).map((w, i) => capitalize1st(w)).join('')
|
|
43
35
|
}
|
|
44
36
|
|
|
45
37
|
/**Eg: Titlecase undefined, null... => '' */
|
|
46
|
-
export function titleCase(wordBits: string[]): string
|
|
47
|
-
export function titleCase(...wordBits: string[]): string
|
|
48
|
-
export function titleCase(...wordBits): string {
|
|
38
|
+
export function titleCase(...wordBits: string[] | [string[]]): string {
|
|
49
39
|
const wordBitsReal = getWordBits(wordBits)
|
|
50
40
|
return capitalize1st(wordBitsReal.filter(e => e).map(w => w.trim()).join(''))
|
|
51
41
|
}
|
|
52
42
|
|
|
53
43
|
/**Eg: UPPERCASE undefined, null... => '' */
|
|
54
|
-
export function upperCase(wordBits: string[]): string
|
|
55
|
-
export function upperCase(...wordBits: string[]): string
|
|
56
|
-
export function upperCase(...wordBits): string {
|
|
44
|
+
export function upperCase(...wordBits: string[] | [string[]]): string {
|
|
57
45
|
const wordBitsReal = getWordBits(wordBits)
|
|
58
46
|
return wordBitsReal.filter(e => e).map(w => w.trim().toUpperCase()).join('')
|
|
59
47
|
}
|
|
60
48
|
|
|
61
49
|
/**Eg: lowercase undefined, null... => '' */
|
|
62
|
-
export function lowerCase(wordBits: string[]): string
|
|
63
|
-
export function lowerCase(...wordBits: string[]): string
|
|
64
|
-
export function lowerCase(...wordBits): string {
|
|
50
|
+
export function lowerCase(...wordBits: string[] | [string[]]): string {
|
|
65
51
|
const wordBitsReal = getWordBits(wordBits)
|
|
66
52
|
return wordBitsReal.filter(e => e).map(w => w.trim().toLowerCase()).join('')
|
|
67
53
|
}
|
|
@@ -205,16 +191,23 @@ export function generateObjectId() {
|
|
|
205
191
|
|
|
206
192
|
|
|
207
193
|
/** Useful to join differents bits of url with normalizing slashes
|
|
208
|
-
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2
|
|
194
|
+
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2
|
|
209
195
|
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
210
196
|
*/
|
|
211
197
|
export function urlPathJoin(...bits: string[]) {
|
|
212
|
-
return bits
|
|
198
|
+
return bits
|
|
199
|
+
.join('/')
|
|
200
|
+
.replace(/\/+/g, '/') // replace double slash
|
|
201
|
+
.replace(/(^\/|\/$)/g, '') // remove starting and trailing slash
|
|
202
|
+
.replace(/(https?:)\/\/?/, '$1//') // make sure there is 2 slashes after http(s)
|
|
213
203
|
}
|
|
214
204
|
|
|
215
|
-
/** file path using ONLY SLASH and not antislash on windows. Remove also starting and trailing slashes */
|
|
205
|
+
/** @deprecated use urlPathJoin instead // file path using ONLY SLASH and not antislash on windows. Remove also starting and trailing slashes */
|
|
216
206
|
export function pathJoinSafe(...pathBits: string[]) {
|
|
217
|
-
return pathBits
|
|
207
|
+
return pathBits
|
|
208
|
+
.join('/')
|
|
209
|
+
.replace(/\/+/g, '/') // replace double slash
|
|
210
|
+
.replace(/(^\/|\/$)/g, '') // remove starting and trailing slash
|
|
218
211
|
}
|
|
219
212
|
|
|
220
213
|
|
|
@@ -242,4 +235,22 @@ export function miniTemplater(content: string, varz: ObjectGeneric, options: Par
|
|
|
242
235
|
|
|
243
236
|
|
|
244
237
|
/** Clean output for outside world. All undefined / null / NaN / Infinity values are changed to '-' */
|
|
245
|
-
export function cln(val, replacerInCaseItIsUndefinNaN = '-') { return ['undefined', undefined, 'indéfini', 'NaN', NaN, Infinity, null].includes(val) ? replacerInCaseItIsUndefinNaN : val }
|
|
238
|
+
export function cln(val, replacerInCaseItIsUndefinNaN = '-') { return ['undefined', undefined, 'indéfini', 'NaN', NaN, Infinity, null].includes(val) ? replacerInCaseItIsUndefinNaN : val }
|
|
239
|
+
|
|
240
|
+
export function nbOccurenceInString(baseString: string, searchedString:string, allowOverlapping: boolean = false) {
|
|
241
|
+
|
|
242
|
+
if (searchedString.length === 0) return baseString.length + 1
|
|
243
|
+
|
|
244
|
+
let n = 0
|
|
245
|
+
let pos = 0
|
|
246
|
+
let step = allowOverlapping ? 1 : searchedString.length
|
|
247
|
+
|
|
248
|
+
while (true) {
|
|
249
|
+
pos = baseString.indexOf(searchedString, pos);
|
|
250
|
+
if (pos >= 0) {
|
|
251
|
+
++n;
|
|
252
|
+
pos += step;
|
|
253
|
+
} else break;
|
|
254
|
+
}
|
|
255
|
+
return n;
|
|
256
|
+
}
|