@muze-nl/od-jsontag 0.2.7 → 0.2.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@muze-nl/od-jsontag",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "On Demand JSONTag: parse/serialize large datastructures on demand, useful for sharing data between threads",
5
5
  "type": "module",
6
6
  "author": "Auke van Slooten <auke@muze.nl>",
package/src/serialize.mjs CHANGED
@@ -6,6 +6,7 @@ import * as odJSONTag from './jsontag.mjs'
6
6
  //
7
7
  const encoder = new TextEncoder()
8
8
  const decoder = new TextDecoder()
9
+ const realJSON = JSON // in case someone redefines JSON as JSONTag later
9
10
 
10
11
  function stringToSAB(strData) {
11
12
  const buffer = encoder.encode(strData)
@@ -61,7 +62,7 @@ export default function serialize(value, options={}) {
61
62
  if (odJSONTag.isNull(value)) {
62
63
  value = 'null'
63
64
  } else {
64
- value = JSON.stringify(''+value)
65
+ value = realJSON.stringify(''+value)
65
66
  }
66
67
  prop = typeString + value
67
68
  break
@@ -84,7 +85,7 @@ export default function serialize(value, options={}) {
84
85
  if (odJSONTag.isNull(value)) {
85
86
  value = 'null'
86
87
  } else {
87
- value = JSON.stringify(value)
88
+ value = realJSON.stringify(value)
88
89
  }
89
90
  prop = typeString + value
90
91
  break
@@ -138,7 +139,7 @@ export default function serialize(value, options={}) {
138
139
  let value = object[key]
139
140
  let prop = stringifyValue(value, false, current)
140
141
  let enumerable = object.propertyIsEnumerable(key) ? '' : '#'
141
- props.push(enumerable+'"'+key+'":'+prop)
142
+ props.push(enumerable+realJSON.stringify(key)+':'+prop) //FIXME: how does key get escaped?
142
143
  }
143
144
  result = odJSONTag.getTypeString(object)+'{'+props.join(',')+'}'
144
145
  return result