@ls-stack/utils 3.16.0 → 3.17.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/lib/dedent.cjs +42 -23
- package/lib/dedent.d.cts +12 -4
- package/lib/dedent.d.ts +12 -4
- package/lib/dedent.js +42 -23
- package/lib/hash.cjs +57 -0
- package/lib/hash.d.cts +7 -0
- package/lib/hash.d.ts +7 -0
- package/lib/hash.js +32 -0
- package/package.json +9 -1
package/lib/dedent.cjs
CHANGED
|
@@ -23,33 +23,52 @@ __export(dedent_exports, {
|
|
|
23
23
|
dedent: () => dedent
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(dedent_exports);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
var dedent = createDedent({});
|
|
27
|
+
function createDedent(options) {
|
|
28
|
+
d.withOptions = (newOptions) => createDedent({ ...options, ...newOptions });
|
|
29
|
+
return d;
|
|
30
|
+
function d(strings, ...values) {
|
|
31
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
32
|
+
const {
|
|
33
|
+
escapeSpecialCharacters = Array.isArray(strings),
|
|
34
|
+
trimWhitespace = true
|
|
35
|
+
} = options;
|
|
36
|
+
let result = "";
|
|
37
|
+
for (let i = 0; i < raw.length; i++) {
|
|
38
|
+
let next = raw[i];
|
|
39
|
+
if (escapeSpecialCharacters) {
|
|
40
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
41
|
+
}
|
|
42
|
+
result += next;
|
|
43
|
+
if (i < values.length) {
|
|
44
|
+
result += values[i];
|
|
45
|
+
}
|
|
33
46
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const lines = result.split("\n");
|
|
48
|
+
let mindent = null;
|
|
49
|
+
for (const l of lines) {
|
|
50
|
+
const m = l.match(/^(\s+)\S+/);
|
|
51
|
+
if (m) {
|
|
52
|
+
const indent = m[1].length;
|
|
53
|
+
if (!mindent) {
|
|
54
|
+
mindent = indent;
|
|
55
|
+
} else {
|
|
56
|
+
mindent = Math.min(mindent, indent);
|
|
57
|
+
}
|
|
45
58
|
}
|
|
46
59
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
if (mindent !== null) {
|
|
61
|
+
const m = mindent;
|
|
62
|
+
result = lines.map((l) => l[0] === " " || l[0] === " " ? l.slice(m) : l).join("\n");
|
|
63
|
+
}
|
|
64
|
+
if (trimWhitespace) {
|
|
65
|
+
result = result.trim();
|
|
66
|
+
}
|
|
67
|
+
if (escapeSpecialCharacters) {
|
|
68
|
+
result = result.replace(/\\n/g, "\n");
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
51
71
|
}
|
|
52
|
-
return result.trim().replace(/\\n/g, "\n");
|
|
53
72
|
}
|
|
54
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
55
74
|
0 && (module.exports = {
|
package/lib/dedent.d.cts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface DedentOptions {
|
|
2
|
+
escapeSpecialCharacters?: boolean;
|
|
3
|
+
trimWhitespace?: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface Dedent {
|
|
6
|
+
(literals: string): string;
|
|
7
|
+
(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
8
|
+
withOptions: CreateDedent;
|
|
9
|
+
}
|
|
10
|
+
type CreateDedent = (options: DedentOptions) => Dedent;
|
|
11
|
+
declare const dedent: Dedent;
|
|
4
12
|
|
|
5
|
-
export { dedent };
|
|
13
|
+
export { type CreateDedent, type Dedent, type DedentOptions, dedent };
|
package/lib/dedent.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
interface DedentOptions {
|
|
2
|
+
escapeSpecialCharacters?: boolean;
|
|
3
|
+
trimWhitespace?: boolean;
|
|
4
|
+
}
|
|
5
|
+
interface Dedent {
|
|
6
|
+
(literals: string): string;
|
|
7
|
+
(strings: TemplateStringsArray, ...values: unknown[]): string;
|
|
8
|
+
withOptions: CreateDedent;
|
|
9
|
+
}
|
|
10
|
+
type CreateDedent = (options: DedentOptions) => Dedent;
|
|
11
|
+
declare const dedent: Dedent;
|
|
4
12
|
|
|
5
|
-
export { dedent };
|
|
13
|
+
export { type CreateDedent, type Dedent, type DedentOptions, dedent };
|
package/lib/dedent.js
CHANGED
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
// src/dedent.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var dedent = createDedent({});
|
|
3
|
+
function createDedent(options) {
|
|
4
|
+
d.withOptions = (newOptions) => createDedent({ ...options, ...newOptions });
|
|
5
|
+
return d;
|
|
6
|
+
function d(strings, ...values) {
|
|
7
|
+
const raw = typeof strings === "string" ? [strings] : strings.raw;
|
|
8
|
+
const {
|
|
9
|
+
escapeSpecialCharacters = Array.isArray(strings),
|
|
10
|
+
trimWhitespace = true
|
|
11
|
+
} = options;
|
|
12
|
+
let result = "";
|
|
13
|
+
for (let i = 0; i < raw.length; i++) {
|
|
14
|
+
let next = raw[i];
|
|
15
|
+
if (escapeSpecialCharacters) {
|
|
16
|
+
next = next.replace(/\\\n[ \t]*/g, "").replace(/\\`/g, "`").replace(/\\\$/g, "$").replace(/\\\{/g, "{");
|
|
17
|
+
}
|
|
18
|
+
result += next;
|
|
19
|
+
if (i < values.length) {
|
|
20
|
+
result += values[i];
|
|
21
|
+
}
|
|
9
22
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
const lines = result.split("\n");
|
|
24
|
+
let mindent = null;
|
|
25
|
+
for (const l of lines) {
|
|
26
|
+
const m = l.match(/^(\s+)\S+/);
|
|
27
|
+
if (m) {
|
|
28
|
+
const indent = m[1].length;
|
|
29
|
+
if (!mindent) {
|
|
30
|
+
mindent = indent;
|
|
31
|
+
} else {
|
|
32
|
+
mindent = Math.min(mindent, indent);
|
|
33
|
+
}
|
|
21
34
|
}
|
|
22
35
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
if (mindent !== null) {
|
|
37
|
+
const m = mindent;
|
|
38
|
+
result = lines.map((l) => l[0] === " " || l[0] === " " ? l.slice(m) : l).join("\n");
|
|
39
|
+
}
|
|
40
|
+
if (trimWhitespace) {
|
|
41
|
+
result = result.trim();
|
|
42
|
+
}
|
|
43
|
+
if (escapeSpecialCharacters) {
|
|
44
|
+
result = result.replace(/\\n/g, "\n");
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
27
47
|
}
|
|
28
|
-
return result.trim().replace(/\\n/g, "\n");
|
|
29
48
|
}
|
|
30
49
|
export {
|
|
31
50
|
dedent
|
package/lib/hash.cjs
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/hash.ts
|
|
21
|
+
var hash_exports = {};
|
|
22
|
+
__export(hash_exports, {
|
|
23
|
+
murmur2: () => murmur2
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(hash_exports);
|
|
26
|
+
function murmur2(str) {
|
|
27
|
+
let h = 0;
|
|
28
|
+
let k, i = 0, len = str.length;
|
|
29
|
+
for (; len >= 4; ++i, len -= 4) {
|
|
30
|
+
k = str.charCodeAt(i) & 255 | (str.charCodeAt(++i) & 255) << 8 | (str.charCodeAt(++i) & 255) << 16 | (str.charCodeAt(++i) & 255) << 24;
|
|
31
|
+
k = /* Math.imul(k, m): */
|
|
32
|
+
(k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16);
|
|
33
|
+
k ^= /* k >>> r: */
|
|
34
|
+
k >>> 24;
|
|
35
|
+
h = /* Math.imul(k, m): */
|
|
36
|
+
(k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ /* Math.imul(h, m): */
|
|
37
|
+
(h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
|
|
38
|
+
}
|
|
39
|
+
switch (len) {
|
|
40
|
+
case 3:
|
|
41
|
+
h ^= (str.charCodeAt(i + 2) & 255) << 16;
|
|
42
|
+
case 2:
|
|
43
|
+
h ^= (str.charCodeAt(i + 1) & 255) << 8;
|
|
44
|
+
case 1:
|
|
45
|
+
h ^= str.charCodeAt(i) & 255;
|
|
46
|
+
h = /* Math.imul(h, m): */
|
|
47
|
+
(h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
|
|
48
|
+
}
|
|
49
|
+
h ^= h >>> 13;
|
|
50
|
+
h = /* Math.imul(h, m): */
|
|
51
|
+
(h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
|
|
52
|
+
return ((h ^ h >>> 15) >>> 0).toString(36);
|
|
53
|
+
}
|
|
54
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
55
|
+
0 && (module.exports = {
|
|
56
|
+
murmur2
|
|
57
|
+
});
|
package/lib/hash.d.cts
ADDED
package/lib/hash.d.ts
ADDED
package/lib/hash.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/hash.ts
|
|
2
|
+
function murmur2(str) {
|
|
3
|
+
let h = 0;
|
|
4
|
+
let k, i = 0, len = str.length;
|
|
5
|
+
for (; len >= 4; ++i, len -= 4) {
|
|
6
|
+
k = str.charCodeAt(i) & 255 | (str.charCodeAt(++i) & 255) << 8 | (str.charCodeAt(++i) & 255) << 16 | (str.charCodeAt(++i) & 255) << 24;
|
|
7
|
+
k = /* Math.imul(k, m): */
|
|
8
|
+
(k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16);
|
|
9
|
+
k ^= /* k >>> r: */
|
|
10
|
+
k >>> 24;
|
|
11
|
+
h = /* Math.imul(k, m): */
|
|
12
|
+
(k & 65535) * 1540483477 + ((k >>> 16) * 59797 << 16) ^ /* Math.imul(h, m): */
|
|
13
|
+
(h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
|
|
14
|
+
}
|
|
15
|
+
switch (len) {
|
|
16
|
+
case 3:
|
|
17
|
+
h ^= (str.charCodeAt(i + 2) & 255) << 16;
|
|
18
|
+
case 2:
|
|
19
|
+
h ^= (str.charCodeAt(i + 1) & 255) << 8;
|
|
20
|
+
case 1:
|
|
21
|
+
h ^= str.charCodeAt(i) & 255;
|
|
22
|
+
h = /* Math.imul(h, m): */
|
|
23
|
+
(h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
|
|
24
|
+
}
|
|
25
|
+
h ^= h >>> 13;
|
|
26
|
+
h = /* Math.imul(h, m): */
|
|
27
|
+
(h & 65535) * 1540483477 + ((h >>> 16) * 59797 << 16);
|
|
28
|
+
return ((h ^ h >>> 15) >>> 0).toString(36);
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
murmur2
|
|
32
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ls-stack/utils",
|
|
3
3
|
"description": "Typescript utils",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.17.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib"
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"import": "./lib/main.js",
|
|
19
19
|
"require": "./lib/main.cjs"
|
|
20
20
|
},
|
|
21
|
+
"./__snapshots__": {
|
|
22
|
+
"import": "./lib/__snapshots__.js",
|
|
23
|
+
"require": "./lib/__snapshots__.cjs"
|
|
24
|
+
},
|
|
21
25
|
"./arrayUtils": {
|
|
22
26
|
"import": "./lib/arrayUtils.js",
|
|
23
27
|
"require": "./lib/arrayUtils.cjs"
|
|
@@ -82,6 +86,10 @@
|
|
|
82
86
|
"import": "./lib/getValueStableKey.js",
|
|
83
87
|
"require": "./lib/getValueStableKey.cjs"
|
|
84
88
|
},
|
|
89
|
+
"./hash": {
|
|
90
|
+
"import": "./lib/hash.js",
|
|
91
|
+
"require": "./lib/hash.cjs"
|
|
92
|
+
},
|
|
85
93
|
"./interpolate": {
|
|
86
94
|
"import": "./lib/interpolate.js",
|
|
87
95
|
"require": "./lib/interpolate.cjs"
|