@naturalcycles/js-lib 14.149.2 → 14.149.3
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/object/object.util.js +1 -1
- package/dist/string/case.js +3 -3
- package/dist/string/escape.js +10 -10
- package/dist/string/pupa.js +2 -2
- package/dist/string/string.util.d.ts +0 -7
- package/dist/string/string.util.js +3 -13
- package/dist-esm/object/object.util.js +1 -1
- package/dist-esm/string/case.js +3 -3
- package/dist-esm/string/escape.js +10 -10
- package/dist-esm/string/pupa.js +2 -2
- package/dist-esm/string/string.util.js +2 -11
- package/package.json +2 -2
- package/src/object/object.util.ts +1 -1
- package/src/string/case.ts +3 -3
- package/src/string/escape.ts +10 -10
- package/src/string/pupa.ts +2 -2
- package/src/string/string.util.ts +2 -12
package/dist/string/case.js
CHANGED
|
@@ -5,17 +5,17 @@ const words_1 = require("./lodash/words");
|
|
|
5
5
|
const string_util_1 = require("./string.util");
|
|
6
6
|
function _camelCase(s) {
|
|
7
7
|
// return s.replace(/(_\w)/g, m => m[1]!.toUpperCase())
|
|
8
|
-
return (0, words_1.words)(s.
|
|
8
|
+
return (0, words_1.words)(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => {
|
|
9
9
|
word = word.toLowerCase();
|
|
10
10
|
return result + (index ? (0, string_util_1._upperFirst)(word) : word);
|
|
11
11
|
}, '');
|
|
12
12
|
}
|
|
13
13
|
exports._camelCase = _camelCase;
|
|
14
14
|
function _snakeCase(s) {
|
|
15
|
-
return (0, words_1.words)(s.
|
|
15
|
+
return (0, words_1.words)(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '_' : '') + word.toLowerCase(), '');
|
|
16
16
|
}
|
|
17
17
|
exports._snakeCase = _snakeCase;
|
|
18
18
|
function _kebabCase(s) {
|
|
19
|
-
return (0, words_1.words)(s.
|
|
19
|
+
return (0, words_1.words)(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '-' : '') + word.toLowerCase(), '');
|
|
20
20
|
}
|
|
21
21
|
exports._kebabCase = _kebabCase;
|
package/dist/string/escape.js
CHANGED
|
@@ -16,19 +16,19 @@ exports.htmlUnescape = exports.htmlEscape = void 0;
|
|
|
16
16
|
// Multiple `.replace()` calls are actually faster than using replacer functions
|
|
17
17
|
function _htmlEscape(s) {
|
|
18
18
|
return s
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
.
|
|
19
|
+
.replaceAll('&', '&') // Must happen first or else it will escape other just-escaped characters.
|
|
20
|
+
.replaceAll('"', '"')
|
|
21
|
+
.replaceAll("'", ''')
|
|
22
|
+
.replaceAll('<', '<')
|
|
23
|
+
.replaceAll('>', '>');
|
|
24
24
|
}
|
|
25
25
|
function _htmlUnescape(html) {
|
|
26
26
|
return html
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
.
|
|
31
|
-
.
|
|
27
|
+
.replaceAll('>', '>')
|
|
28
|
+
.replaceAll('<', '<')
|
|
29
|
+
.replaceAll(/�?39;/g, "'")
|
|
30
|
+
.replaceAll('"', '"')
|
|
31
|
+
.replaceAll('&', '&'); // Must happen last or else it will unescape other characters in the wrong order.
|
|
32
32
|
}
|
|
33
33
|
function htmlEscape(strings, ...values) {
|
|
34
34
|
if (typeof strings === 'string') {
|
package/dist/string/pupa.js
CHANGED
|
@@ -52,9 +52,9 @@ function pupa(template, data, opt = {}) {
|
|
|
52
52
|
// The regex tries to match either a number inside `{{ }}` or a valid JS identifier or key path.
|
|
53
53
|
const doubleBraceRegex = /{{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}}/gi;
|
|
54
54
|
if (doubleBraceRegex.test(template)) {
|
|
55
|
-
template = template.
|
|
55
|
+
template = template.replaceAll(doubleBraceRegex, composeHtmlEscape(replace));
|
|
56
56
|
}
|
|
57
57
|
const braceRegex = /{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}/gi;
|
|
58
|
-
return template.
|
|
58
|
+
return template.replaceAll(braceRegex, replace);
|
|
59
59
|
}
|
|
60
60
|
exports.pupa = pupa;
|
|
@@ -35,13 +35,6 @@ export declare function _substringAfterLast(s: string, delimiter: string): strin
|
|
|
35
35
|
* // `someFile`
|
|
36
36
|
*/
|
|
37
37
|
export declare function _substringBetweenLast(s: string, leftDelimiter: string, rightDelimiter: string): string;
|
|
38
|
-
/**
|
|
39
|
-
* Polyfill for es2021 `String.prototype.replaceAll`.
|
|
40
|
-
* Uses regex implementation that's a bit faster than another popular "split/join" implementation.
|
|
41
|
-
*
|
|
42
|
-
* Based on: https://stackoverflow.com/a/1144788/4919972
|
|
43
|
-
*/
|
|
44
|
-
export declare function _replaceAll(s: string, find: string, replaceWith: string): string;
|
|
45
38
|
/**
|
|
46
39
|
* Converts `\n` (aka new-line) to `<br>`, to be presented in HTML.
|
|
47
40
|
* Keeps `\n`, so if it's printed in non-HTML environment it still looks ok-ish.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._nl2br = exports.
|
|
3
|
+
exports._nl2br = exports._substringBetweenLast = exports._substringAfterLast = exports._substringAfter = exports._substringBeforeLast = exports._substringBefore = exports._truncateMiddle = exports._truncate = exports._removeWhitespace = exports._split = exports._lowerFirst = exports._upperFirst = exports._capitalize = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Converts the first character of string to upper case and the remaining to lower case.
|
|
6
6
|
*/
|
|
@@ -29,7 +29,7 @@ function _split(str, separator, limit) {
|
|
|
29
29
|
}
|
|
30
30
|
exports._split = _split;
|
|
31
31
|
function _removeWhitespace(s) {
|
|
32
|
-
return s.
|
|
32
|
+
return s.replaceAll(/\s/g, '');
|
|
33
33
|
}
|
|
34
34
|
exports._removeWhitespace = _removeWhitespace;
|
|
35
35
|
/**
|
|
@@ -92,21 +92,11 @@ function _substringBetweenLast(s, leftDelimiter, rightDelimiter) {
|
|
|
92
92
|
return _substringBefore(_substringAfterLast(s, leftDelimiter), rightDelimiter);
|
|
93
93
|
}
|
|
94
94
|
exports._substringBetweenLast = _substringBetweenLast;
|
|
95
|
-
/**
|
|
96
|
-
* Polyfill for es2021 `String.prototype.replaceAll`.
|
|
97
|
-
* Uses regex implementation that's a bit faster than another popular "split/join" implementation.
|
|
98
|
-
*
|
|
99
|
-
* Based on: https://stackoverflow.com/a/1144788/4919972
|
|
100
|
-
*/
|
|
101
|
-
function _replaceAll(s, find, replaceWith) {
|
|
102
|
-
return s.replace(new RegExp(find, 'g'), replaceWith);
|
|
103
|
-
}
|
|
104
|
-
exports._replaceAll = _replaceAll;
|
|
105
95
|
/**
|
|
106
96
|
* Converts `\n` (aka new-line) to `<br>`, to be presented in HTML.
|
|
107
97
|
* Keeps `\n`, so if it's printed in non-HTML environment it still looks ok-ish.
|
|
108
98
|
*/
|
|
109
99
|
function _nl2br(s) {
|
|
110
|
-
return s.
|
|
100
|
+
return s.replaceAll('\n', '<br>\n');
|
|
111
101
|
}
|
|
112
102
|
exports._nl2br = _nl2br;
|
|
@@ -275,7 +275,7 @@ export function _invertMap(m) {
|
|
|
275
275
|
*/
|
|
276
276
|
export function _get(obj = {}, path = '') {
|
|
277
277
|
return path
|
|
278
|
-
.
|
|
278
|
+
.replaceAll(/\[([^\]]+)]/g, '.$1')
|
|
279
279
|
.split('.')
|
|
280
280
|
.reduce((o, p) => o === null || o === void 0 ? void 0 : o[p], obj);
|
|
281
281
|
}
|
package/dist-esm/string/case.js
CHANGED
|
@@ -2,14 +2,14 @@ import { words } from './lodash/words';
|
|
|
2
2
|
import { _upperFirst } from './string.util';
|
|
3
3
|
export function _camelCase(s) {
|
|
4
4
|
// return s.replace(/(_\w)/g, m => m[1]!.toUpperCase())
|
|
5
|
-
return words(s.
|
|
5
|
+
return words(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => {
|
|
6
6
|
word = word.toLowerCase();
|
|
7
7
|
return result + (index ? _upperFirst(word) : word);
|
|
8
8
|
}, '');
|
|
9
9
|
}
|
|
10
10
|
export function _snakeCase(s) {
|
|
11
|
-
return words(s.
|
|
11
|
+
return words(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '_' : '') + word.toLowerCase(), '');
|
|
12
12
|
}
|
|
13
13
|
export function _kebabCase(s) {
|
|
14
|
-
return words(s.
|
|
14
|
+
return words(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => result + (index ? '-' : '') + word.toLowerCase(), '');
|
|
15
15
|
}
|
|
@@ -13,19 +13,19 @@ Reasons:
|
|
|
13
13
|
// Multiple `.replace()` calls are actually faster than using replacer functions
|
|
14
14
|
function _htmlEscape(s) {
|
|
15
15
|
return s
|
|
16
|
-
.
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
.
|
|
20
|
-
.
|
|
16
|
+
.replaceAll('&', '&') // Must happen first or else it will escape other just-escaped characters.
|
|
17
|
+
.replaceAll('"', '"')
|
|
18
|
+
.replaceAll("'", ''')
|
|
19
|
+
.replaceAll('<', '<')
|
|
20
|
+
.replaceAll('>', '>');
|
|
21
21
|
}
|
|
22
22
|
function _htmlUnescape(html) {
|
|
23
23
|
return html
|
|
24
|
-
.
|
|
25
|
-
.
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.
|
|
24
|
+
.replaceAll('>', '>')
|
|
25
|
+
.replaceAll('<', '<')
|
|
26
|
+
.replaceAll(/�?39;/g, "'")
|
|
27
|
+
.replaceAll('"', '"')
|
|
28
|
+
.replaceAll('&', '&'); // Must happen last or else it will unescape other characters in the wrong order.
|
|
29
29
|
}
|
|
30
30
|
export function htmlEscape(strings, ...values) {
|
|
31
31
|
if (typeof strings === 'string') {
|
package/dist-esm/string/pupa.js
CHANGED
|
@@ -48,8 +48,8 @@ export function pupa(template, data, opt = {}) {
|
|
|
48
48
|
// The regex tries to match either a number inside `{{ }}` or a valid JS identifier or key path.
|
|
49
49
|
const doubleBraceRegex = /{{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}}/gi;
|
|
50
50
|
if (doubleBraceRegex.test(template)) {
|
|
51
|
-
template = template.
|
|
51
|
+
template = template.replaceAll(doubleBraceRegex, composeHtmlEscape(replace));
|
|
52
52
|
}
|
|
53
53
|
const braceRegex = /{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}/gi;
|
|
54
|
-
return template.
|
|
54
|
+
return template.replaceAll(braceRegex, replace);
|
|
55
55
|
}
|
|
@@ -22,7 +22,7 @@ export function _split(str, separator, limit) {
|
|
|
22
22
|
return [...parts.slice(0, limit - 1), parts.slice(limit - 1).join(separator)];
|
|
23
23
|
}
|
|
24
24
|
export function _removeWhitespace(s) {
|
|
25
|
-
return s.
|
|
25
|
+
return s.replaceAll(/\s/g, '');
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* _.truncate('hi-diddly-ho there, neighborino')
|
|
@@ -77,19 +77,10 @@ export function _substringAfterLast(s, delimiter) {
|
|
|
77
77
|
export function _substringBetweenLast(s, leftDelimiter, rightDelimiter) {
|
|
78
78
|
return _substringBefore(_substringAfterLast(s, leftDelimiter), rightDelimiter);
|
|
79
79
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Polyfill for es2021 `String.prototype.replaceAll`.
|
|
82
|
-
* Uses regex implementation that's a bit faster than another popular "split/join" implementation.
|
|
83
|
-
*
|
|
84
|
-
* Based on: https://stackoverflow.com/a/1144788/4919972
|
|
85
|
-
*/
|
|
86
|
-
export function _replaceAll(s, find, replaceWith) {
|
|
87
|
-
return s.replace(new RegExp(find, 'g'), replaceWith);
|
|
88
|
-
}
|
|
89
80
|
/**
|
|
90
81
|
* Converts `\n` (aka new-line) to `<br>`, to be presented in HTML.
|
|
91
82
|
* Keeps `\n`, so if it's printed in non-HTML environment it still looks ok-ish.
|
|
92
83
|
*/
|
|
93
84
|
export function _nl2br(s) {
|
|
94
|
-
return s.
|
|
85
|
+
return s.replaceAll('\n', '<br>\n');
|
|
95
86
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.149.
|
|
3
|
+
"version": "14.149.3",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@naturalcycles/dev-lib": "^13.0.1",
|
|
17
17
|
"@naturalcycles/nodejs-lib": "^12.33.4",
|
|
18
18
|
"@naturalcycles/time-lib": "^3.5.1",
|
|
19
|
-
"@types/node": "^
|
|
19
|
+
"@types/node": "^20.1.0",
|
|
20
20
|
"jest": "^29.0.0",
|
|
21
21
|
"prettier": "^2.1.2",
|
|
22
22
|
"rxjs": "^7.0.1",
|
|
@@ -322,7 +322,7 @@ export function _invertMap<K, V>(m: ReadonlyMap<K, V>): Map<V, K> {
|
|
|
322
322
|
*/
|
|
323
323
|
export function _get<T extends AnyObject>(obj = {} as T, path = ''): unknown {
|
|
324
324
|
return path
|
|
325
|
-
.
|
|
325
|
+
.replaceAll(/\[([^\]]+)]/g, '.$1')
|
|
326
326
|
.split('.')
|
|
327
327
|
.reduce((o, p) => o?.[p], obj)
|
|
328
328
|
}
|
package/src/string/case.ts
CHANGED
|
@@ -3,21 +3,21 @@ import { _upperFirst } from './string.util'
|
|
|
3
3
|
|
|
4
4
|
export function _camelCase(s: string): string {
|
|
5
5
|
// return s.replace(/(_\w)/g, m => m[1]!.toUpperCase())
|
|
6
|
-
return words(s.
|
|
6
|
+
return words(s.replaceAll(/['\u2019]/g, '')).reduce((result, word, index) => {
|
|
7
7
|
word = word.toLowerCase()
|
|
8
8
|
return result + (index ? _upperFirst(word) : word)
|
|
9
9
|
}, '')
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function _snakeCase(s: string): string {
|
|
13
|
-
return words(s.
|
|
13
|
+
return words(s.replaceAll(/['\u2019]/g, '')).reduce(
|
|
14
14
|
(result, word, index) => result + (index ? '_' : '') + word.toLowerCase(),
|
|
15
15
|
'',
|
|
16
16
|
)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export function _kebabCase(s: string): string {
|
|
20
|
-
return words(s.
|
|
20
|
+
return words(s.replaceAll(/['\u2019]/g, '')).reduce(
|
|
21
21
|
(result, word, index) => result + (index ? '-' : '') + word.toLowerCase(),
|
|
22
22
|
'',
|
|
23
23
|
)
|
package/src/string/escape.ts
CHANGED
|
@@ -14,20 +14,20 @@ Reasons:
|
|
|
14
14
|
// Multiple `.replace()` calls are actually faster than using replacer functions
|
|
15
15
|
function _htmlEscape(s: string): string {
|
|
16
16
|
return s
|
|
17
|
-
.
|
|
18
|
-
.
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.
|
|
17
|
+
.replaceAll('&', '&') // Must happen first or else it will escape other just-escaped characters.
|
|
18
|
+
.replaceAll('"', '"')
|
|
19
|
+
.replaceAll("'", ''')
|
|
20
|
+
.replaceAll('<', '<')
|
|
21
|
+
.replaceAll('>', '>')
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
function _htmlUnescape(html: string): string {
|
|
25
25
|
return html
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
.
|
|
29
|
-
.
|
|
30
|
-
.
|
|
26
|
+
.replaceAll('>', '>')
|
|
27
|
+
.replaceAll('<', '<')
|
|
28
|
+
.replaceAll(/�?39;/g, "'")
|
|
29
|
+
.replaceAll('"', '"')
|
|
30
|
+
.replaceAll('&', '&') // Must happen last or else it will unescape other characters in the wrong order.
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function htmlEscape(strings: string | TemplateStringsArray, ...values: any[]): string {
|
package/src/string/pupa.ts
CHANGED
|
@@ -77,10 +77,10 @@ export function pupa(template: string, data: any[] | AnyObject, opt: PupaOptions
|
|
|
77
77
|
const doubleBraceRegex = /{{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}}/gi
|
|
78
78
|
|
|
79
79
|
if (doubleBraceRegex.test(template)) {
|
|
80
|
-
template = template.
|
|
80
|
+
template = template.replaceAll(doubleBraceRegex, composeHtmlEscape(replace))
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
const braceRegex = /{(\d+|[a-z$_][\w\-$]*?(?:\.[\w\-$]*?)*?)}/gi
|
|
84
84
|
|
|
85
|
-
return template.
|
|
85
|
+
return template.replaceAll(braceRegex, replace)
|
|
86
86
|
}
|
|
@@ -25,7 +25,7 @@ export function _split(str: string, separator: string, limit: number): string[]
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
export function _removeWhitespace(s: string): string {
|
|
28
|
-
return s.
|
|
28
|
+
return s.replaceAll(/\s/g, '')
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
@@ -90,20 +90,10 @@ export function _substringBetweenLast(
|
|
|
90
90
|
return _substringBefore(_substringAfterLast(s, leftDelimiter), rightDelimiter)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
/**
|
|
94
|
-
* Polyfill for es2021 `String.prototype.replaceAll`.
|
|
95
|
-
* Uses regex implementation that's a bit faster than another popular "split/join" implementation.
|
|
96
|
-
*
|
|
97
|
-
* Based on: https://stackoverflow.com/a/1144788/4919972
|
|
98
|
-
*/
|
|
99
|
-
export function _replaceAll(s: string, find: string, replaceWith: string): string {
|
|
100
|
-
return s.replace(new RegExp(find, 'g'), replaceWith)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
93
|
/**
|
|
104
94
|
* Converts `\n` (aka new-line) to `<br>`, to be presented in HTML.
|
|
105
95
|
* Keeps `\n`, so if it's printed in non-HTML environment it still looks ok-ish.
|
|
106
96
|
*/
|
|
107
97
|
export function _nl2br(s: string): string {
|
|
108
|
-
return s.
|
|
98
|
+
return s.replaceAll('\n', '<br>\n')
|
|
109
99
|
}
|