Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: no export getNavigatorLanguages and getNavigatorLanguage #25

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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