Sha256: 658fe4d054e30dd889c79086591e85afdb7aed402614553867a9430071661434

Contents?: true

Size: 1.06 KB

Versions: 13

Compression:

Stored size: 1.06 KB

Contents

var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var fails = require('../internals/fails');

var $stringify = getBuiltIn('JSON', 'stringify');
var re = /[\uD800-\uDFFF]/g;
var low = /^[\uD800-\uDBFF]$/;
var hi = /^[\uDC00-\uDFFF]$/;

var fix = function (match, offset, string) {
  var prev = string.charAt(offset - 1);
  var next = string.charAt(offset + 1);
  if ((low.test(match) && !hi.test(next)) || (hi.test(match) && !low.test(prev))) {
    return '\\u' + match.charCodeAt(0).toString(16);
  } return match;
};

var FORCED = fails(function () {
  return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"'
    || $stringify('\uDEAD') !== '"\\udead"';
});

if ($stringify) {
  // https://github.com/tc39/proposal-well-formed-stringify
  $({ target: 'JSON', stat: true, forced: FORCED }, {
    // eslint-disable-next-line no-unused-vars
    stringify: function stringify(it, replacer, space) {
      var result = $stringify.apply(null, arguments);
      return typeof result == 'string' ? result.replace(re, fix) : result;
    }
  });
}

Version data entries

13 entries across 13 versions & 4 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/core-js/modules/es.json.stringify.js
tang-0.2.1 spec/tang_app/node_modules/core-js/modules/es.json.stringify.js
tang-0.2.0 spec/tang_app/node_modules/core-js/modules/es.json.stringify.js
tang-0.1.0 spec/tang_app/node_modules/core-js/modules/es.json.stringify.js
tang-0.0.9 spec/tang_app/node_modules/core-js/modules/es.json.stringify.js
enju_library-0.3.8 spec/dummy/node_modules/core-js/modules/es.json.stringify.js
condenser-0.3 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js
condenser-0.2 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js
condenser-0.1 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js
condenser-0.0.12 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js
condenser-0.0.11 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js
condenser-0.0.10 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js
condenser-0.0.9 lib/condenser/processors/node_modules/core-js-pure/modules/es.json.stringify.js