@@ -163,14 +163,14 @@ structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
163163 - [ ` Promise.withResolvers ` ] ( #promisewithresolvers )
164164 - [ ` Symbol.asyncIterator ` for asynchronous iteration] ( #symbolasynciterator-for-asynchronous-iteration )
165165 - [ ` Symbol.prototype.description ` ] ( #symbolprototypedescription )
166+ - [ ` JSON.parse ` source text access] ( #jsonparse-source-text-access )
166167 - [ Well-formed ` JSON.stringify ` ] ( #well-formed-jsonstringify )
167168 - [ Well-formed unicode strings] ( #well-formed-unicode-strings )
168169 - [ New ` Set ` methods] ( #new-set-methods )
169170 - [ ` Math.sumPrecise ` ] ( #mathsumprecise )
170171 - [ Stage 3 proposals] ( #stage-3-proposals )
171172 - [ ` Iterator ` sequencing] ( #iterator-sequencing )
172173 - [ ` Map ` upsert] ( #map-upsert )
173- - [ ` JSON.parse ` source text access] ( #jsonparse-source-text-access )
174174 - [ ` Symbol.metadata ` for decorators metadata proposal] ( #symbolmetadata-for-decorators-metadata-proposal )
175175 - [ Stage 2.7 proposals] ( #stage-27-proposals )
176176 - [ ` Iterator ` chunking] ( #iterator-chunking )
@@ -2134,21 +2134,45 @@ instance.c; // => 42
21342134#### ECMAScript: JSON[ ⬆] ( #index )
21352135Since ` JSON ` object is missed only in very old engines like IE7-, ` core-js ` does not provide a full ` JSON ` polyfill, however, fix already existing implementations by the current standard, for example, [ well-formed ` JSON.stringify ` ] ( https://github.com/tc39/proposal-well-formed-stringify ) . ` JSON ` is also fixed in other modules - for example, ` Symbol ` polyfill fixes ` JSON.stringify ` for correct work with symbols.
21362136
2137- Module [ ` es.json.to-string-tag ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.to-string-tag .js ) and [ ` es.json.stringify ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.stringify.js ) .
2137+ Module [ ` es.json.is-raw-json ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.is-raw-json .js ) , [ ` es.json.parse ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.parse.js ) , [ ` es.json.raw-json ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.raw-json.js ) , [ ` es.json. stringify` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.stringify.js ) and [ ` es.json.to-string-tag ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/es.json.to-string-tag.js ) .
21382138``` ts
21392139namespace JSON {
2140+ isRawJSON (O : any ): boolean ;
2141+ parse (text : string , reviver ?: (this : any , key : string , value : any , context : { source? : string }) => any ): any ;
2142+ rawJSON (text : any ): RawJSON ;
21402143 stringify (value : any , replacer ?: Array < string | number > | (this : any , key : string , value : any ) => any , space ?: string | number ): string | void ;
21412144 @@toStringTag : ' JSON' ;
21422145}
21432146```
21442147[ * CommonJS entry points:* ] ( #commonjs-api )
21452148```
2149+ core-js(-pure)/es|stable|actual|full/json/is-raw-json
2150+ core-js(-pure)/es|stable|actual|full/json/parse
2151+ core-js(-pure)/es|stable|actual|full/json/raw-json
2152+ core-js(-pure)/es|stable|actual|full/json/stringify
21462153core-js(-pure)/es|stable|actual|full/json/stringify
21472154core-js(-pure)/es|stable|actual|full/json/to-string-tag
21482155```
2149- [ * Examples* ] ( https://is.gd/izZqKn ) :
2156+ [ * Examples* ] ( https://tinyurl.com/34ctm7cn ) :
21502157``` js
21512158JSON .stringify ({ ' 𠮷' : [' \uDF06\uD834 ' ] }); // => '{"𠮷":["\\udf06\\ud834"]}'
2159+
2160+ function digitsToBigInt (key , val , { source }) {
2161+ return / ^ \d + $ / .test (source) ? BigInt (source) : val;
2162+ }
2163+
2164+ function bigIntToRawJSON (key , val ) {
2165+ return typeof val === ' bigint' ? JSON .rawJSON (String (val)) : val;
2166+ }
2167+
2168+ const tooBigForNumber = BigInt (Number .MAX_SAFE_INTEGER ) + 2n ;
2169+ JSON .parse (String (tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
2170+
2171+ const wayTooBig = BigInt (` 1${ ' 0' .repeat (1000 ) } ` );
2172+ JSON .parse (String (wayTooBig), digitsToBigInt) === wayTooBig; // true
2173+
2174+ const embedded = JSON .stringify ({ tooBigForNumber }, bigIntToRawJSON);
2175+ embedded === ' {"tooBigForNumber":9007199254740993}' ; // true
21522176```
21532177
21542178#### ECMAScript: globalThis[ ⬆] ( #index )
@@ -2631,6 +2655,23 @@ class Symbol {
26312655```
26322656core-js/proposals/symbol-description
26332657```
2658+
2659+ ##### [ ` JSON.parse ` source text access] ( https://github.com/tc39/proposal-json-parse-with-source ) [ ⬆] ( #index )
2660+ ``` ts
2661+ namespace JSON {
2662+ isRawJSON (O : any ): boolean ;
2663+ // patched for source support
2664+ parse (text : string , reviver ?: (this : any , key : string , value : any , context : { source? : string }) => any ): any ;
2665+ rawJSON (text : any ): RawJSON ;
2666+ // patched for `JSON.rawJSON` support
2667+ stringify (value : any , replacer ?: Array < string | number > | (this : any , key : string , value : any ) => any , space ?: string | number ): string | void ;
2668+ }
2669+ ```
2670+ [ * CommonJS entry points:* ] ( #commonjs-api )
2671+ ```
2672+ core-js/proposals/json-parse-with-source
2673+ ```
2674+
26342675##### [ Well-formed ` JSON.stringify ` ] ( https://github.com/tc39/proposal-well-formed-stringify ) [ ⬆] ( #index )
26352676``` ts
26362677namespace JSON {
@@ -2743,46 +2784,6 @@ map.getOrInsertComputed('c', key => key); // => 'c'
27432784console .log (map); // => Map { 'a': 1, 'b': 3, 'c': 'c' }
27442785```
27452786
2746- ##### [ ` JSON.parse ` source text access] ( https://github.com/tc39/proposal-json-parse-with-source ) [ ⬆] ( #index )
2747- Modules [ ` esnext.json.is-raw-json ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.is-raw-json.js ) , [ ` esnext.json.parse ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.parse.js ) , [ ` esnext.json.raw-json ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.json.raw-json.js ) .
2748- ``` ts
2749- namespace JSON {
2750- isRawJSON (O : any ): boolean ;
2751- // patched for source support
2752- parse (text : string , reviver ?: (this : any , key : string , value : any , context : { source? : string }) => any ): any ;
2753- rawJSON (text : any ): RawJSON ;
2754- // patched for `JSON.rawJSON` support
2755- stringify (value : any , replacer ?: Array < string | number > | (this : any , key : string , value : any ) => any , space ?: string | number ): string | void ;
2756- }
2757- ```
2758- [ * CommonJS entry points:* ] ( #commonjs-api )
2759- ```
2760- core-js/proposals/json-parse-with-source
2761- core-js(-pure)/actual|full/json/is-raw-json
2762- core-js(-pure)/actual|full/json/parse
2763- core-js(-pure)/actual|full/json/raw-json
2764- core-js(-pure)/actual|full/json/stringify
2765- ```
2766- [ * Examples* ] ( https://tinyurl.com/22phm569 ) :
2767- ``` js
2768- function digitsToBigInt (key , val , { source }) {
2769- return / ^ \d + $ / .test (source) ? BigInt (source) : val;
2770- }
2771-
2772- function bigIntToRawJSON (key , val ) {
2773- return typeof val === ' bigint' ? JSON .rawJSON (String (val)) : val;
2774- }
2775-
2776- const tooBigForNumber = BigInt (Number .MAX_SAFE_INTEGER ) + 2n ;
2777- JSON .parse (String (tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
2778-
2779- const wayTooBig = BigInt (` 1${ ' 0' .repeat (1000 ) } ` );
2780- JSON .parse (String (wayTooBig), digitsToBigInt) === wayTooBig; // true
2781-
2782- const embedded = JSON .stringify ({ tooBigForNumber }, bigIntToRawJSON);
2783- embedded === ' {"tooBigForNumber":9007199254740993}' ; // true
2784- ```
2785-
27862787##### [ ` Symbol.metadata ` for decorators metadata proposal] ( https://github.com/tc39/proposal-decorator-metadata ) [ ⬆] ( #index )
27872788Modules [ ` esnext.symbol.metadata ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.symbol.metadata.js ) and [ ` esnext.function.metadata ` ] ( https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.function.metadata.js ) .
27882789``` ts
0 commit comments