Skip to content

Commit

Permalink
Create jsonc.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqxx authored Oct 18, 2024
1 parent 153e527 commit 6df52fe
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/jsonc/jsonc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const JSONC = {
parse: (text : string, reviver?: (this: unknown, key: string, value: unknown) => unknown) => {
text = text.replace(/((")(?:\\[\s\S]|.)*?\2|\/(?![*\/])(?:\\.|\[(?:\\.|.)\]|.)*?\/)|\/\/.*?$|\/\*[\s\S]*?\*\//gm, '$1');
return JSON.parse(text, reviver);
},
stringify: JSON.stringify
}

0 comments on commit 6df52fe

Please sign in to comment.