Skip to content

Commit 6df52fe

Browse files
authored
Create jsonc.ts
1 parent 153e527 commit 6df52fe

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/jsonc/jsonc.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export const JSONC = {
2+
parse: (text : string, reviver?: (this: unknown, key: string, value: unknown) => unknown) => {
3+
text = text.replace(/((")(?:\\[\s\S]|.)*?\2|\/(?![*\/])(?:\\.|\[(?:\\.|.)\]|.)*?\/)|\/\/.*?$|\/\*[\s\S]*?\*\//gm, '$1');
4+
return JSON.parse(text, reviver);
5+
},
6+
stringify: JSON.stringify
7+
}

0 commit comments

Comments
 (0)