char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
8ee750c
main
1import { 2JSONStringify , 3RangeError , 4TypeError , 5} from "ext:core/primordials" ; 6import { 7op_fjson_apply , 8op_fjson_parse , 9op_fjson_stringify , 10} from "ext:core/ops" ; 11 12const JSONParse = JSON . parse ; 13const ParseError = SyntaxError ; 14 15export function parse ( source :string ) :unknown { 16const result = op_fjson_parse ( ` ${ source } ` ); 17if ( result [ 1 ] !== null ) throw new ParseError ( result [ 1 ]); 18return JSONParse ( result [ 0 ]); 19} 20 21export function stringify ( value :unknown ) :string { 22const json = JSONStringify ( value ); 23if ( json === undefined ) throw new TypeError ( "Value is not JSON serializable" ); 24const result = op_fjson_stringify ( json ); 25if ( result [ 1 ] !== null ) { 26const ErrorClass = result [ 2 ] ?RangeError :TypeError ; 27throw new ErrorClass ( result [ 1 ]); 28} 29return result [ 0 ]; 30} 31 32export function apply ( source :string , ...overrides :Record < string , unknown >[]) :string { 33return op_fjson_apply ( ` ${ source } ` , overrides ); 34}