From e33ca7a8bd2f204ffc905b81d67d2d1bba86da02 Mon Sep 17 00:00:00 2001 From: Baldeep Singh Date: Wed, 18 Oct 2023 13:29:11 +0530 Subject: [PATCH] feat(all): #2 added more tests and fixed bugs --- package.json | 3 +- src/file/convert-base64-to-file.ts | 16 --- src/file/convert-file-to-base64.ts | 9 -- src/file/get-base64.ts | 16 +++ src/file/get-file.ts | 41 +++++++ src/file/index.ts | 4 +- src/string/convert-listcases.ts | 2 +- src/string/param-case.ts | 5 +- src/string/snake-case.ts | 5 +- src/string/title-case.ts | 3 +- src/url/convert-url-to-file.ts | 35 ------ src/url/index.ts | 1 - tests/file/base64.json | 3 + tests/file/convert-base64-to-file._test.ts | 12 --- tests/file/get-base64.test.ts | 19 ++++ tests/file/get-file.test.ts | 52 +++++++++ tests/string/capitalize.test.ts | 29 +++++ tests/string/convert-listcases.test.ts | 119 +++++++++++++++++++++ tests/string/has-emoji.test.ts | 33 ++++++ tests/string/param-case.test.ts | 29 +++++ tests/string/snake-case.test.ts | 29 +++++ tests/string/title-case.test.ts | 29 +++++ tests/url/convert-url-to-file.test.ts | 22 ---- tsconfig.json | 1 + yarn.lock | 2 +- 25 files changed, 413 insertions(+), 106 deletions(-) delete mode 100644 src/file/convert-base64-to-file.ts delete mode 100644 src/file/convert-file-to-base64.ts create mode 100644 src/file/get-base64.ts create mode 100644 src/file/get-file.ts delete mode 100644 src/url/convert-url-to-file.ts create mode 100644 tests/file/base64.json delete mode 100644 tests/file/convert-base64-to-file._test.ts create mode 100644 tests/file/get-base64.test.ts create mode 100644 tests/file/get-file.test.ts create mode 100644 tests/string/capitalize.test.ts create mode 100644 tests/string/convert-listcases.test.ts create mode 100644 tests/string/has-emoji.test.ts create mode 100644 tests/string/param-case.test.ts create mode 100644 tests/string/snake-case.test.ts create mode 100644 tests/string/title-case.test.ts delete mode 100644 tests/url/convert-url-to-file.test.ts diff --git a/package.json b/package.json index 30d06a92..7545a91c 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "jest": "^29.7.0", "jest-environment-jsdom": "^29.7.0", "lint-staged": "^14.0.1", - "mime-types": "^2.1.35", "node-fetch": "2", "prettier": "^3.0.3", "rollup": "^3.29.3", @@ -57,4 +56,4 @@ "type": "git", "url": "git+https://github.com/Pantelwar/js-utils.git" } -} +} \ No newline at end of file diff --git a/src/file/convert-base64-to-file.ts b/src/file/convert-base64-to-file.ts deleted file mode 100644 index ace5ecaf..00000000 --- a/src/file/convert-base64-to-file.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Converts a base64 string to a File object and saves it with the specified file name. - * - * @param {string} base64 - The base64 string to convert. - * @param {string} fileName - The name to save the file as. - * @return {Promise} The converted File object. - */ -export async function convertBase64ToFile( - base64: string, - fileName: string -): Promise { - const type = base64.substring("data:".length, base64.indexOf(";")); - const res = await fetch(base64); - const buf = await res.arrayBuffer(); - return new File([buf], fileName, { type }); -} diff --git a/src/file/convert-file-to-base64.ts b/src/file/convert-file-to-base64.ts deleted file mode 100644 index d0f2a7fe..00000000 --- a/src/file/convert-file-to-base64.ts +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Converts a file to a base64 string representation. - * - * @param {File} file - The file to be converted. - * @return {string} The base64 string representation of the file. - */ -export function convertFileToBase64(file: File): string { - return URL.createObjectURL(file); -} diff --git a/src/file/get-base64.ts b/src/file/get-base64.ts new file mode 100644 index 00000000..80bcdc13 --- /dev/null +++ b/src/file/get-base64.ts @@ -0,0 +1,16 @@ +/** + * Converts a file to a base64 string representation. + * + * @param {File} file - The file to be converted. + * @return {string} The base64 string representation of the file. + */ +export function getBase64(file: File): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + + reader.readAsDataURL(file); + + reader.onload = () => + typeof reader.result === "string" ? resolve(reader.result) : reject(); + }); +} diff --git a/src/file/get-file.ts b/src/file/get-file.ts new file mode 100644 index 00000000..15e80933 --- /dev/null +++ b/src/file/get-file.ts @@ -0,0 +1,41 @@ +import { identifyFilename } from "../url/identify-filename"; + +/** + * Converts a base64 string to a File object and saves it with the specified file name. + * + * @param {string} url - The base64 string, blob url or http url of the file. + * @param {string} [fileName] - The name to save the file as. + * @param {string} [mimeType] - The mime type of the file + * @return {Promise} The converted File object. + */ +export async function getFile( + url: string, + fileName?: string, + mimeType?: string +): Promise { + if (url.startsWith("data:")) { + const arr = url.split(","); + const mime = arr[0].match(/:(.*?);/)?.[1]; + const bstr = atob(arr[arr.length - 1]); + + let n = bstr.length; + const u8arr = new Uint8Array(n); + while (n--) { + u8arr[n] = bstr.charCodeAt(n); + } + + const file = new File([u8arr], fileName || "file", { + type: mime || mimeType, + }); + return Promise.resolve(file); + } + + if (!fileName) { + fileName = identifyFilename(url); + } + + return fetch(url) + .then((res) => res.arrayBuffer()) + .then((buf) => new File([buf], fileName || "file", { type: mimeType })) + .catch(() => null); +} diff --git a/src/file/index.ts b/src/file/index.ts index 8426b29f..330be60e 100644 --- a/src/file/index.ts +++ b/src/file/index.ts @@ -1,2 +1,2 @@ -export * from "./convert-base64-to-file"; -export * from "./convert-file-to-base64"; +export * from "./get-base64"; +export * from "./get-file"; diff --git a/src/string/convert-listcases.ts b/src/string/convert-listcases.ts index 367e5950..776ea2ef 100644 --- a/src/string/convert-listcases.ts +++ b/src/string/convert-listcases.ts @@ -5,5 +5,5 @@ * @return {string} - The converted list case string. */ export function convertListcases(value: number): string { - return (value + 9).toString(36); + return ((Math.abs(value) % 26 || 26) + 9).toString(36); } diff --git a/src/string/param-case.ts b/src/string/param-case.ts index a4f88015..60fb5ab2 100644 --- a/src/string/param-case.ts +++ b/src/string/param-case.ts @@ -1,6 +1,7 @@ export function paramCase(str: string) { return str .toLowerCase() - .replace(/\s+/g, "-") - .replace(/[^a-z0-9-]/g, ""); + .replace(/[^a-z 0-9-]/g, "") + .trim() + .replace(/\s+/g, "-"); } diff --git a/src/string/snake-case.ts b/src/string/snake-case.ts index cf412c32..495fbafd 100644 --- a/src/string/snake-case.ts +++ b/src/string/snake-case.ts @@ -1,6 +1,7 @@ export function snakeCase(str: string) { return str .toLowerCase() - .replace(/\s+/g, "_") - .replace(/[^a-z0-9_]/g, ""); + .replace(/[^a-z 0-9-]/g, "") + .trim() + .replace(/\s+/g, "_"); } diff --git a/src/string/title-case.ts b/src/string/title-case.ts index 554c0c86..c3fa7c2b 100644 --- a/src/string/title-case.ts +++ b/src/string/title-case.ts @@ -3,7 +3,8 @@ import { capitalize } from "./capitalize"; export function titleCase(str: string) { return str .toLowerCase() - .split("_") + .trim() + .split(/[_\s-]+/) .map((word) => capitalize(word)) .join(" "); } diff --git a/src/url/convert-url-to-file.ts b/src/url/convert-url-to-file.ts deleted file mode 100644 index c02400fb..00000000 --- a/src/url/convert-url-to-file.ts +++ /dev/null @@ -1,35 +0,0 @@ -import mime from "mime-types"; - -import { identifyExtension } from "./identify-extension"; -import { identifyFilename } from "./identify-filename"; - -export type PreviewFile = File & { preview: string }; - -/** - * Converts a given URL to a File object asynchronously. - * - * @param {string} url - The URL to convert to a File object. - * @return {Promise} A Promise that resolves to a File object if the conversion is successful, or null if there is an error. - */ -export const convertUrlToFile = async ( - url: string -): Promise => { - const filename = identifyFilename(url); - const extension = identifyExtension(url); - - try { - const res = await fetch(url); - const data = await res.blob(); - const file = new File([data], filename, { - type: mime.lookup(extension) || "application/octet-stream", - }); - - Object.assign(file, { - preview: URL.createObjectURL(file), - }); - - return file as PreviewFile; - } catch (error) { - return null; - } -}; diff --git a/src/url/index.ts b/src/url/index.ts index 120b5ae0..891fb2ee 100644 --- a/src/url/index.ts +++ b/src/url/index.ts @@ -1,3 +1,2 @@ -export * from "./convert-url-to-file"; export * from "./identify-extension"; export * from "./identify-filename"; diff --git a/tests/file/base64.json b/tests/file/base64.json new file mode 100644 index 00000000..88373d2a --- /dev/null +++ b/tests/file/base64.json @@ -0,0 +1,3 @@ +{ + "str": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLE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qAx79/DhKTIPN14v8mXjLVik0pJqaPUDwetskQhqyJatEQ3oJjqbdBeOAxVCGrBwQ7XRdT2VzUr/wBkT9aL8Rlo3XnnCQQbbBMRGSrwRES9Vqz8UOxGFyujgubyivA3tS1arRsWGBjmzE4OP7vcB9HjuzkcktIA4v2bqU92NW1Gvstrxgz76G6qY9zDWFTozUmJJbW8HmXhQwMV8lRfh28wL9sGC5sQF0Mbvrx9FAftFpzJ0xuGKx2VRSabN1RTvXNI1FZBlhlu2IYg02CYRAEQ8kRK51E665ux1VzeP1VzdjqrnUTrrnUTrrnUTrrm7HVXN4/VXN2OqudROuudROuudROuubsdVc3j9Vc3Y6q51E6651E6651E665ux1VzeP1VzdjqrnUTrrnUTrrnUTrrm7HVXN4/VXN2OqudROunBUDA7ZiEJCXFFRTqb/GWa7AmtTEYbdXOM6rZFhNpck8xuWoQuy+z5muZs634u4aw+HatqPS4E+LDelNHFNfctIYCubIXAo1yuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VZ1tQ5cqfJhvRWWGGHUN1SNxBTMEVMH9/xLvOvzVd5/Yu86/NV3n9i7zr81Xef2LvOvzVd5/Yu86/NV3n9i7zr81Xef8A1C//2Q==" +} \ No newline at end of file diff --git a/tests/file/convert-base64-to-file._test.ts b/tests/file/convert-base64-to-file._test.ts deleted file mode 100644 index a36a70f3..00000000 --- a/tests/file/convert-base64-to-file._test.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { convertBase64ToFile } from "../../src"; - -describe("Convert Base64 to File", () => { - it("converts an empty string to a file", async () => { - const file = await convertBase64ToFile( - "data:image/png;base64,", - "test.txt" - ); - expect(file).toBeDefined(); - expect(file).toBeInstanceOf(File); - }); -}); diff --git a/tests/file/get-base64.test.ts b/tests/file/get-base64.test.ts new file mode 100644 index 00000000..95dd7033 --- /dev/null +++ b/tests/file/get-base64.test.ts @@ -0,0 +1,19 @@ +/** + * @jest-environment jsdom + */ + +import { getBase64, getFile } from "../../src"; +import base64 from "./base64.json"; + +describe("Get Base 64", () => { + it("converts an empty file to base 64 string", async () => { + const file = new File([], "test.txt", { type: "plain/text" }); + expect(await getBase64(file)).toBe("data:plain/text;base64,"); + }); + + it("converts a valid file to base 64 string", async () => { + const file = await getFile(base64.str, "image.jpg", "image/jpeg"); + if (file === null) return; + expect(await getBase64(file)).toBe(base64.str); + }); +}); diff --git a/tests/file/get-file.test.ts b/tests/file/get-file.test.ts new file mode 100644 index 00000000..e1023797 --- /dev/null +++ b/tests/file/get-file.test.ts @@ -0,0 +1,52 @@ +/** + * @jest-environment jsdom + */ + +import { getFile } from "../../src"; +import base64 from "./base64.json"; + +describe("Get File", () => { + it("converts an empty base64 string to a file", async () => { + const file = await getFile("data:image/png;base64,", "test.txt"); + expect(file).toBeDefined(); + expect(file).toBeInstanceOf(File); + expect(file).toHaveProperty("size", 0); + }); + + it("converts a valid base64 string to a file", async () => { + const file = await getFile(base64.str, "image.jpg"); + expect(file).toBeDefined(); + expect(file).toBeInstanceOf(File); + expect(file).toHaveProperty("type", "image/jpeg"); + }); + + it("convert an http url to a file", async () => { + const url = + "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"; + + const file = await getFile(url); + expect(file).toHaveProperty("name", "googlelogo_color_272x92dp.png"); + }); + + it("converts an invalid url to null", async () => { + const url = + "google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp"; + + const file = await getFile(url); + expect(file).toBeNull(); + }); + + it("converts a blob url to file", async () => { + expect(true).not.toBe(false); + + /** + * jsdom doesn't support blob urls yet + * issue link: https://github.com/jsdom/jsdom/issues/1721 + * uncomment when this issue is closed + */ + // const file = new File([], "something"); + // const convertedFile = await getFile(URL.createObjectURL(file), "something"); + // expect(convertedFile).toBeDefined(); + // expect(convertedFile).toHaveProperty("name", "something"); + }); +}); diff --git a/tests/string/capitalize.test.ts b/tests/string/capitalize.test.ts new file mode 100644 index 00000000..70722c7e --- /dev/null +++ b/tests/string/capitalize.test.ts @@ -0,0 +1,29 @@ +import { capitalize } from "../../src"; + +describe("Capitalize", () => { + it("capitalizes an empty string", () => { + expect(capitalize("")).toBe(""); + }); + + it("capitalizes a lowercase string", () => { + expect(capitalize("test")).toBe("Test"); + }); + + it("capitalizes an uppercase string", () => { + expect(capitalize("TEST")).toBe("Test"); + }); + + it("capitalizes a string with numbers", () => { + expect(capitalize("test@123")).toBe("Test@123"); + }); + + it("capitalizes a string with special characters", () => { + expect(capitalize("~!@#$%^&*()_+`1234567890-={}|[]:\";'<>?,./")).toBe( + "~!@#$%^&*()_+`1234567890-={}|[]:\";'<>?,./" + ); + }); + + it("capitalizes a sentence", () => { + expect(capitalize("the quick brown fox")).toBe("The quick brown fox"); + }); +}); diff --git a/tests/string/convert-listcases.test.ts b/tests/string/convert-listcases.test.ts new file mode 100644 index 00000000..75affe80 --- /dev/null +++ b/tests/string/convert-listcases.test.ts @@ -0,0 +1,119 @@ +import { convertListcases } from "../../src"; + +describe("Convert listcases", () => { + it("converts positive numbers to list case", () => { + expect(convertListcases(1)).toBe("a"); + expect(convertListcases(2)).toBe("b"); + expect(convertListcases(3)).toBe("c"); + expect(convertListcases(4)).toBe("d"); + expect(convertListcases(5)).toBe("e"); + expect(convertListcases(6)).toBe("f"); + expect(convertListcases(7)).toBe("g"); + expect(convertListcases(8)).toBe("h"); + expect(convertListcases(9)).toBe("i"); + expect(convertListcases(10)).toBe("j"); + expect(convertListcases(11)).toBe("k"); + expect(convertListcases(12)).toBe("l"); + expect(convertListcases(13)).toBe("m"); + expect(convertListcases(14)).toBe("n"); + expect(convertListcases(15)).toBe("o"); + expect(convertListcases(16)).toBe("p"); + expect(convertListcases(17)).toBe("q"); + expect(convertListcases(18)).toBe("r"); + expect(convertListcases(19)).toBe("s"); + expect(convertListcases(20)).toBe("t"); + expect(convertListcases(21)).toBe("u"); + expect(convertListcases(22)).toBe("v"); + expect(convertListcases(23)).toBe("w"); + expect(convertListcases(24)).toBe("x"); + expect(convertListcases(25)).toBe("y"); + expect(convertListcases(26)).toBe("z"); + }); + + it("converts negative number to list case", () => { + expect(convertListcases(-1)).toBe("a"); + expect(convertListcases(-2)).toBe("b"); + expect(convertListcases(-3)).toBe("c"); + expect(convertListcases(-4)).toBe("d"); + expect(convertListcases(-5)).toBe("e"); + expect(convertListcases(-6)).toBe("f"); + expect(convertListcases(-7)).toBe("g"); + expect(convertListcases(-8)).toBe("h"); + expect(convertListcases(-9)).toBe("i"); + expect(convertListcases(-10)).toBe("j"); + expect(convertListcases(-11)).toBe("k"); + expect(convertListcases(-12)).toBe("l"); + expect(convertListcases(-13)).toBe("m"); + expect(convertListcases(-14)).toBe("n"); + expect(convertListcases(-15)).toBe("o"); + expect(convertListcases(-16)).toBe("p"); + expect(convertListcases(-17)).toBe("q"); + expect(convertListcases(-18)).toBe("r"); + expect(convertListcases(-19)).toBe("s"); + expect(convertListcases(-20)).toBe("t"); + expect(convertListcases(-21)).toBe("u"); + expect(convertListcases(-22)).toBe("v"); + expect(convertListcases(-23)).toBe("w"); + expect(convertListcases(-24)).toBe("x"); + expect(convertListcases(-25)).toBe("y"); + expect(convertListcases(-26)).toBe("z"); + }); + + it("converts overflowing positive numbers to list case", () => { + expect(convertListcases(26 + 1)).toBe("a"); + expect(convertListcases(26 + 2)).toBe("b"); + expect(convertListcases(26 + 3)).toBe("c"); + expect(convertListcases(26 + 4)).toBe("d"); + expect(convertListcases(26 + 5)).toBe("e"); + expect(convertListcases(26 + 6)).toBe("f"); + expect(convertListcases(26 + 7)).toBe("g"); + expect(convertListcases(26 + 8)).toBe("h"); + expect(convertListcases(26 + 9)).toBe("i"); + expect(convertListcases(26 + 10)).toBe("j"); + expect(convertListcases(26 + 11)).toBe("k"); + expect(convertListcases(26 + 12)).toBe("l"); + expect(convertListcases(26 + 13)).toBe("m"); + expect(convertListcases(26 + 14)).toBe("n"); + expect(convertListcases(26 + 15)).toBe("o"); + expect(convertListcases(26 + 16)).toBe("p"); + expect(convertListcases(26 + 17)).toBe("q"); + expect(convertListcases(26 + 18)).toBe("r"); + expect(convertListcases(26 + 19)).toBe("s"); + expect(convertListcases(26 + 20)).toBe("t"); + expect(convertListcases(26 + 21)).toBe("u"); + expect(convertListcases(26 + 22)).toBe("v"); + expect(convertListcases(26 + 23)).toBe("w"); + expect(convertListcases(26 + 24)).toBe("x"); + expect(convertListcases(26 + 25)).toBe("y"); + expect(convertListcases(26 + 26)).toBe("z"); + }); + + it("converts overflowing negative number to list case", () => { + expect(convertListcases(-26 - 1)).toBe("a"); + expect(convertListcases(-26 - 2)).toBe("b"); + expect(convertListcases(-26 - 3)).toBe("c"); + expect(convertListcases(-26 - 4)).toBe("d"); + expect(convertListcases(-26 - 5)).toBe("e"); + expect(convertListcases(-26 - 6)).toBe("f"); + expect(convertListcases(-26 - 7)).toBe("g"); + expect(convertListcases(-26 - 8)).toBe("h"); + expect(convertListcases(-26 - 9)).toBe("i"); + expect(convertListcases(-26 - 10)).toBe("j"); + expect(convertListcases(-26 - 11)).toBe("k"); + expect(convertListcases(-26 - 12)).toBe("l"); + expect(convertListcases(-26 - 13)).toBe("m"); + expect(convertListcases(-26 - 14)).toBe("n"); + expect(convertListcases(-26 - 15)).toBe("o"); + expect(convertListcases(-26 - 16)).toBe("p"); + expect(convertListcases(-26 - 17)).toBe("q"); + expect(convertListcases(-26 - 18)).toBe("r"); + expect(convertListcases(-26 - 19)).toBe("s"); + expect(convertListcases(-26 - 20)).toBe("t"); + expect(convertListcases(-26 - 21)).toBe("u"); + expect(convertListcases(-26 - 22)).toBe("v"); + expect(convertListcases(-26 - 23)).toBe("w"); + expect(convertListcases(-26 - 24)).toBe("x"); + expect(convertListcases(-26 - 25)).toBe("y"); + expect(convertListcases(-26 - 26)).toBe("z"); + }); +}); diff --git a/tests/string/has-emoji.test.ts b/tests/string/has-emoji.test.ts new file mode 100644 index 00000000..bec1bd91 --- /dev/null +++ b/tests/string/has-emoji.test.ts @@ -0,0 +1,33 @@ +/** + * @jest-environment jsdom + */ + +import { hasEmoji } from "../../src"; + +describe("Has emoij", () => { + it("can check an empty string", () => { + expect(hasEmoji("")).toBe(false); + }); + + it("can check a normal string", () => { + expect(hasEmoji("This is a sentence")).toBe(false); + }); + + it("can check a string with emoji", () => { + expect(hasEmoji("This is a sentence with emoji 😃")).toBe(true); + }); + + it("can check a string with special characters", () => { + expect( + hasEmoji("This is a sentence with special characters {}|:.,;'[]0819247") + ).toBe(false); + }); + + it("can check a string with special characters and emoji", () => { + expect( + hasEmoji( + "This is a sentence with special characters {}|:.,;'[]0819247 and emoji 😃" + ) + ).toBe(true); + }); +}); diff --git a/tests/string/param-case.test.ts b/tests/string/param-case.test.ts new file mode 100644 index 00000000..259f8e25 --- /dev/null +++ b/tests/string/param-case.test.ts @@ -0,0 +1,29 @@ +import { paramCase } from "../../src"; + +describe("Param Case", () => { + it("converts an empty string", () => { + expect(paramCase("")).toBe(""); + }); + + it("converts a simple string", () => { + expect(paramCase("this is a string")).toBe("this-is-a-string"); + }); + + it("converts a string with whitespaces", () => { + expect(paramCase(" this has whitespaces ")).toBe( + "this-has-whitespaces" + ); + }); + + it("should remove all special characters", () => { + expect(paramCase("this has $p3ci@l ch@r@ct$r$")).toBe( + "this-has-p3cil-chrctr" + ); + }); + + it("should remove all emoijs", () => { + expect(paramCase("🥳 Welcome to the party!!! Have fun 🎉")).toBe( + "welcome-to-the-party-have-fun" + ); + }); +}); diff --git a/tests/string/snake-case.test.ts b/tests/string/snake-case.test.ts new file mode 100644 index 00000000..60722478 --- /dev/null +++ b/tests/string/snake-case.test.ts @@ -0,0 +1,29 @@ +import { snakeCase } from "../../src"; + +describe("Snake Case", () => { + it("converts an empty string", () => { + expect(snakeCase("")).toBe(""); + }); + + it("converts a simple string", () => { + expect(snakeCase("this is a string")).toBe("this_is_a_string"); + }); + + it("converts a string with whitespaces", () => { + expect(snakeCase(" this has whitespaces ")).toBe( + "this_has_whitespaces" + ); + }); + + it("should remove all special characters", () => { + expect(snakeCase("this has $p3ci@l ch@r@ct$r$")).toBe( + "this_has_p3cil_chrctr" + ); + }); + + it("should remove all emoijs", () => { + expect(snakeCase("🥳 Welcome to the party!!! Have fun 🎉")).toBe( + "welcome_to_the_party_have_fun" + ); + }); +}); diff --git a/tests/string/title-case.test.ts b/tests/string/title-case.test.ts new file mode 100644 index 00000000..daf507da --- /dev/null +++ b/tests/string/title-case.test.ts @@ -0,0 +1,29 @@ +import { titleCase } from "../../src"; + +describe("Title Case", () => { + it("converts an empty string", () => { + expect(titleCase("")).toBe(""); + }); + + it("converts a simple string", () => { + expect(titleCase("this is a string")).toBe("This Is A String"); + }); + + it("converts a string with whitespaces", () => { + expect(titleCase(" this has whitespaces ")).toBe( + "This Has Whitespaces" + ); + }); + + it("converts a string with special characters", () => { + expect(titleCase("this has $p3ci@l ch@r@ct$r$")).toBe( + "This Has $p3ci@l Ch@r@ct$r$" + ); + }); + + it("converts a string with emojis", () => { + expect(titleCase("🥳 Welcome to the party !!! Have fun 🎉")).toBe( + "🥳 Welcome To The Party !!! Have Fun 🎉" + ); + }); +}); diff --git a/tests/url/convert-url-to-file.test.ts b/tests/url/convert-url-to-file.test.ts deleted file mode 100644 index 4bda8696..00000000 --- a/tests/url/convert-url-to-file.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * @jest-environment jsdom - */ -import { convertUrlToFile } from "../../src"; - -describe("Convert URL to File", () => { - it("convert an image to a file", async () => { - const url = - "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"; - - const file = await convertUrlToFile(url); - expect(file).toHaveProperty("type", "image/png"); - }); - - it("converts an invalid url to null", async () => { - const url = - "google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp"; - - const file = await convertUrlToFile(url); - expect(file).toBeNull(); - }); -}); diff --git a/tsconfig.json b/tsconfig.json index 46c8bd93..98c43a5e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,7 @@ "outDir": "dist", "moduleResolution": "node", "emitDeclarationOnly": true, + "resolveJsonModule": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, "paths": { diff --git a/yarn.lock b/yarn.lock index 5d059176..7195ca00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4545,7 +4545,7 @@ mime-db@1.52.0: resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== -mime-types@^2.1.12, mime-types@^2.1.35: +mime-types@^2.1.12: version "2.1.35" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==