@keyv/serialize 1.1.0 → 6.0.0-alpha.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/README.md +1 -1
- package/dist/index.cjs +10 -5
- package/dist/index.js +10 -5
- package/package.json +22 -16
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://github.com/jaredwray/keyv/blob/main/LICENSE)
|
|
9
9
|
[](https://npmjs.com/package/@keyv/serialize)
|
|
10
10
|
|
|
11
|
-
This is the serialization functionality for [Keyv](https://github.com/jaredwray/keyv/tree/main/
|
|
11
|
+
This is the serialization functionality for [Keyv](https://github.com/jaredwray/keyv/tree/main/core/keyv). It is used to serialize and deserialize data for storage and retrieval. You can also create your own [custom serialization functions](https://github.com/jaredwray/keyv/tree/main/core/keyv#custom-serializers).
|
|
12
12
|
|
|
13
13
|
## License
|
|
14
14
|
|
package/dist/index.cjs
CHANGED
|
@@ -25,15 +25,17 @@ __export(index_exports, {
|
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(index_exports);
|
|
27
27
|
var import_node_buffer = require("buffer");
|
|
28
|
-
var
|
|
28
|
+
var _serialize = (data, escapeColonStrings = true) => {
|
|
29
29
|
if (data === void 0 || data === null) {
|
|
30
30
|
return "null";
|
|
31
31
|
}
|
|
32
32
|
if (typeof data === "string") {
|
|
33
|
-
return JSON.stringify(
|
|
33
|
+
return JSON.stringify(
|
|
34
|
+
escapeColonStrings && data.startsWith(":") ? `:${data}` : data
|
|
35
|
+
);
|
|
34
36
|
}
|
|
35
37
|
if (import_node_buffer.Buffer.isBuffer(data)) {
|
|
36
|
-
return JSON.stringify(
|
|
38
|
+
return JSON.stringify(`:base64:${data.toString("base64")}`);
|
|
37
39
|
}
|
|
38
40
|
if (data?.toJSON) {
|
|
39
41
|
data = data.toJSON();
|
|
@@ -53,9 +55,9 @@ var defaultSerialize = (data) => {
|
|
|
53
55
|
}
|
|
54
56
|
first = false;
|
|
55
57
|
if (array) {
|
|
56
|
-
s +=
|
|
58
|
+
s += _serialize(data[k], escapeColonStrings);
|
|
57
59
|
} else if (data[k] !== void 0) {
|
|
58
|
-
s +=
|
|
60
|
+
s += `${_serialize(k, false)}:${_serialize(data[k], escapeColonStrings)}`;
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
s += array ? "]" : "}";
|
|
@@ -63,6 +65,9 @@ var defaultSerialize = (data) => {
|
|
|
63
65
|
}
|
|
64
66
|
return JSON.stringify(data);
|
|
65
67
|
};
|
|
68
|
+
var defaultSerialize = (data) => {
|
|
69
|
+
return _serialize(data, true);
|
|
70
|
+
};
|
|
66
71
|
var defaultDeserialize = (data) => JSON.parse(data, (_, value) => {
|
|
67
72
|
if (typeof value === "string") {
|
|
68
73
|
if (value.startsWith(":base64:")) {
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { Buffer } from "buffer";
|
|
3
|
-
var
|
|
3
|
+
var _serialize = (data, escapeColonStrings = true) => {
|
|
4
4
|
if (data === void 0 || data === null) {
|
|
5
5
|
return "null";
|
|
6
6
|
}
|
|
7
7
|
if (typeof data === "string") {
|
|
8
|
-
return JSON.stringify(
|
|
8
|
+
return JSON.stringify(
|
|
9
|
+
escapeColonStrings && data.startsWith(":") ? `:${data}` : data
|
|
10
|
+
);
|
|
9
11
|
}
|
|
10
12
|
if (Buffer.isBuffer(data)) {
|
|
11
|
-
return JSON.stringify(
|
|
13
|
+
return JSON.stringify(`:base64:${data.toString("base64")}`);
|
|
12
14
|
}
|
|
13
15
|
if (data?.toJSON) {
|
|
14
16
|
data = data.toJSON();
|
|
@@ -28,9 +30,9 @@ var defaultSerialize = (data) => {
|
|
|
28
30
|
}
|
|
29
31
|
first = false;
|
|
30
32
|
if (array) {
|
|
31
|
-
s +=
|
|
33
|
+
s += _serialize(data[k], escapeColonStrings);
|
|
32
34
|
} else if (data[k] !== void 0) {
|
|
33
|
-
s +=
|
|
35
|
+
s += `${_serialize(k, false)}:${_serialize(data[k], escapeColonStrings)}`;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
36
38
|
s += array ? "]" : "}";
|
|
@@ -38,6 +40,9 @@ var defaultSerialize = (data) => {
|
|
|
38
40
|
}
|
|
39
41
|
return JSON.stringify(data);
|
|
40
42
|
};
|
|
43
|
+
var defaultSerialize = (data) => {
|
|
44
|
+
return _serialize(data, true);
|
|
45
|
+
};
|
|
41
46
|
var defaultDeserialize = (data) => JSON.parse(data, (_, value) => {
|
|
42
47
|
if (typeof value === "string") {
|
|
43
48
|
if (value.startsWith(":base64:")) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keyv/serialize",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0-alpha.1",
|
|
4
4
|
"description": "Serialization for Keyv",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.
|
|
7
|
-
"module": "dist/index.js",
|
|
8
|
-
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"require":
|
|
12
|
-
|
|
11
|
+
"require": {
|
|
12
|
+
"types": "./dist/index.d.cts",
|
|
13
|
+
"default": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
13
19
|
}
|
|
14
20
|
},
|
|
15
21
|
"repository": {
|
|
@@ -30,14 +36,12 @@
|
|
|
30
36
|
},
|
|
31
37
|
"homepage": "https://github.com/jaredwray/keyv",
|
|
32
38
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"@keyv/test-suite": "^2.0.9",
|
|
40
|
-
"keyv": "^5.3.4"
|
|
39
|
+
"@biomejs/biome": "^2.3.13",
|
|
40
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
41
|
+
"rimraf": "^6.1.2",
|
|
42
|
+
"tsd": "^0.33.0",
|
|
43
|
+
"typescript": "^5.9.3",
|
|
44
|
+
"vitest": "^4.0.18"
|
|
41
45
|
},
|
|
42
46
|
"tsd": {
|
|
43
47
|
"directory": "test"
|
|
@@ -48,8 +52,10 @@
|
|
|
48
52
|
],
|
|
49
53
|
"scripts": {
|
|
50
54
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
55
|
+
"lint": "biome check --write --error-on-warnings",
|
|
56
|
+
"lint:ci": "biome check --error-on-warnings",
|
|
57
|
+
"test": "pnpm lint && vitest run --coverage",
|
|
58
|
+
"test:ci": "pnpm lint:ci && vitest --run --sequence.setupFiles=list --coverage",
|
|
53
59
|
"clean": "rimraf ./node_modules ./coverage ./dist"
|
|
54
60
|
}
|
|
55
61
|
}
|