@live-change/serialization 0.9.162 → 0.9.163
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/package.json +2 -2
- package/serialization.js +4 -2
- package/stringKey.js +6 -0
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/serialization",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.163",
|
|
4
4
|
"scripts": {},
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Michał Łaszczewski <michal@laszczewski.pl>",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"description": "",
|
|
10
|
-
"gitHead": "
|
|
10
|
+
"gitHead": "c410e1dacd07daed9a5c55367abd7f19d9a575cc"
|
|
11
11
|
}
|
package/serialization.js
CHANGED
|
@@ -5,11 +5,12 @@ export const typeMap = Object.freeze({
|
|
|
5
5
|
'boolean': 'b',
|
|
6
6
|
'object': 'o',
|
|
7
7
|
'null': 'z',
|
|
8
|
-
'array': 'a'
|
|
8
|
+
'array': 'a',
|
|
9
|
+
'undefined': 'u'
|
|
9
10
|
})
|
|
10
11
|
|
|
11
12
|
export const types = Object.freeze(Object.fromEntries(
|
|
12
|
-
|
|
13
|
+
Object.entries(typeMap).map(([type, key]) => [key, type])
|
|
13
14
|
))
|
|
14
15
|
|
|
15
16
|
/** Serialize any data using writer
|
|
@@ -38,6 +39,7 @@ export function write(data, writer) {
|
|
|
38
39
|
write(value, writer)
|
|
39
40
|
}
|
|
40
41
|
return writer
|
|
42
|
+
case 'undefined': return writer.writeType(typeMap.undefined)
|
|
41
43
|
default:
|
|
42
44
|
throw new Error(`Unsupported type: ${typeof data}`)
|
|
43
45
|
}
|
package/stringKey.js
CHANGED
|
@@ -174,6 +174,12 @@ export function serializeKeyToString(key) {
|
|
|
174
174
|
return writer.getOutput()
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
export function serializeKeyDataToString(key) {
|
|
178
|
+
const writer = new StringKeyWriter()
|
|
179
|
+
write(key, writer)
|
|
180
|
+
return writer.getData()
|
|
181
|
+
}
|
|
182
|
+
|
|
177
183
|
export function deserializeKeyFromString(serialized, structure) {
|
|
178
184
|
const reader = new StringKeyReader(serialized, structure)
|
|
179
185
|
return read(reader)
|