Skip to content

Commit

Permalink
BREAKING CHANGE: no export getNavigatorLanguages and `getNavigatorL…
Browse files Browse the repository at this point in the history
…anguage` (#25)
  • Loading branch information
kazupon authored Oct 13, 2023
1 parent bf88d98 commit bfd43df
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 45 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ You can do `import { ... } from '@intlify/utils'` the above utilities

### Navigator

- `getNavigatorLanguages`
- `getNavigatorLanguage`
- `getNavigatorLocales`
- `getNavigatorLocale`

Expand Down
4 changes: 2 additions & 2 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ let navigatorLanguages: string[] | undefined
*
* @returns {Array<string>} {@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
}
Expand Down Expand Up @@ -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] || '')
}
Expand Down
40 changes: 1 addition & 39 deletions src/web.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
getHeaderLanguages,
getHeaderLocale,
getHeaderLocales,
getNavigatorLanguage,
getNavigatorLanguages,
getNavigatorLocale,
getNavigatorLocales,
setCookieLocale,
Expand Down Expand Up @@ -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', {
Expand All @@ -282,7 +244,7 @@ describe('getNavigatorLocales', () => {
})
})

describe('getNavigatorLanguage', () => {
describe('getNavigatorLocale', () => {
test('basic', () => {
vi.stubGlobal('navigator', {
language: 'en-US',
Expand Down
4 changes: 2 additions & 2 deletions src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function setCookieLocale(
*
* @returns {Array<string>} {@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`')
}
Expand All @@ -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`')
}
Expand Down

0 comments on commit bfd43df

Please sign in to comment.