source: node_modules/core-js-pure/modules/es.date.to-json.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1008 bytes
Line 
1'use strict';
2var $ = require('../internals/export');
3var call = require('../internals/function-call');
4var toObject = require('../internals/to-object');
5var toPrimitive = require('../internals/to-primitive');
6var toISOString = require('../internals/date-to-iso-string');
7var classof = require('../internals/classof-raw');
8var fails = require('../internals/fails');
9
10var FORCED = fails(function () {
11 return new Date(NaN).toJSON() !== null
12 || call(Date.prototype.toJSON, { toISOString: function () { return 1; } }) !== 1;
13});
14
15// `Date.prototype.toJSON` method
16// https://tc39.es/ecma262/#sec-date.prototype.tojson
17$({ target: 'Date', proto: true, forced: FORCED }, {
18 // eslint-disable-next-line no-unused-vars -- required for `.length`
19 toJSON: function toJSON(key) {
20 var O = toObject(this);
21 var pv = toPrimitive(O, 'number');
22 return typeof pv == 'number' && !isFinite(pv) ? null :
23 (!('toISOString' in O) && classof(O) === 'Date') ? call(toISOString, O) : O.toISOString();
24 }
25});
Note: See TracBrowser for help on using the repository browser.