diff --git a/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.spec.ts b/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.spec.ts index 27e60ee..e5fdf6e 100644 --- a/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.spec.ts +++ b/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.spec.ts @@ -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); }); }); diff --git a/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.ts b/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.ts index 6f3dea0..af587b0 100644 --- a/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.ts +++ b/packages/phone-input/src/helpers/checkCountryValidity/checkCountryValidity.ts @@ -1,8 +1,8 @@ -import { CountryCode } from 'libphonenumber-js'; +import { CountryCode } from "libphonenumber-js"; export const checkCountryValidity = ( country: CountryCode | string, - list?: CountryCode[] + list?: CountryCode[], ) => { if (!list) return true; return list.includes(country.toUpperCase() as CountryCode); diff --git a/packages/phone-input/src/helpers/formatInternational/formatInternational.ts b/packages/phone-input/src/helpers/formatInternational/formatInternational.ts index 9f8cf4c..cde1c3e 100644 --- a/packages/phone-input/src/helpers/formatInternational/formatInternational.ts +++ b/packages/phone-input/src/helpers/formatInternational/formatInternational.ts @@ -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); }; diff --git a/packages/phone-input/src/helpers/getPossibleCountriesByCallingCode/getPossibleCountriesByCallingCode.spec.ts b/packages/phone-input/src/helpers/getPossibleCountriesByCallingCode/getPossibleCountriesByCallingCode.spec.ts index a76fed1..495ea1e 100644 --- a/packages/phone-input/src/helpers/getPossibleCountriesByCallingCode/getPossibleCountriesByCallingCode.spec.ts +++ b/packages/phone-input/src/helpers/getPossibleCountriesByCallingCode/getPossibleCountriesByCallingCode.spec.ts @@ -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"]); }); }); diff --git a/packages/phone-input/src/helpers/guessPhoneCountryByIncompleteNumber/guessCountryByIncompleteNumber.spec.ts b/packages/phone-input/src/helpers/guessPhoneCountryByIncompleteNumber/guessCountryByIncompleteNumber.spec.ts index e80391f..ad464d8 100644 --- a/packages/phone-input/src/helpers/guessPhoneCountryByIncompleteNumber/guessCountryByIncompleteNumber.spec.ts +++ b/packages/phone-input/src/helpers/guessPhoneCountryByIncompleteNumber/guessCountryByIncompleteNumber.spec.ts @@ -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"); }); }); diff --git a/vite.config.ts b/vite.config.ts index 5e19f4d..33597b2 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,15 +1,15 @@ /// -import { defineConfig } from 'vite'; -import path from 'node:path'; -import react from '@vitejs/plugin-react'; -import dts from 'vite-plugin-dts'; +import { defineConfig } from "vite"; +import path from "node:path"; +import react from "@vitejs/plugin-react"; +import dts from "vite-plugin-dts"; console.log(process.cwd()); export default defineConfig({ plugins: [ react({ - jsxRuntime: 'automatic', + jsxRuntime: "automatic", }), dts({ insertTypesEntry: true, @@ -21,54 +21,54 @@ export default defineConfig({ */ minify: false, lib: { - entry: path.resolve(process.cwd(), './src/index.ts'), + entry: path.resolve(process.cwd(), "./src/index.ts"), }, rollupOptions: { input: { - index: 'src/index.ts', + index: "src/index.ts", }, external: [ - 'react', - 'react-dom', - 'react/jsx-runtime', - '@react-awesome/hooks', - '@react-awesome/phone-input', + "react", + "react-dom", + "react/jsx-runtime", + "@react-awesome/hooks", + "@react-awesome/phone-input", ], output: [ { - dir: 'dist', - entryFileNames: '[name].js', - chunkFileNames: '[name]-[chunk].js', - format: 'esm', - exports: 'named', + dir: "dist", + entryFileNames: "[name].js", + chunkFileNames: "[name]-[chunk].js", + format: "esm", + exports: "named", preserveModules: true, }, { - dir: 'dist', - entryFileNames: '[name].cjs', - chunkFileNames: '[name]-[chunk].cjs', - format: 'cjs', - exports: 'named', + dir: "dist", + entryFileNames: "[name].cjs", + chunkFileNames: "[name]-[chunk].cjs", + format: "cjs", + exports: "named", preserveModules: true, }, ], }, }, test: { - environment: 'node', + environment: "node", include: [ /** * Unit tests should only apply to helpers function only. * For component testing, we should use Functional Test. * Thus to avoid unnecessary tests we should use .tsx for components file only. */ - './src/**/*.spec.ts', + "./src/**/*.spec.ts", ], coverage: { - provider: 'istanbul', - include: ['**/*.ts'], - exclude: ['**/*.tsx'], - reporter: ['text', 'json', 'html'], + provider: "istanbul", + include: ["**/*.ts"], + exclude: ["**/*.tsx"], + reporter: ["text", "json", "html"], thresholds: { statements: 100, functions: 100,