diff --git a/src/locale/ja-Hira/_lib/formatDistance/index.js b/src/locale/ja-Hira/_lib/formatDistance/index.js deleted file mode 100644 index b6b850288c..0000000000 --- a/src/locale/ja-Hira/_lib/formatDistance/index.js +++ /dev/null @@ -1,116 +0,0 @@ -var formatDistanceLocale = { - lessThanXSeconds: { - one: '1びょうみまん', - other: '{{count}}びょうみまん', - oneWithSuffix: 'やく1びょう', - otherWithSuffix: 'やく{{count}}びょう' - }, - - xSeconds: { - one: '1びょう', - other: '{{count}}びょう' - }, - - halfAMinute: '30びょう', - - lessThanXMinutes: { - one: '1ぷんみまん', - other: '{{count}}ふんみまん', - oneWithSuffix: 'やく1ぷん', - otherWithSuffix: 'やく{{count}}ふん' - }, - - xMinutes: { - one: '1ぷん', - other: '{{count}}ふん' - }, - - aboutXHours: { - one: 'やく1じかん', - other: 'やく{{count}}じかん' - }, - - xHours: { - one: '1じかん', - other: '{{count}}じかん' - }, - - xDays: { - one: '1にち', - other: '{{count}}にち' - }, - - aboutXWeeks: { - one: 'やく1しゅうかん', - other: 'やく{{count}}しゅうかん' - }, - - xWeeks: { - 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}}ねんちかく' - } -} - -export default function formatDistance(token, count, options) { - options = options || {} - - var result - if (typeof formatDistanceLocale[token] === 'string') { - result = formatDistanceLocale[token] - } else if (count === 1) { - if (options.addSuffix && formatDistanceLocale[token].oneWithSuffix) { - result = formatDistanceLocale[token].oneWithSuffix - } else { - result = formatDistanceLocale[token].one - } - } else { - if (options.addSuffix && formatDistanceLocale[token].otherWithSuffix) { - result = formatDistanceLocale[token].otherWithSuffix.replace( - '{{count}}', - count - ) - } else { - result = formatDistanceLocale[token].other.replace('{{count}}', count) - } - } - - if (options.addSuffix) { - if (options.comparison > 0) { - return result + 'あと' - } else { - return result + 'まえ' - } - } - - return result -} diff --git a/src/locale/ja-Hira/_lib/formatDistance/index.ts b/src/locale/ja-Hira/_lib/formatDistance/index.ts new file mode 100644 index 0000000000..608eec5962 --- /dev/null +++ b/src/locale/ja-Hira/_lib/formatDistance/index.ts @@ -0,0 +1,128 @@ +import type { FormatDistanceFn, FormatDistanceLocale } from '../../../types' + +type FormatDistanceTokenValue = + | string + | { + one: string + other: string + oneWithSuffix?: string + otherWithSuffix?: string + } + +const formatDistanceLocale: FormatDistanceLocale = { + lessThanXSeconds: { + one: '1びょうみまん', + other: '{{count}}びょうみまん', + oneWithSuffix: 'やく1びょう', + otherWithSuffix: 'やく{{count}}びょう', + }, + + xSeconds: { + one: '1びょう', + other: '{{count}}びょう', + }, + + halfAMinute: '30びょう', + + lessThanXMinutes: { + one: '1ぷんみまん', + other: '{{count}}ふんみまん', + oneWithSuffix: 'やく1ぷん', + otherWithSuffix: 'やく{{count}}ふん', + }, + + xMinutes: { + one: '1ぷん', + other: '{{count}}ふん', + }, + + aboutXHours: { + one: 'やく1じかん', + other: 'やく{{count}}じかん', + }, + + xHours: { + one: '1じかん', + other: '{{count}}じかん', + }, + + xDays: { + one: '1にち', + other: '{{count}}にち', + }, + + aboutXWeeks: { + one: 'やく1しゅうかん', + other: 'やく{{count}}しゅうかん', + }, + + xWeeks: { + 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}}ねんちかく', + }, +} + +const formatDistance: FormatDistanceFn = (token, count, options) => { + options = options || {} + + let result + + const tokenValue = formatDistanceLocale[token] + if (typeof tokenValue === 'string') { + result = tokenValue + } else if (count === 1) { + if (options.addSuffix && tokenValue.oneWithSuffix) { + result = tokenValue.oneWithSuffix + } else { + result = tokenValue.one + } + } else { + if (options.addSuffix && tokenValue.otherWithSuffix) { + result = tokenValue.otherWithSuffix.replace('{{count}}', String(count)) + } else { + result = tokenValue.other.replace('{{count}}', String(count)) + } + } + + if (options.addSuffix) { + if (options.comparison && options.comparison > 0) { + return result + 'あと' + } else { + return result + 'まえ' + } + } + + return result +} + +export default formatDistance diff --git a/src/locale/ja-Hira/_lib/formatLong/index.js b/src/locale/ja-Hira/_lib/formatLong/index.ts similarity index 64% rename from src/locale/ja-Hira/_lib/formatLong/index.js rename to src/locale/ja-Hira/_lib/formatLong/index.ts index 6429c8b9ce..f0fb62f7f7 100644 --- a/src/locale/ja-Hira/_lib/formatLong/index.js +++ b/src/locale/ja-Hira/_lib/formatLong/index.ts @@ -1,41 +1,42 @@ +import type { FormatLong } from '../../../types' import buildFormatLongFn from '../../../_lib/buildFormatLongFn/index' -var dateFormats = { +const dateFormats = { full: 'yねんMがつdにちEEEE', long: 'yねんMがつdにち', medium: 'y/MM/dd', - short: 'y/MM/dd' + short: 'y/MM/dd', } -var timeFormats = { +const timeFormats = { full: 'Hじmmふんssびょう zzzz', long: 'H:mm:ss z', medium: 'H:mm:ss', - short: 'H:mm' + short: 'H:mm', } -var dateTimeFormats = { +const dateTimeFormats = { full: '{{date}} {{time}}', long: '{{date}} {{time}}', medium: '{{date}} {{time}}', - short: '{{date}} {{time}}' + short: '{{date}} {{time}}', } -var formatLong = { +const formatLong: FormatLong = { date: buildFormatLongFn({ formats: dateFormats, - defaultWidth: 'full' + defaultWidth: 'full', }), time: buildFormatLongFn({ formats: timeFormats, - defaultWidth: 'full' + defaultWidth: 'full', }), dateTime: buildFormatLongFn({ formats: dateTimeFormats, - defaultWidth: 'full' - }) + defaultWidth: 'full', + }), } export default formatLong diff --git a/src/locale/ja-Hira/_lib/formatRelative/index.js b/src/locale/ja-Hira/_lib/formatRelative/index.js deleted file mode 100644 index 464edec175..0000000000 --- a/src/locale/ja-Hira/_lib/formatRelative/index.js +++ /dev/null @@ -1,12 +0,0 @@ -var formatRelativeLocale = { - lastWeek: 'せんしゅうのeeeeのp', - yesterday: 'きのうのp', - today: 'きょうのp', - tomorrow: 'あしたのp', - nextWeek: 'よくしゅうのeeeeのp', - other: 'P' -} - -export default function formatRelative(token, _date, _baseDate, _options) { - return formatRelativeLocale[token] -} diff --git a/src/locale/ja-Hira/_lib/formatRelative/index.ts b/src/locale/ja-Hira/_lib/formatRelative/index.ts new file mode 100644 index 0000000000..c8a51ca2af --- /dev/null +++ b/src/locale/ja-Hira/_lib/formatRelative/index.ts @@ -0,0 +1,21 @@ +import type { FormatRelativeFn } from '../../../types' + +const formatRelativeLocale = { + lastWeek: 'せんしゅうのeeeeのp', + yesterday: 'きのうのp', + today: 'きょうのp', + tomorrow: 'あしたのp', + nextWeek: 'よくしゅうのeeeeのp', + other: 'P', +} + +const formatRelative: FormatRelativeFn = ( + token, + _date, + _baseDate, + _options +) => { + return formatRelativeLocale[token] +} + +export default formatRelative diff --git a/src/locale/ja-Hira/_lib/localize/index.js b/src/locale/ja-Hira/_lib/localize/index.ts similarity index 69% rename from src/locale/ja-Hira/_lib/localize/index.js rename to src/locale/ja-Hira/_lib/localize/index.ts index 2ee1e3b25c..64a6a42724 100644 --- a/src/locale/ja-Hira/_lib/localize/index.js +++ b/src/locale/ja-Hira/_lib/localize/index.ts @@ -1,19 +1,38 @@ +import type { Localize, LocalizeFn, QuarterIndex } from '../../../types' import buildLocalizeFn from '../../../_lib/buildLocalizeFn/index' -var eraValues = { - narrow: ['BC', 'AC'], - abbreviated: ['きげんぜん', 'せいれき'], - wide: ['きげんぜん', 'せいれき'], +const eraValues = { + narrow: ['BC', 'AC'] as const, + abbreviated: ['きげんぜん', 'せいれき'] as const, + wide: ['きげんぜん', 'せいれき'] as const, } -var quarterValues = { - narrow: ['1', '2', '3', '4'], - abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'], - wide: ['だい1しはんき', 'だい2しはんき', 'だい3しはんき', 'だい4しはんき'], +const quarterValues = { + narrow: ['1', '2', '3', '4'] as const, + abbreviated: ['Q1', 'Q2', 'Q3', 'Q4'] as const, + wide: [ + 'だい1しはんき', + 'だい2しはんき', + 'だい3しはんき', + 'だい4しはんき', + ] as const, } -var monthValues = { - narrow: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'], +const monthValues = { + narrow: [ + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + '10', + '11', + '12', + ] as const, abbreviated: [ '1がつ', '2がつ', @@ -27,7 +46,7 @@ var monthValues = { '10がつ', '11がつ', '12がつ', - ], + ] as const, wide: [ '1がつ', '2がつ', @@ -41,17 +60,25 @@ var monthValues = { '10がつ', '11がつ', '12がつ', - ], + ] as const, } -var dayValues = { - narrow: ['にち', 'げつ', 'か', 'すい', 'もく', 'きん', 'ど'], - short: ['にち', 'げつ', 'か', 'すい', 'もく', 'きん', 'ど'], - abbreviated: ['にち', 'げつ', 'か', 'すい', 'もく', 'きん', 'ど'], - wide: ['にちようび', 'げつようび', 'かようび', 'すいようび', 'もくようび', 'きんようび', 'どようび'], +const dayValues = { + narrow: ['にち', 'げつ', 'か', 'すい', 'もく', 'きん', 'ど'] as const, + short: ['にち', 'げつ', 'か', 'すい', 'もく', 'きん', 'ど'] as const, + abbreviated: ['にち', 'げつ', 'か', 'すい', 'もく', 'きん', 'ど'] as const, + wide: [ + 'にちようび', + 'げつようび', + 'かようび', + 'すいようび', + 'もくようび', + 'きんようび', + 'どようび', + ] as const, } -var dayPeriodValues = { +const dayPeriodValues = { narrow: { am: 'ごぜん', pm: 'ごご', @@ -83,7 +110,7 @@ var dayPeriodValues = { night: 'しんや', }, } -var formattingDayPeriodValues = { +const formattingDayPeriodValues = { narrow: { am: 'ごぜん', pm: 'ごご', @@ -116,21 +143,24 @@ var formattingDayPeriodValues = { }, } -function ordinalNumber(dirtyNumber, dirtyOptions) { - var number = Number(dirtyNumber) +const ordinalNumber: LocalizeFn = ( + dirtyNumber, + dirtyOptions +) => { + const number = Number(dirtyNumber) // If ordinal numbers depend on context, for example, // if they are different for different grammatical genders, // use `options.unit`: // - // var options = dirtyOptions || {} - // var unit = String(options.unit) + // const options = dirtyOptions || {} + // const unit = String(options.unit) // // where `unit` can be 'year', 'quarter', 'month', 'week', 'date', 'dayOfYear', // 'day', 'hour', 'minute', 'second' - var options = dirtyOptions || {} - var unit = String(options.unit) + const options = dirtyOptions || {} + const unit = String(options.unit) switch (unit) { case 'year': @@ -154,7 +184,7 @@ function ordinalNumber(dirtyNumber, dirtyOptions) { } } -var localize = { +const localize: Localize = { ordinalNumber: ordinalNumber, era: buildLocalizeFn({ @@ -165,9 +195,7 @@ var localize = { quarter: buildLocalizeFn({ values: quarterValues, defaultWidth: 'wide', - argumentCallback: function (quarter) { - return Number(quarter) - 1 - }, + argumentCallback: (quarter) => (Number(quarter) - 1) as QuarterIndex, }), month: buildLocalizeFn({ diff --git a/src/locale/ja-Hira/_lib/match/index.js b/src/locale/ja-Hira/_lib/match/index.ts similarity index 75% rename from src/locale/ja-Hira/_lib/match/index.js rename to src/locale/ja-Hira/_lib/match/index.ts index 4bd0b72f1e..7434815de6 100644 --- a/src/locale/ja-Hira/_lib/match/index.js +++ b/src/locale/ja-Hira/_lib/match/index.ts @@ -1,34 +1,36 @@ -import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index' +import type { Quarter } from '../../../../types' +import type { Match } from '../../../types' import buildMatchFn from '../../../_lib/buildMatchFn/index' +import buildMatchPatternFn from '../../../_lib/buildMatchPatternFn/index' -var matchOrdinalNumberPattern = /^だ?い?\d+(ねん|しはんき|がつ|しゅう|にち|じ|ふん|びょう)?/i -var parseOrdinalNumberPattern = /\d+/i +const matchOrdinalNumberPattern = /^だ?い?\d+(ねん|しはんき|がつ|しゅう|にち|じ|ふん|びょう)?/i +const parseOrdinalNumberPattern = /\d+/i -var matchEraPatterns = { +const matchEraPatterns = { narrow: /^(B\.?C\.?|A\.?D\.?)/i, abbreviated: /^(きげん[前後]|せいれき)/i, wide: /^(きげん[前後]|せいれき)/i, } -var parseEraPatterns = { - narrow: [/^B/i, /^A/i], - any: [/^(きげんぜん)/i, /^(せいれき|きげんご)/i], +const parseEraPatterns = { + narrow: [/^B/i, /^A/i] as const, + any: [/^(きげんぜん)/i, /^(せいれき|きげんご)/i] as const, } -var matchQuarterPatterns = { +const matchQuarterPatterns = { narrow: /^[1234]/i, abbreviated: /^Q[1234]/i, wide: /^だい[1234一二三四1234]しはんき/i, } -var parseQuarterPatterns = { - any: [/(1|一|1)/i, /(2|二|2)/i, /(3|三|3)/i, /(4|四|4)/i], +const parseQuarterPatterns = { + any: [/(1|一|1)/i, /(2|二|2)/i, /(3|三|3)/i, /(4|四|4)/i] as const, } -var matchMonthPatterns = { +const matchMonthPatterns = { narrow: /^([123456789]|1[012])/, abbreviated: /^([123456789]|1[012])がつ/i, wide: /^([123456789]|1[012])がつ/i, } -var parseMonthPatterns = { +const parseMonthPatterns = { any: [ /^1\D/, /^2/, @@ -42,23 +44,23 @@ var parseMonthPatterns = { /^10/, /^11/, /^12/, - ], + ] as const, } -var matchDayPatterns = { +const matchDayPatterns = { narrow: /^(にち|げつ|か|すい|もく|きん|ど)/, short: /^(にち|げつ|か|すい|もく|きん|ど)/, abbreviated: /^(にち|げつ|か|すい|もく|きん|ど)/, wide: /^(にち|げつ|か|すい|もく|きん|ど)ようび/, } -var parseDayPatterns = { - any: [/^にち/, /^げつ/, /^か/, /^すい/, /^もく/, /^きん/, /^ど/], +const parseDayPatterns = { + any: [/^にち/, /^げつ/, /^か/, /^すい/, /^もく/, /^きん/, /^ど/] as const, } -var matchDayPeriodPatterns = { +const matchDayPeriodPatterns = { any: /^(AM|PM|ごぜん|ごご|しょうご|しんや|まよなか|よる|あさ)/i, } -var parseDayPeriodPatterns = { +const parseDayPeriodPatterns = { any: { am: /^(A|ごぜん)/i, pm: /^(P|ごご)/i, @@ -71,7 +73,7 @@ var parseDayPeriodPatterns = { }, } -var match = { +const match: Match = { ordinalNumber: buildMatchPatternFn({ matchPattern: matchOrdinalNumberPattern, parsePattern: parseOrdinalNumberPattern, @@ -92,9 +94,7 @@ var match = { defaultMatchWidth: 'wide', parsePatterns: parseQuarterPatterns, defaultParseWidth: 'any', - valueCallback: function (index) { - return index + 1 - }, + valueCallback: (index) => (index + 1) as Quarter, }), month: buildMatchFn({ diff --git a/src/locale/ja-Hira/index.js b/src/locale/ja-Hira/index.ts similarity index 87% rename from src/locale/ja-Hira/index.js rename to src/locale/ja-Hira/index.ts index 8d68bc20f8..8bfdb058b6 100644 --- a/src/locale/ja-Hira/index.js +++ b/src/locale/ja-Hira/index.ts @@ -1,3 +1,4 @@ +import type { Locale } from '../types' import formatDistance from './_lib/formatDistance/index' import formatLong from './_lib/formatLong/index' import formatRelative from './_lib/formatRelative/index' @@ -12,7 +13,7 @@ import match from './_lib/match/index' * @iso-639-2 jpn * @author Eri Hiramatsu [@Eritutteo]{@link https://github.com/Eritutteo} */ -var locale = { +const locale: Locale = { code: 'ja-Hira', formatDistance: formatDistance, formatLong: formatLong, @@ -21,8 +22,8 @@ var locale = { match: match, options: { weekStartsOn: 0 /* Sunday */, - firstWeekContainsDate: 1 - } + firstWeekContainsDate: 1, + }, } export default locale