/
githubmirror
/
dayjs
Обзор
Документация
Войти
/
githubmirror
/
dayjs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/plugin/bigIntSupport/index.js
25 строк
589 B
iamkun
fix: add BigIntSupport plugin (#2087)
21 окт 2022, 03:36
Не верифицирован
21 окт 2022, 03:36
f6dce48
Код
Авторство
О чём код?
// eslint-disable-next-line valid-typeof const isBigInt = num => typeof num === 'bigint' export default (o, c, dayjs) => { const proto = c.prototype const parseDate = (cfg) => { const { date } = cfg if (isBigInt(date)) { return Number(date) } return date } const oldParse = proto.parse proto.parse = function (cfg) { cfg.date = parseDate.bind(this)(cfg) oldParse.bind(this)(cfg) } const oldUnix = dayjs.unix dayjs.unix = function (timestamp) { const ts = isBigInt(timestamp) ? Number(timestamp) : timestamp return oldUnix(ts) } }