/
githubmirror
/
dayjs
Обзор
Документация
Войти
/
githubmirror
/
dayjs
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
src/plugin/preParsePostFormat/index.js
47 строк
1 KB
Moshe Jonathan Gordon Radian
fix: add preParsePostFormat plugin & update Arabic [ar] locale (#1255)
02 янв 2021, 14:03
Не верифицирован
02 янв 2021, 14:03
f2e4790
Код
Авторство
О чём код?
// Plugin template from https://day.js.org/docs/en/plugin/plugin export default (option, dayjsClass) => { const oldParse = dayjsClass.prototype.parse dayjsClass.prototype.parse = function (cfg) { if (typeof cfg.date === 'string') { const locale = this.$locale() cfg.date = locale && locale.preparse ? locale.preparse(cfg.date) : cfg.date } // original parse result return oldParse.bind(this)(cfg) } // // overriding existing API // // e.g. extend dayjs().format() const oldFormat = dayjsClass.prototype.format dayjsClass.prototype.format = function (...args) { // original format result const result = oldFormat.call(this, ...args) // return modified result const locale = this.$locale() return locale && locale.postformat ? locale.postformat(result) : result } const oldFromTo = dayjsClass.prototype.fromToBase if (oldFromTo) { dayjsClass.prototype.fromToBase = function ( input, withoutSuffix, instance, isFrom ) { const locale = this.$locale() || instance.$locale() // original format result return oldFromTo.call( this, input, withoutSuffix, instance, isFrom, locale && locale.postformat ) } } }