-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a701c70
commit 164e337
Showing
6 changed files
with
69 additions
and
69 deletions.
There are no files selected for viewing
22 changes: 11 additions & 11 deletions
22
packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
import { it, expect, describe } from 'vitest'; | ||
import { checkCountryValidity } from './checkCountryValidity'; | ||
import { it, expect, describe } from "vitest"; | ||
import { checkCountryValidity } from "./checkCountryValidity"; | ||
|
||
describe('checkCountryValidity', () => { | ||
it('Should return true when country is supported', () => { | ||
expect(checkCountryValidity('US', ['US'])).toBe(true); | ||
describe("checkCountryValidity", () => { | ||
it("Should return true when country is supported", () => { | ||
expect(checkCountryValidity("US", ["US"])).toBe(true); | ||
}); | ||
|
||
it('Should return false when country is not supported', () => { | ||
expect(checkCountryValidity('US', ['AU'])).toBe(false); | ||
it("Should return false when country is not supported", () => { | ||
expect(checkCountryValidity("US", ["AU"])).toBe(false); | ||
}); | ||
|
||
it('Should return true when country list is not provided', () => { | ||
expect(checkCountryValidity('US')).toBe(true); | ||
it("Should return true when country list is not provided", () => { | ||
expect(checkCountryValidity("US")).toBe(true); | ||
}); | ||
|
||
it('Should return false when country list is an empty array', () => { | ||
expect(checkCountryValidity('US', [])).toBe(false); | ||
it("Should return false when country list is an empty array", () => { | ||
expect(checkCountryValidity("US", [])).toBe(false); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
packages/phone-input/src/helpers/formatInternational/formatInternational.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import { parseIncompletePhoneNumber } from 'libphonenumber-js'; | ||
import { parseIncompletePhoneNumber } from "libphonenumber-js"; | ||
|
||
export const formatInternational = (phoneValue: string) => { | ||
if (!phoneValue) return ''; | ||
if (phoneValue.startsWith('+')) return parseIncompletePhoneNumber(phoneValue); | ||
if (!phoneValue) return ""; | ||
if (phoneValue.startsWith("+")) return parseIncompletePhoneNumber(phoneValue); | ||
|
||
if (phoneValue.startsWith('0')) | ||
return parseIncompletePhoneNumber('+' + phoneValue.slice(1)); | ||
if (phoneValue.startsWith("0")) | ||
return parseIncompletePhoneNumber("+" + phoneValue.slice(1)); | ||
|
||
return parseIncompletePhoneNumber('+' + phoneValue); | ||
return parseIncompletePhoneNumber("+" + phoneValue); | ||
}; |
26 changes: 13 additions & 13 deletions
26
...t/src/helpers/getPossibleCountriesByCallingCode/getPossibleCountriesByCallingCode.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
import { it, expect, describe } from 'vitest'; | ||
import { getPossibleCountriesByCallingCode } from './getPossibleCountriesByCallingCode'; | ||
import { it, expect, describe } from "vitest"; | ||
import { getPossibleCountriesByCallingCode } from "./getPossibleCountriesByCallingCode"; | ||
|
||
describe('getPossibleCountriesByCallingCode', () => { | ||
it('Should return empty array if the value is invalid', () => { | ||
expect(getPossibleCountriesByCallingCode('')).toEqual([]); | ||
describe("getPossibleCountriesByCallingCode", () => { | ||
it("Should return empty array if the value is invalid", () => { | ||
expect(getPossibleCountriesByCallingCode("")).toEqual([]); | ||
// @ts-ignore | ||
expect(getPossibleCountriesByCallingCode(undefined)).toEqual([]); | ||
}); | ||
|
||
it('Should return empty array if no country was found', () => { | ||
expect(getPossibleCountriesByCallingCode('9')).toEqual([]); | ||
it("Should return empty array if no country was found", () => { | ||
expect(getPossibleCountriesByCallingCode("9")).toEqual([]); | ||
}); | ||
|
||
it('Should return correct possible country which matches one character', () => { | ||
expect(getPossibleCountriesByCallingCode('7')).toEqual(['RU', 'KZ']); | ||
it("Should return correct possible country which matches one character", () => { | ||
expect(getPossibleCountriesByCallingCode("7")).toEqual(["RU", "KZ"]); | ||
}); | ||
|
||
it('Should return correct possible country which matches two characters', () => { | ||
expect(getPossibleCountriesByCallingCode('36')).toEqual(['HU']); | ||
it("Should return correct possible country which matches two characters", () => { | ||
expect(getPossibleCountriesByCallingCode("36")).toEqual(["HU"]); | ||
}); | ||
|
||
it('Should return correct possible country which matches three characters', () => { | ||
expect(getPossibleCountriesByCallingCode('996')).toEqual(['KG']); | ||
it("Should return correct possible country which matches three characters", () => { | ||
expect(getPossibleCountriesByCallingCode("996")).toEqual(["KG"]); | ||
}); | ||
}); |
18 changes: 9 additions & 9 deletions
18
...ut/src/helpers/guessPhoneCountryByIncompleteNumber/guessCountryByIncompleteNumber.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { it, expect, describe } from 'vitest'; | ||
import { guessCountryByIncompleteNumber } from './guessCountryByIncompleteNumber'; | ||
import { it, expect, describe } from "vitest"; | ||
import { guessCountryByIncompleteNumber } from "./guessCountryByIncompleteNumber"; | ||
|
||
describe('guessPhoneCountry', () => { | ||
it('Should work', () => { | ||
expect(guessCountryByIncompleteNumber('1')).toBe('US'); | ||
describe("guessPhoneCountry", () => { | ||
it("Should work", () => { | ||
expect(guessCountryByIncompleteNumber("1")).toBe("US"); | ||
|
||
expect(guessCountryByIncompleteNumber('1 505')).toBe('US'); | ||
expect(guessCountryByIncompleteNumber('+1 505')).toBe('US'); | ||
expect(guessCountryByIncompleteNumber("1 505")).toBe("US"); | ||
expect(guessCountryByIncompleteNumber("+1 505")).toBe("US"); | ||
|
||
expect(guessCountryByIncompleteNumber('1 684')).toBe('AS'); | ||
expect(guessCountryByIncompleteNumber('+1684')).toBe('AS'); | ||
expect(guessCountryByIncompleteNumber("1 684")).toBe("AS"); | ||
expect(guessCountryByIncompleteNumber("+1684")).toBe("AS"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters