Skip to content

Commit

Permalink
Remove isRelativeTimeFormatToPartsSupported
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Dec 5, 2024
1 parent c33384d commit ee024f9
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 19 deletions.
5 changes: 2 additions & 3 deletions src/lib/relative-time-format/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ import { formatNumber, formatNumberToParts } from '../number-format/index.js';
import {
getRelativeTimeFormat,
isRelativeTimeFormatSupported,
isRelativeTimeFormatToPartsSupported,
} from './intl.js';

export { isRelativeTimeFormatSupported, isRelativeTimeFormatToPartsSupported };
export { isRelativeTimeFormatSupported };

/**
* Formats a relative time with support for various [styles](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat#style).
Expand Down Expand Up @@ -103,7 +102,7 @@ function formatRelativeTimeToPartsFactory(): (
locales?: Locale | Locale[],
options?: Intl.RelativeTimeFormatOptions,
) => Intl.RelativeTimeFormatPart[] {
if (!isRelativeTimeFormatToPartsSupported) {
if (!isRelativeTimeFormatSupported) {
return (value, unit, locales, options) => {
// In runtimes that don't support formatting to parts, the relative time
// is formatted using the `Intl.NumberFormat` API instead.
Expand Down
15 changes: 0 additions & 15 deletions src/lib/relative-time-format/intl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@ export const isRelativeTimeFormatSupported = (() => {
}

Check warning on line 31 in src/lib/relative-time-format/intl.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/relative-time-format/intl.ts#L30-L31

Added lines #L30 - L31 were not covered by tests
})();

/**
* Whether the `Intl`, `Intl.RelativeTimeFormat`, and
* `Intl.RelativeTimeFormat.formatToParts` APIs are supported by the runtime.
*/
export const isRelativeTimeFormatToPartsSupported = (() => {
try {
return (
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
typeof Intl.RelativeTimeFormat.prototype.formatToParts !== 'undefined'
);
} catch (error) {
return false;
}
})();

export const getRelativeTimeFormat = memoize(Intl.RelativeTimeFormat) as (
locales?: Locale | Locale[],
options?: Intl.RelativeTimeFormatOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ vi.mock('../intl', async () => {
return {
...intl,
isRelativeTimeFormatSupported: false,
isRelativeTimeFormatToPartsSupported: false,
};
});

Expand Down

0 comments on commit ee024f9

Please sign in to comment.