webhook-action/node_modules/es-abstract/2020/ToDateString.js

22 lines
514 B
JavaScript
Raw Normal View History

'use strict';
var GetIntrinsic = require('get-intrinsic');
2024-03-28 02:00:41 +00:00
var $TypeError = require('es-errors/type');
var $Date = GetIntrinsic('%Date%');
2024-03-28 02:00:41 +00:00
var $String = GetIntrinsic('%String%');
var $isNaN = require('../helpers/isNaN');
2024-03-28 02:00:41 +00:00
// https://262.ecma-international.org/6.0/#sec-todatestring
module.exports = function ToDateString(tv) {
2024-03-28 02:00:41 +00:00
if (typeof tv !== 'number') {
throw new $TypeError('Assertion failed: `tv` must be a Number');
}
if ($isNaN(tv)) {
return 'Invalid Date';
}
2024-03-28 02:00:41 +00:00
return $String(new $Date(tv));
};