source: imaps-frontend/node_modules/core-js/modules/es.json.stringify.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[79a0317]1'use strict';
2var $ = require('../internals/export');
3var getBuiltIn = require('../internals/get-built-in');
4var apply = require('../internals/function-apply');
5var call = require('../internals/function-call');
6var uncurryThis = require('../internals/function-uncurry-this');
7var fails = require('../internals/fails');
8var isCallable = require('../internals/is-callable');
9var isSymbol = require('../internals/is-symbol');
10var arraySlice = require('../internals/array-slice');
11var getReplacerFunction = require('../internals/get-json-replacer-function');
12var NATIVE_SYMBOL = require('../internals/symbol-constructor-detection');
13
14var $String = String;
15var $stringify = getBuiltIn('JSON', 'stringify');
16var exec = uncurryThis(/./.exec);
17var charAt = uncurryThis(''.charAt);
18var charCodeAt = uncurryThis(''.charCodeAt);
19var replace = uncurryThis(''.replace);
20var numberToString = uncurryThis(1.0.toString);
21
22var tester = /[\uD800-\uDFFF]/g;
23var low = /^[\uD800-\uDBFF]$/;
24var hi = /^[\uDC00-\uDFFF]$/;
25
26var WRONG_SYMBOLS_CONVERSION = !NATIVE_SYMBOL || fails(function () {
27 var symbol = getBuiltIn('Symbol')('stringify detection');
28 // MS Edge converts symbol values to JSON as {}
29 return $stringify([symbol]) !== '[null]'
30 // WebKit converts symbol values to JSON as null
31 || $stringify({ a: symbol }) !== '{}'
32 // V8 throws on boxed symbols
33 || $stringify(Object(symbol)) !== '{}';
34});
35
36// https://github.com/tc39/proposal-well-formed-stringify
37var ILL_FORMED_UNICODE = fails(function () {
38 return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
39 || $stringify('\uDEAD') !== '"\\udead"';
40});
41
42var stringifyWithSymbolsFix = function (it, replacer) {
43 var args = arraySlice(arguments);
44 var $replacer = getReplacerFunction(replacer);
45 if (!isCallable($replacer) && (it === undefined || isSymbol(it))) return; // IE8 returns string on undefined
46 args[1] = function (key, value) {
47 // some old implementations (like WebKit) could pass numbers as keys
48 if (isCallable($replacer)) value = call($replacer, this, $String(key), value);
49 if (!isSymbol(value)) return value;
50 };
51 return apply($stringify, null, args);
52};
53
54var fixIllFormed = function (match, offset, string) {
55 var prev = charAt(string, offset - 1);
56 var next = charAt(string, offset + 1);
57 if ((exec(low, match) && !exec(hi, next)) || (exec(hi, match) && !exec(low, prev))) {
58 return '\\u' + numberToString(charCodeAt(match, 0), 16);
59 } return match;
60};
61
62if ($stringify) {
63 // `JSON.stringify` method
64 // https://tc39.es/ecma262/#sec-json.stringify
65 $({ target: 'JSON', stat: true, arity: 3, forced: WRONG_SYMBOLS_CONVERSION || ILL_FORMED_UNICODE }, {
66 // eslint-disable-next-line no-unused-vars -- required for `.length`
67 stringify: function stringify(it, replacer, space) {
68 var args = arraySlice(arguments);
69 var result = apply(WRONG_SYMBOLS_CONVERSION ? stringifyWithSymbolsFix : $stringify, null, args);
70 return ILL_FORMED_UNICODE && typeof result == 'string' ? replace(result, tester, fixIllFormed) : result;
71 }
72 });
73}
Note: See TracBrowser for help on using the repository browser.