From bfd43df8cb93cf7b7f7ebf8bcd66267e136877d4 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Fri, 13 Oct 2023 13:59:42 +0900 Subject: [PATCH] BREAKING CHANGE: no export `getNavigatorLanguages` and `getNavigatorLanguage` (#25) --- README.md | 2 -- src/node.ts | 4 ++-- src/web.test.ts | 40 +--------------------------------------- src/web.ts | 4 ++-- 4 files changed, 5 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 425793f..aa52ed1 100644 --- a/README.md +++ b/README.md @@ -130,8 +130,6 @@ You can do `import { ... } from '@intlify/utils'` the above utilities ### Navigator -- `getNavigatorLanguages` -- `getNavigatorLanguage` - `getNavigatorLocales` - `getNavigatorLocale` diff --git a/src/node.ts b/src/node.ts index fffc939..361123c 100644 --- a/src/node.ts +++ b/src/node.ts @@ -255,7 +255,7 @@ let navigatorLanguages: string[] | undefined * * @returns {Array} {@link https://datatracker.ietf.org/doc/html/rfc4646#section-2.1 | BCP 47 language tags}, if you can't get the language tag, return an empty array. */ -export function getNavigatorLanguages(): readonly string[] { +function getNavigatorLanguages(): readonly string[] { if (navigatorLanguages && navigatorLanguages.length > 0) { return navigatorLanguages } @@ -382,7 +382,7 @@ let navigatorLanguage = '' * * @returns {string} {@link https://datatracker.ietf.org/doc/html/rfc4646#section-2.1 | BCP 47 language tag}, if you can't get the language tag, return a enmpty string. */ -export function getNavigatorLanguage(): string { +function getNavigatorLanguage(): string { return navigatorLanguage || (navigatorLanguage = getNavigatorLanguages()[0] || '') } diff --git a/src/web.test.ts b/src/web.test.ts index 18ad99f..c1e0280 100644 --- a/src/web.test.ts +++ b/src/web.test.ts @@ -5,8 +5,6 @@ import { getHeaderLanguages, getHeaderLocale, getHeaderLocales, - getNavigatorLanguage, - getNavigatorLanguages, getNavigatorLocale, getNavigatorLocales, setCookieLocale, @@ -224,42 +222,6 @@ describe('setCookieLocale', () => { }) }) -describe('getNavigatorLanguages', () => { - test('basic', () => { - vi.stubGlobal('navigator', { - languages: ['en-US', 'en', 'ja'], - }) - - expect(getNavigatorLanguages()).toEqual(['en-US', 'en', 'ja']) - }) - - test('error', () => { - vi.stubGlobal('navigator', undefined) - - expect(() => getNavigatorLanguages()).toThrowError( - /not support `navigator`/, - ) - }) -}) - -describe('getNavigatorLanguage', () => { - test('basic', () => { - vi.stubGlobal('navigator', { - language: 'en-US', - }) - - expect(getNavigatorLanguage()).toEqual('en-US') - }) - - test('error', () => { - vi.stubGlobal('navigator', undefined) - - expect(() => getNavigatorLanguage()).toThrowError( - /not support `navigator`/, - ) - }) -}) - describe('getNavigatorLocales', () => { test('basic', () => { vi.stubGlobal('navigator', { @@ -282,7 +244,7 @@ describe('getNavigatorLocales', () => { }) }) -describe('getNavigatorLanguage', () => { +describe('getNavigatorLocale', () => { test('basic', () => { vi.stubGlobal('navigator', { language: 'en-US', diff --git a/src/web.ts b/src/web.ts index e4a6bd0..88af0a7 100644 --- a/src/web.ts +++ b/src/web.ts @@ -259,7 +259,7 @@ export function setCookieLocale( * * @returns {Array} {@link https://datatracker.ietf.org/doc/html/rfc4646#section-2.1 | BCP 47 language tags} */ -export function getNavigatorLanguages(): readonly string[] { +function getNavigatorLanguages(): readonly string[] { if (typeof navigator === 'undefined') { throw new Error('not support `navigator`') } @@ -276,7 +276,7 @@ export function getNavigatorLanguages(): readonly string[] { * * @returns {string} {@link https://datatracker.ietf.org/doc/html/rfc4646#section-2.1 | BCP 47 language tag} */ -export function getNavigatorLanguage(): string { +function getNavigatorLanguage(): string { if (typeof navigator === 'undefined') { throw new Error('not support `navigator`') }