UNPKG

date-fns

Version:

Modern JavaScript date utility library

100 lines (80 loc) 1.79 kB
function buildDistanceInWordsLocale () { var distanceInWordsLocale = { lessThanXSeconds: { one: '1秒以下', other: '{{count}}秒以下' }, xSeconds: { one: '1秒', other: '{{count}}秒' }, halfAMinute: '半分', lessThanXMinutes: { one: '1分以下', other: '{{count}}分以下' }, xMinutes: { one: '1分', other: '{{count}}分' }, aboutXHours: { one: '1時間ごろ', other: '{{count}}時間ごろ' }, xHours: { one: '1時間', other: '{{count}}時間' }, xDays: { one: '1日', other: '{{count}}日' }, aboutXMonths: { one: '1ヶ月ごろ', other: '{{count}}ヶ月ごろ' }, xMonths: { one: '1ヶ月', other: '{{count}}ヶ月' }, aboutXYears: { one: '1年ごろ', other: '{{count}}年ごろ' }, xYears: { one: '1年', other: '{{count}}年' }, overXYears: { one: '1年以上', other: '{{count}}年以上' }, almostXYears: { one: '1年以下', other: '{{count}}年以下' } } function localize (token, count, options) { options = options || {} var result if (typeof distanceInWordsLocale[token] === 'string') { result = distanceInWordsLocale[token] } else if (count === 1) { result = distanceInWordsLocale[token].one } else { result = distanceInWordsLocale[token].other.replace('{{count}}', count) } if (options.addSuffix) { if (options.comparison > 0) { return result + '後' } else { return result + '前' } } return result } return { localize: localize } } module.exports = buildDistanceInWordsLocale