@naturalcycles/js-lib 14.168.1 → 14.169.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/error/assert.js +12 -14
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/web.d.ts +18 -0
- package/dist/web.js +37 -0
- package/dist-esm/error/assert.js +12 -14
- package/dist-esm/index.js +1 -0
- package/dist-esm/web.js +35 -0
- package/package.json +1 -1
- package/src/error/assert.ts +14 -14
- package/src/index.ts +1 -0
- package/src/web.ts +41 -0
package/dist/error/assert.js
CHANGED
|
@@ -36,13 +36,10 @@ exports._assert = _assert;
|
|
|
36
36
|
*/
|
|
37
37
|
function _assertEquals(actual, expected, message, errorData) {
|
|
38
38
|
if (actual !== expected) {
|
|
39
|
-
const msg =
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join('\n');
|
|
39
|
+
const msg = message ||
|
|
40
|
+
['not equal', `expected: ${(0, __1._stringifyAny)(expected)}`, `got : ${(0, __1._stringifyAny)(actual)}`]
|
|
41
|
+
.filter(Boolean)
|
|
42
|
+
.join('\n');
|
|
46
43
|
throw new AssertionError(msg, {
|
|
47
44
|
userFriendly: true,
|
|
48
45
|
...errorData,
|
|
@@ -58,13 +55,14 @@ exports._assertEquals = _assertEquals;
|
|
|
58
55
|
*/
|
|
59
56
|
function _assertDeepEquals(actual, expected, message, errorData) {
|
|
60
57
|
if (!(0, __1._deepEquals)(actual, expected)) {
|
|
61
|
-
const msg =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
58
|
+
const msg = message ||
|
|
59
|
+
[
|
|
60
|
+
`not deeply equal`,
|
|
61
|
+
`expected: ${(0, __1._stringifyAny)(expected)}`,
|
|
62
|
+
`got : ${(0, __1._stringifyAny)(actual)}`,
|
|
63
|
+
]
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.join('\n');
|
|
68
66
|
throw new AssertionError(msg, {
|
|
69
67
|
userFriendly: true,
|
|
70
68
|
...errorData,
|
package/dist/index.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export * from './string/hash.util';
|
|
|
82
82
|
export * from './env/buildInfo';
|
|
83
83
|
export * from './form.util';
|
|
84
84
|
export * from './semver';
|
|
85
|
+
export * from './web';
|
|
85
86
|
export * from './zod/zod.util';
|
|
86
87
|
export * from './zod/zod.shared.schemas';
|
|
87
88
|
import { z, ZodSchema, ZodError, ZodIssue } from 'zod';
|
package/dist/index.js
CHANGED
|
@@ -86,6 +86,7 @@ tslib_1.__exportStar(require("./string/hash.util"), exports);
|
|
|
86
86
|
tslib_1.__exportStar(require("./env/buildInfo"), exports);
|
|
87
87
|
tslib_1.__exportStar(require("./form.util"), exports);
|
|
88
88
|
tslib_1.__exportStar(require("./semver"), exports);
|
|
89
|
+
tslib_1.__exportStar(require("./web"), exports);
|
|
89
90
|
tslib_1.__exportStar(require("./zod/zod.util"), exports);
|
|
90
91
|
tslib_1.__exportStar(require("./zod/zod.shared.schemas"), exports);
|
|
91
92
|
const zod_1 = require("zod");
|
package/dist/web.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { StringMap } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Implements WebStorage API by using in-memory storage.
|
|
5
|
+
* Can be useful in SSR environment or unit tests.
|
|
6
|
+
*
|
|
7
|
+
* @experimental
|
|
8
|
+
*/
|
|
9
|
+
export declare class InMemoryWebStorage implements Storage {
|
|
10
|
+
data: StringMap;
|
|
11
|
+
constructor(data?: StringMap);
|
|
12
|
+
getItem(key: string): string | null;
|
|
13
|
+
setItem(key: string, value: string): void;
|
|
14
|
+
removeItem(key: string): void;
|
|
15
|
+
key(index: number): string | null;
|
|
16
|
+
clear(): void;
|
|
17
|
+
get length(): number;
|
|
18
|
+
}
|
package/dist/web.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/// <reference lib="dom"/>
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InMemoryWebStorage = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Implements WebStorage API by using in-memory storage.
|
|
7
|
+
* Can be useful in SSR environment or unit tests.
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
10
|
+
*/
|
|
11
|
+
class InMemoryWebStorage {
|
|
12
|
+
constructor(data = {}) {
|
|
13
|
+
this.data = data;
|
|
14
|
+
}
|
|
15
|
+
// Not implementing "free property access" now for simplicity,
|
|
16
|
+
// but can be implemented with Proxy
|
|
17
|
+
// [ name: string ]: any
|
|
18
|
+
getItem(key) {
|
|
19
|
+
return this.data[key] ?? null;
|
|
20
|
+
}
|
|
21
|
+
setItem(key, value) {
|
|
22
|
+
this.data[key] = String(value);
|
|
23
|
+
}
|
|
24
|
+
removeItem(key) {
|
|
25
|
+
delete this.data[key];
|
|
26
|
+
}
|
|
27
|
+
key(index) {
|
|
28
|
+
return Object.keys(this.data)[index] ?? null;
|
|
29
|
+
}
|
|
30
|
+
clear() {
|
|
31
|
+
this.data = {};
|
|
32
|
+
}
|
|
33
|
+
get length() {
|
|
34
|
+
return Object.keys(this.data).length;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.InMemoryWebStorage = InMemoryWebStorage;
|
package/dist-esm/error/assert.js
CHANGED
|
@@ -29,13 +29,10 @@ message, errorData) {
|
|
|
29
29
|
*/
|
|
30
30
|
export function _assertEquals(actual, expected, message, errorData) {
|
|
31
31
|
if (actual !== expected) {
|
|
32
|
-
const msg =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
]
|
|
37
|
-
.filter(Boolean)
|
|
38
|
-
.join('\n');
|
|
32
|
+
const msg = message ||
|
|
33
|
+
['not equal', `expected: ${_stringifyAny(expected)}`, `got : ${_stringifyAny(actual)}`]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('\n');
|
|
39
36
|
throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
|
|
40
37
|
}
|
|
41
38
|
}
|
|
@@ -47,13 +44,14 @@ export function _assertEquals(actual, expected, message, errorData) {
|
|
|
47
44
|
*/
|
|
48
45
|
export function _assertDeepEquals(actual, expected, message, errorData) {
|
|
49
46
|
if (!_deepEquals(actual, expected)) {
|
|
50
|
-
const msg =
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
const msg = message ||
|
|
48
|
+
[
|
|
49
|
+
`not deeply equal`,
|
|
50
|
+
`expected: ${_stringifyAny(expected)}`,
|
|
51
|
+
`got : ${_stringifyAny(actual)}`,
|
|
52
|
+
]
|
|
53
|
+
.filter(Boolean)
|
|
54
|
+
.join('\n');
|
|
57
55
|
throw new AssertionError(msg, Object.assign({ userFriendly: true }, errorData));
|
|
58
56
|
}
|
|
59
57
|
}
|
package/dist-esm/index.js
CHANGED
|
@@ -82,6 +82,7 @@ export * from './string/hash.util';
|
|
|
82
82
|
export * from './env/buildInfo';
|
|
83
83
|
export * from './form.util';
|
|
84
84
|
export * from './semver';
|
|
85
|
+
export * from './web';
|
|
85
86
|
export * from './zod/zod.util';
|
|
86
87
|
export * from './zod/zod.shared.schemas';
|
|
87
88
|
import { z, ZodSchema, ZodError } from 'zod';
|
package/dist-esm/web.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/// <reference lib="dom"/>
|
|
2
|
+
/**
|
|
3
|
+
* Implements WebStorage API by using in-memory storage.
|
|
4
|
+
* Can be useful in SSR environment or unit tests.
|
|
5
|
+
*
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export class InMemoryWebStorage {
|
|
9
|
+
constructor(data = {}) {
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
// Not implementing "free property access" now for simplicity,
|
|
13
|
+
// but can be implemented with Proxy
|
|
14
|
+
// [ name: string ]: any
|
|
15
|
+
getItem(key) {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = this.data[key]) !== null && _a !== void 0 ? _a : null;
|
|
18
|
+
}
|
|
19
|
+
setItem(key, value) {
|
|
20
|
+
this.data[key] = String(value);
|
|
21
|
+
}
|
|
22
|
+
removeItem(key) {
|
|
23
|
+
delete this.data[key];
|
|
24
|
+
}
|
|
25
|
+
key(index) {
|
|
26
|
+
var _a;
|
|
27
|
+
return (_a = Object.keys(this.data)[index]) !== null && _a !== void 0 ? _a : null;
|
|
28
|
+
}
|
|
29
|
+
clear() {
|
|
30
|
+
this.data = {};
|
|
31
|
+
}
|
|
32
|
+
get length() {
|
|
33
|
+
return Object.keys(this.data).length;
|
|
34
|
+
}
|
|
35
|
+
}
|
package/package.json
CHANGED
package/src/error/assert.ts
CHANGED
|
@@ -43,13 +43,11 @@ export function _assertEquals<T>(
|
|
|
43
43
|
errorData?: ErrorData,
|
|
44
44
|
): asserts actual is T {
|
|
45
45
|
if (actual !== expected) {
|
|
46
|
-
const msg =
|
|
47
|
-
message ||
|
|
48
|
-
`expected: ${_stringifyAny(expected)}`,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
.filter(Boolean)
|
|
52
|
-
.join('\n')
|
|
46
|
+
const msg =
|
|
47
|
+
message ||
|
|
48
|
+
['not equal', `expected: ${_stringifyAny(expected)}`, `got : ${_stringifyAny(actual)}`]
|
|
49
|
+
.filter(Boolean)
|
|
50
|
+
.join('\n')
|
|
53
51
|
|
|
54
52
|
throw new AssertionError(msg, {
|
|
55
53
|
userFriendly: true,
|
|
@@ -71,13 +69,15 @@ export function _assertDeepEquals<T>(
|
|
|
71
69
|
errorData?: ErrorData,
|
|
72
70
|
): asserts actual is T {
|
|
73
71
|
if (!_deepEquals(actual, expected)) {
|
|
74
|
-
const msg =
|
|
75
|
-
message ||
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
const msg =
|
|
73
|
+
message ||
|
|
74
|
+
[
|
|
75
|
+
`not deeply equal`,
|
|
76
|
+
`expected: ${_stringifyAny(expected)}`,
|
|
77
|
+
`got : ${_stringifyAny(actual)}`,
|
|
78
|
+
]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join('\n')
|
|
81
81
|
|
|
82
82
|
throw new AssertionError(msg, {
|
|
83
83
|
userFriendly: true,
|
package/src/index.ts
CHANGED
|
@@ -82,6 +82,7 @@ export * from './string/hash.util'
|
|
|
82
82
|
export * from './env/buildInfo'
|
|
83
83
|
export * from './form.util'
|
|
84
84
|
export * from './semver'
|
|
85
|
+
export * from './web'
|
|
85
86
|
export * from './zod/zod.util'
|
|
86
87
|
export * from './zod/zod.shared.schemas'
|
|
87
88
|
import { z, ZodSchema, ZodError, ZodIssue } from 'zod'
|
package/src/web.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/// <reference lib="dom"/>
|
|
2
|
+
|
|
3
|
+
import { StringMap } from './types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Implements WebStorage API by using in-memory storage.
|
|
7
|
+
* Can be useful in SSR environment or unit tests.
|
|
8
|
+
*
|
|
9
|
+
* @experimental
|
|
10
|
+
*/
|
|
11
|
+
export class InMemoryWebStorage implements Storage {
|
|
12
|
+
constructor(public data: StringMap = {}) {}
|
|
13
|
+
|
|
14
|
+
// Not implementing "free property access" now for simplicity,
|
|
15
|
+
// but can be implemented with Proxy
|
|
16
|
+
// [ name: string ]: any
|
|
17
|
+
|
|
18
|
+
getItem(key: string): string | null {
|
|
19
|
+
return this.data[key] ?? null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
setItem(key: string, value: string): void {
|
|
23
|
+
this.data[key] = String(value)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
removeItem(key: string): void {
|
|
27
|
+
delete this.data[key]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
key(index: number): string | null {
|
|
31
|
+
return Object.keys(this.data)[index] ?? null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
clear(): void {
|
|
35
|
+
this.data = {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get length(): number {
|
|
39
|
+
return Object.keys(this.data).length
|
|
40
|
+
}
|
|
41
|
+
}
|