Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
trinhthinh388 committed Jan 27, 2024
1 parent a701c70 commit 164e337
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 69 deletions.
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);
});
});
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
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);
};
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"]);
});
});
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");
});
});
56 changes: 28 additions & 28 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/// <reference types="vitest" />
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,
Expand All @@ -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,
Expand Down

0 comments on commit 164e337

Please sign in to comment.