id
int64
0
3.78k
code
stringlengths
13
37.9k
declarations
stringlengths
16
64.6k
700
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setMilliseconds(value) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
701
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setMinutes(value, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
702
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date = setISODay(date, value) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
703
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number, options: ParserOptions ): DateType { date = setDay(date, value, options) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
704
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number, options: ParserOptions ): DateType { date = setDay(date, value, options) date.setHours(0, 0, 0, 0) return date }
type ParserOptions = Required< LocaleOptions & FirstWeekContainsDateOptions & WeekStartOptions >
705
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: LocaleDayPeriod ): DateType { date.setHours(dayPeriodEnumToHours(value), 0, 0, 0) return date }
type LocaleDayPeriod = | 'am' | 'pm' | 'midnight' | 'noon' | 'morning' | 'afternoon' | 'evening' | 'night'
706
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: LocaleDayPeriod ): DateType { date.setHours(dayPeriodEnumToHours(value), 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
707
set<DateType extends Date>( date: DateType, flags: ParseFlags, value: number ): DateType { flags.era = value date.setFullYear(value, 0, 1) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
708
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { const isPM = date.getHours() >= 12 if (isPM && value < 12) { date.setHours(value + 12, 0, 0, 0) } else { date.setHours(value, 0, 0, 0) } return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
709
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setMonth((value - 1) * 3, 1) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
710
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): [DateType, ParseFlags] { return [constructFrom(date, value), { timestampIsSet: true }] }
interface ParseFlags { timestampIsSet?: boolean era?: number }
711
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): [DateType, ParseFlags] { return [constructFrom(date, value * 1000), { timestampIsSet: true }] }
interface ParseFlags { timestampIsSet?: boolean era?: number }
712
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number, options: ParserOptions ): DateType { return startOfWeek(setWeek(date, value, options), options) }
interface ParseFlags { timestampIsSet?: boolean era?: number }
713
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number, options: ParserOptions ): DateType { return startOfWeek(setWeek(date, value, options), options) }
type ParserOptions = Required< LocaleOptions & FirstWeekContainsDateOptions & WeekStartOptions >
714
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setHours(value, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
715
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setFullYear(value, 0, 1) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
716
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { const hours = value <= 24 ? value % 24 : value date.setHours(hours, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
717
validate<DateType extends Date>( _date: DateType, value: YearParserValue ): boolean { return value.isTwoDigitYear || value.year > 0 }
interface YearParserValue { year: number isTwoDigitYear: boolean }
718
set<DateType extends Date>( date: DateType, flags: ParseFlags, value: YearParserValue, options: ParserOptions ): DateType { const currentYear = getWeekYear(date, options) if (value.isTwoDigitYear) { const normalizedTwoDigitYear = normalizeTwoDigitYear( value.year, currentYear ) date.setFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate) date.setHours(0, 0, 0, 0) return startOfWeek(date, options) } const year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year date.setFullYear(year, 0, options.firstWeekContainsDate) date.setHours(0, 0, 0, 0) return startOfWeek(date, options) }
interface ParseFlags { timestampIsSet?: boolean era?: number }
719
set<DateType extends Date>( date: DateType, flags: ParseFlags, value: YearParserValue, options: ParserOptions ): DateType { const currentYear = getWeekYear(date, options) if (value.isTwoDigitYear) { const normalizedTwoDigitYear = normalizeTwoDigitYear( value.year, currentYear ) date.setFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate) date.setHours(0, 0, 0, 0) return startOfWeek(date, options) } const year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year date.setFullYear(year, 0, options.firstWeekContainsDate) date.setHours(0, 0, 0, 0) return startOfWeek(date, options) }
type ParserOptions = Required< LocaleOptions & FirstWeekContainsDateOptions & WeekStartOptions >
720
set<DateType extends Date>( date: DateType, flags: ParseFlags, value: YearParserValue, options: ParserOptions ): DateType { const currentYear = getWeekYear(date, options) if (value.isTwoDigitYear) { const normalizedTwoDigitYear = normalizeTwoDigitYear( value.year, currentYear ) date.setFullYear(normalizedTwoDigitYear, 0, options.firstWeekContainsDate) date.setHours(0, 0, 0, 0) return startOfWeek(date, options) } const year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year date.setFullYear(year, 0, options.firstWeekContainsDate) date.setHours(0, 0, 0, 0) return startOfWeek(date, options) }
interface YearParserValue { year: number isTwoDigitYear: boolean }
721
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setSeconds(value, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
722
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setMonth(value, 1) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
723
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { return startOfISOWeek(setISOWeek(date, value)) }
interface ParseFlags { timestampIsSet?: boolean era?: number }
724
set<DateType extends Date>( date: DateType, flags: ParseFlags, value: YearParserValue ): DateType { const currentYear = date.getFullYear() if (value.isTwoDigitYear) { const normalizedTwoDigitYear = normalizeTwoDigitYear( value.year, currentYear ) date.setFullYear(normalizedTwoDigitYear, 0, 1) date.setHours(0, 0, 0, 0) return date } const year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year date.setFullYear(year, 0, 1) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
725
set<DateType extends Date>( date: DateType, flags: ParseFlags, value: YearParserValue ): DateType { const currentYear = date.getFullYear() if (value.isTwoDigitYear) { const normalizedTwoDigitYear = normalizeTwoDigitYear( value.year, currentYear ) date.setFullYear(normalizedTwoDigitYear, 0, 1) date.setHours(0, 0, 0, 0) return date } const year = !('era' in flags) || flags.era === 1 ? value.year : 1 - value.year date.setFullYear(year, 0, 1) date.setHours(0, 0, 0, 0) return date }
interface YearParserValue { year: number isTwoDigitYear: boolean }
726
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setDate(value) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
727
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { const firstWeekOfYear = constructFrom(date, 0) firstWeekOfYear.setFullYear(value, 0, 4) firstWeekOfYear.setHours(0, 0, 0, 0) return startOfISOWeek(firstWeekOfYear) }
interface ParseFlags { timestampIsSet?: boolean era?: number }
728
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { date.setMonth(0, value) date.setHours(0, 0, 0, 0) return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
729
set<DateType extends Date>( date: DateType, _flags: ParseFlags, value: number ): DateType { const isPM = date.getHours() >= 12 if (isPM && value < 12) { date.setHours(value + 12, 0, 0, 0) } else if (!isPM && value === 12) { date.setHours(0, 0, 0, 0) } else { date.setHours(value, 0, 0, 0) } return date }
interface ParseFlags { timestampIsSet?: boolean era?: number }
730
function formatISODuration(duration: Duration): string { const { years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = 0, } = duration return `P${years}Y${months}M${days}DT${hours}H${minutes}M${seconds}S` }
interface Duration { years?: number months?: number weeks?: number days?: number hours?: number minutes?: number seconds?: number }
731
( date: Date, token: string, localize: Localize, options: Required< LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions > & { _originalDate: Date } ) => string
interface Localize { ordinalNumber: LocalizeFn< number, BuildLocalizeFnArgCallback<number> | undefined > era: LocalizeFn<Era, undefined> quarter: LocalizeFn<Quarter, BuildLocalizeFnArgCallback<Quarter>> month: LocalizeFn<Month, undefined> day: LocalizeFn<Day, undefined> dayPeriod: LocalizeFn<LocaleDayPeriod, undefined> }
732
function setDefaultOptions(newOptions: DefaultOptions): void { defaultOptions = newOptions }
type DefaultOptions = LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions
733
function setDefaultOptions(newOptions: DefaultOptions): void { const result: DefaultOptions = {} const defaultOptions = getDefaultOptions() for (const property in defaultOptions) { if (Object.prototype.hasOwnProperty.call(defaultOptions, property)) { ;(result as any)[property] = defaultOptions[property as keyof DefaultOptions] } } for (const property in newOptions) { if (Object.prototype.hasOwnProperty.call(newOptions, property)) { if (newOptions[property as keyof DefaultOptions] === undefined) { delete (result as any)[property] } else { ;(result as any)[property] = newOptions[property as keyof DefaultOptions] } } } setInternalDefaultOptions(result) }
type DefaultOptions = LocaleOptions & WeekStartOptions & FirstWeekContainsDateOptions
734
function intlFormat<DateType extends Date>( date: DateType, localeOptions: LocaleOptions ): string
interface LocaleOptions { locale?: Locale }
735
function intlFormat<DateType extends Date>( date: DateType, localeOptions: LocaleOptions ): string
type LocaleOptions = { locale: Locale | Locale[] }
736
function intlFormat<DateType extends Date>( date: DateType, localeOptions: LocaleOptions ): string
interface LocaleOptions { weekStartsOn?: Day firstWeekContainsDate?: FirstWeekContainsDate }
737
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions ): string
interface FormatOptions { format?: 'extended' | 'basic' }
738
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions ): string
interface FormatOptions extends LocaleOptions, WeekStartOptions, FirstWeekContainsDateOptions, AdditionalTokensOptions {}
739
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions ): string
type FormatOptions = Intl.DateTimeFormatOptions
740
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions, localeOptions: LocaleOptions ): string
interface FormatOptions { format?: 'extended' | 'basic' }
741
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions, localeOptions: LocaleOptions ): string
interface FormatOptions extends LocaleOptions, WeekStartOptions, FirstWeekContainsDateOptions, AdditionalTokensOptions {}
742
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions, localeOptions: LocaleOptions ): string
type FormatOptions = Intl.DateTimeFormatOptions
743
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions, localeOptions: LocaleOptions ): string
interface LocaleOptions { locale?: Locale }
744
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions, localeOptions: LocaleOptions ): string
type LocaleOptions = { locale: Locale | Locale[] }
745
function intlFormat<DateType extends Date>( date: DateType, formatOptions: FormatOptions, localeOptions: LocaleOptions ): string
interface LocaleOptions { weekStartsOn?: Day firstWeekContainsDate?: FirstWeekContainsDate }
746
function intlFormat<DateType extends Date>( date: DateType, formatOrLocale?: FormatOptions | LocaleOptions, localeOptions?: LocaleOptions ): string { let formatOptions: FormatOptions | undefined if (isFormatOptions(formatOrLocale)) { formatOptions = formatOrLocale } else { localeOptions = formatOrLocale } return new Intl.DateTimeFormat(localeOptions?.locale, formatOptions).format( date ) }
interface LocaleOptions { locale?: Locale }
747
function intlFormat<DateType extends Date>( date: DateType, formatOrLocale?: FormatOptions | LocaleOptions, localeOptions?: LocaleOptions ): string { let formatOptions: FormatOptions | undefined if (isFormatOptions(formatOrLocale)) { formatOptions = formatOrLocale } else { localeOptions = formatOrLocale } return new Intl.DateTimeFormat(localeOptions?.locale, formatOptions).format( date ) }
type LocaleOptions = { locale: Locale | Locale[] }
748
function intlFormat<DateType extends Date>( date: DateType, formatOrLocale?: FormatOptions | LocaleOptions, localeOptions?: LocaleOptions ): string { let formatOptions: FormatOptions | undefined if (isFormatOptions(formatOrLocale)) { formatOptions = formatOrLocale } else { localeOptions = formatOrLocale } return new Intl.DateTimeFormat(localeOptions?.locale, formatOptions).format( date ) }
interface LocaleOptions { weekStartsOn?: Day firstWeekContainsDate?: FirstWeekContainsDate }
749
function formatDuration( duration: Duration, options?: FormatDurationOptions ): string { const defaultOptions = getDefaultOptions() const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale const format = options?.format ?? defaultFormat const zero = options?.zero ?? false const delimiter = options?.delimiter ?? ' ' if (!locale.formatDistance) { return '' } const result = format .reduce((acc, unit) => { const token = `x${unit.replace(/(^.)/, (m) => m.toUpperCase() )}` as FormatDistanceToken const value = duration[unit] if (value !== undefined && (zero || duration[unit])) { return acc.concat(locale.formatDistance(token, value)) } return acc }, [] as string[]) .join(delimiter) return result }
interface FormatDurationOptions extends LocaleOptions { format?: DurationUnit[] zero?: boolean delimiter?: string }
750
function formatDuration( duration: Duration, options?: FormatDurationOptions ): string { const defaultOptions = getDefaultOptions() const locale = options?.locale ?? defaultOptions.locale ?? defaultLocale const format = options?.format ?? defaultFormat const zero = options?.zero ?? false const delimiter = options?.delimiter ?? ' ' if (!locale.formatDistance) { return '' } const result = format .reduce((acc, unit) => { const token = `x${unit.replace(/(^.)/, (m) => m.toUpperCase() )}` as FormatDistanceToken const value = duration[unit] if (value !== undefined && (zero || duration[unit])) { return acc.concat(locale.formatDistance(token, value)) } return acc }, [] as string[]) .join(delimiter) return result }
interface Duration { years?: number months?: number weeks?: number days?: number hours?: number minutes?: number seconds?: number }
751
function areIntervalsOverlapping( intervalLeft: Interval, intervalRight: Interval, options?: AreIntervalsOverlappingOptions ): boolean { const leftStartTime = toDate(intervalLeft.start).getTime() const leftEndTime = toDate(intervalLeft.end).getTime() const rightStartTime = toDate(intervalRight.start).getTime() const rightEndTime = toDate(intervalRight.end).getTime() // Throw an exception if start date is after end date or if any date is `Invalid Date` if (!(leftStartTime <= leftEndTime && rightStartTime <= rightEndTime)) { throw new RangeError('Invalid interval') } if (options?.inclusive) { return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime } return leftStartTime < rightEndTime && rightStartTime < leftEndTime }
interface AreIntervalsOverlappingOptions { inclusive?: boolean }
752
function areIntervalsOverlapping( intervalLeft: Interval, intervalRight: Interval, options?: AreIntervalsOverlappingOptions ): boolean { const leftStartTime = toDate(intervalLeft.start).getTime() const leftEndTime = toDate(intervalLeft.end).getTime() const rightStartTime = toDate(intervalRight.start).getTime() const rightEndTime = toDate(intervalRight.end).getTime() // Throw an exception if start date is after end date or if any date is `Invalid Date` if (!(leftStartTime <= leftEndTime && rightStartTime <= rightEndTime)) { throw new RangeError('Invalid interval') } if (options?.inclusive) { return leftStartTime <= rightEndTime && rightStartTime <= leftEndTime } return leftStartTime < rightEndTime && rightStartTime < leftEndTime }
interface Interval<DateType extends Date = Date> { start: DateType | number end: DateType | number }
753
function milliseconds({ years, months, weeks, days, hours, minutes, seconds, }: Duration): number { let totalDays = 0 if (years) totalDays += years * daysInYear if (months) totalDays += months * (daysInYear / 12) if (weeks) totalDays += weeks * 7 if (days) totalDays += days let totalSeconds = totalDays * 24 * 60 * 60 if (hours) totalSeconds += hours * 60 * 60 if (minutes) totalSeconds += minutes * 60 if (seconds) totalSeconds += seconds return Math.round(totalSeconds * 1000) }
interface Duration { years?: number months?: number weeks?: number days?: number hours?: number minutes?: number seconds?: number }
754
( token: FormatDistanceToken, count: number, options?: FormatDistanceFnOptions ) => string
interface FormatDistanceFnOptions { addSuffix?: boolean comparison?: -1 | 0 | 1 }
755
( token: FormatDistanceToken, count: number, options?: FormatDistanceFnOptions ) => string
type FormatDistanceToken = | 'lessThanXSeconds' | 'xSeconds' | 'halfAMinute' | 'lessThanXMinutes' | 'xMinutes' | 'aboutXHours' | 'xHours' | 'xDays' | 'aboutXWeeks' | 'xWeeks' | 'aboutXMonths' | 'xMonths' | 'aboutXYears' | 'xYears' | 'overXYears' | 'almostXYears'
756
<DateType extends Date>( token: FormatRelativeToken, date: DateType, baseDate: DateType, options?: FormatRelativeFnOptions ) => string
type FormatRelativeToken = | 'lastWeek' | 'yesterday' | 'today' | 'tomorrow' | 'nextWeek' | 'other'
757
<DateType extends Date>( token: FormatRelativeToken, date: DateType, baseDate: DateType, options?: FormatRelativeFnOptions ) => string
interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale }
758
(options: FormatLongFnOptions) => string
interface FormatLongFnOptions { width?: FormatLongWidth }
759
function lastWeek(day: Day): string { const weekday = accusativeWeekdays[day] switch (day) { case 0: case 3: case 5: case 6: return "'у мінулую " + weekday + " а' p" case 1: case 2: case 4: return "'у мінулы " + weekday + " а' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
760
function thisWeek(day: Day): string { const weekday = accusativeWeekdays[day] return "'у " + weekday + " а' p" }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
761
function nextWeek(day: Day): string { const weekday = accusativeWeekdays[day] switch (day) { case 0: case 3: case 5: case 6: return "'у наступную " + weekday + " а' p" case 1: case 2: case 4: return "'у наступны " + weekday + " а' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
762
function declension(scheme: DeclensionScheme, count: number): string { // scheme for count=1 exists if (scheme.one !== undefined && count === 1) { return scheme.one } const rem10 = count % 10 const rem100 = count % 100 // 1, 21, 31, ... if (rem10 === 1 && rem100 !== 11) { return scheme.singularNominative.replace('{{count}}', String(count)) // 2, 3, 4, 22, 23, 24, 32 ... } else if (rem10 >= 2 && rem10 <= 4 && (rem100 < 10 || rem100 > 20)) { return scheme.singularGenitive.replace('{{count}}', String(count)) // 5, 6, 7, 8, 9, 10, 11, ... } else { return scheme.pluralGenitive.replace('{{count}}', String(count)) } }
interface DeclensionScheme { one?: string singularNominative: string singularGenitive: string pluralGenitive: string }
763
function declension(scheme: DeclensionScheme, count: number): string { // scheme for count=1 exists if (scheme.one !== undefined && count === 1) { return scheme.one } const rem10 = count % 10 const rem100 = count % 100 // 1, 21, 31, ... if (rem10 === 1 && rem100 !== 11) { return scheme.singularNominative.replace('{{count}}', String(count)) // 2, 3, 4, 22, 23, 24, 32 ... } else if (rem10 >= 2 && rem10 <= 4 && (rem100 < 10 || rem100 > 20)) { return scheme.singularGenitive.replace('{{count}}', String(count)) // 5, 6, 7, 8, 9, 10, 11, ... } else { return scheme.pluralGenitive.replace('{{count}}', String(count)) } }
type DeclensionScheme = { one?: string singularNominative: string singularGenitive: string pluralGenitive: string }
764
function declension(scheme: DeclensionScheme, count: number): string { // scheme for count=1 exists if (scheme.one !== undefined && count === 1) { return scheme.one } const rem10 = count % 10 const rem100 = count % 100 // 1, 21, 31, ... if (rem10 === 1 && rem100 !== 11) { return scheme.singularNominative.replace('{{count}}', String(count)) // 2, 3, 4, 22, 23, 24, 32 ... } else if (rem10 >= 2 && rem10 <= 4 && (rem100 < 10 || rem100 > 20)) { return scheme.singularGenitive.replace('{{count}}', String(count)) // 5, 6, 7, 8, 9, 10, 11, ... } else { return scheme.pluralGenitive.replace('{{count}}', String(count)) } }
type DeclensionScheme = { one?: string singularNominative: string singularGenitive: string pluralGenitive: string }
765
function declension(scheme: DeclensionScheme, count: number): string { // scheme for count=1 exists if (scheme.one !== undefined && count === 1) { return scheme.one } const rem10 = count % 10 const rem100 = count % 100 // 1, 21, 31, ... if (rem10 === 1 && rem100 !== 11) { return scheme.singularNominative.replace('{{count}}', String(count)) // 2, 3, 4, 22, 23, 24, 32 ... } else if (rem10 >= 2 && rem10 <= 4 && (rem100 < 10 || rem100 > 20)) { return scheme.singularGenitive.replace('{{count}}', String(count)) // 5, 6, 7, 8, 9, 10, 11, ... } else { return scheme.pluralGenitive.replace('{{count}}', String(count)) } }
interface DeclensionScheme { one?: string singularNominative: string singularGenitive: string pluralGenitive: string }
766
function lastWeek(day: Day): string { const weekday = weekdays[day] switch (day) { case 0: case 3: case 6: return "'миналата " + weekday + " в' p" case 1: case 2: case 4: case 5: return "'миналия " + weekday + " в' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
767
function thisWeek(day: Day): string { const weekday = weekdays[day] if (day === 2 /* Tue */) { return "'във " + weekday + " в' p" } else { return "'в " + weekday + " в' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
768
function nextWeek(day: Day): string { const weekday = weekdays[day] switch (day) { case 0: case 3: case 6: return "'следващата " + weekday + " в' p" case 1: case 2: case 4: case 5: return "'следващия " + weekday + " в' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
769
function lastWeek(day: Day): string { const weekday = weekdays[day] switch (day) { case 0: case 3: case 6: return "'минатата " + weekday + " во' p" case 1: case 2: case 4: case 5: return "'минатиот " + weekday + " во' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
770
function thisWeek(day: Day): string { const weekday = weekdays[day] switch (day) { case 0: case 3: case 6: return "'ова " + weekday + " вo' p" case 1: case 2: case 4: case 5: return "'овој " + weekday + " вo' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
771
function nextWeek(day: Day): string { const weekday = weekdays[day] switch (day) { case 0: case 3: case 6: return "'следната " + weekday + " вo' p" case 1: case 2: case 4: case 5: return "'следниот " + weekday + " вo' p" } }
type Day = 0 | 1 | 2 | 3 | 4 | 5 | 6
772
<DateType extends Date>( date: DateType, baseDate: DateType, options?: FormatRelativeFnOptions ): string => { const day = date.getDay() as Day if (isSameWeek(date, baseDate, options)) { return thisWeek(day) } else { return lastWeek(day) } }
interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale }
773
<DateType extends Date>( date: DateType, baseDate: DateType, options?: FormatRelativeFnOptions ): string => { const day = date.getDay() as Day if (isSameWeek(date, baseDate, options)) { return thisWeek(day) } else { return nextWeek(day) } }
interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale }
774
<DateType extends Date>( date: DateType, baseDate: DateType, options?: FormatRelativeFnOptions ): string => { if (isSameWeek(date, baseDate, options)) { return "eeee 'plkst.' p" } const weekday = weekdays[date.getDay()] return "'Pagājušā " + weekday + " plkst.' p" }
interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale }
775
<DateType extends Date>( date: DateType, baseDate: DateType, options?: FormatRelativeFnOptions ): string => { if (isSameWeek(date, baseDate, options)) { return "eeee 'plkst.' p" } const weekday = weekdays[date.getDay()] return "'Nākamajā " + weekday + " plkst.' p" }
interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale }
776
function buildLocalizeTokenFn(schema: Schema) { return (count: number, options?: FormatDistanceFnOptions): string => { if (count === 1) { if (options?.addSuffix) { return schema.one[0].replace('{{time}}', schema.one[2]) } else { return schema.one[0].replace('{{time}}', schema.one[1]) } } else { const rem = count % 10 === 1 && count % 100 !== 11 if (options?.addSuffix) { return schema.other[0] .replace('{{time}}', rem ? schema.other[3] : schema.other[4]) .replace('{{count}}', String(count)) } else { return schema.other[0] .replace('{{time}}', rem ? schema.other[1] : schema.other[2]) .replace('{{count}}', String(count)) } } } }
type Schema = { one: string[] other: string[] }
777
function dayAndTimeWithAdjective( token: FormatRelativeToken, date: Date, baseDate: Date, options?: FormatRelativeFnOptions ): string { let adjectives if (isSameWeek(date, baseDate, options)) { adjectives = adjectivesThisWeek } else if (token === 'lastWeek') { adjectives = adjectivesLastWeek } else if (token === 'nextWeek') { adjectives = adjectivesNextWeek } else { throw new Error(`Cannot determine adjectives for token ${token}`) } const day = date.getDay() as Day const grammaticalGender = dayGrammaticalGender[day] as keyof Adjective const adjective = adjectives[grammaticalGender] return `'${adjective}' eeee 'o' p` }
type FormatRelativeToken = | 'lastWeek' | 'yesterday' | 'today' | 'tomorrow' | 'nextWeek' | 'other'
778
function dayAndTimeWithAdjective( token: FormatRelativeToken, date: Date, baseDate: Date, options?: FormatRelativeFnOptions ): string { let adjectives if (isSameWeek(date, baseDate, options)) { adjectives = adjectivesThisWeek } else if (token === 'lastWeek') { adjectives = adjectivesLastWeek } else if (token === 'nextWeek') { adjectives = adjectivesNextWeek } else { throw new Error(`Cannot determine adjectives for token ${token}`) } const day = date.getDay() as Day const grammaticalGender = dayGrammaticalGender[day] as keyof Adjective const adjective = adjectives[grammaticalGender] return `'${adjective}' eeee 'o' p` }
interface FormatRelativeFnOptions { weekStartsOn?: Day locale?: Locale }
779
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
780
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
781
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
782
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
783
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
784
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
785
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
786
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = { standalone: Plural | string withPreposition: Plural | string }
787
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string two: string threeToTen: string other: string }
788
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
789
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
790
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
791
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
792
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
793
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
794
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
795
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
796
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string other: string }
797
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = Plural | Tense
798
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: string two: string threeToTen: string other: string }
799
function declensionGroup( scheme: FormatDistanceTokenValue, count: number ): string | Tense { if (count === 1) { return scheme.one } const rem100 = count % 100 // ends with 11-20 if (rem100 <= 20 && rem100 > 10) { return scheme.other } const rem10 = rem100 % 10 // ends with 2, 3, 4 if (rem10 >= 2 && rem10 <= 4) { return scheme.twoFour } return scheme.other }
type FormatDistanceTokenValue = | string | { one: { standalone: string withPrepositionAgo: string withPrepositionIn: string } dual: string other: string }