Skip to content

Commit 1466381

Browse files
committed
feat: use flatted instead of JSON for parse/stringify
1 parent 709620c commit 1466381

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Emitter = require("component-emitter");
2+
import { parse, stringify } from "flatted";
23
import { deconstructPacket, reconstructPacket } from "./binary";
34
import { isBinary, hasBinary } from "./is-binary";
45

@@ -85,7 +86,7 @@ export class Encoder {
8586

8687
// json data
8788
if (null != obj.data) {
88-
str += JSON.stringify(obj.data);
89+
str += stringify(obj.data);
8990
}
9091

9192
debug("encoded %j as %s", obj, str);
@@ -264,7 +265,7 @@ export class Decoder extends Emitter {
264265

265266
function tryParse(str) {
266267
try {
267-
return JSON.parse(str);
268+
return parse(str);
268269
} catch (e) {
269270
return false;
270271
}

0 commit comments

Comments
 (0)