Skip to content

Commit

Permalink
feat(all): #2 added more tests and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
baldeepsingh-pantelwar committed Oct 18, 2023
1 parent 7f4dd59 commit e33ca7a
Show file tree
Hide file tree
Showing 25 changed files with 413 additions and 106 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -57,4 +56,4 @@
"type": "git",
"url": "git+https://github.com/Pantelwar/js-utils.git"
}
}
}
16 changes: 0 additions & 16 deletions src/file/convert-base64-to-file.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/file/convert-file-to-base64.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/file/get-base64.ts
Original file line number Diff line number Diff line change
@@ -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<string> {
return new Promise((resolve, reject) => {
const reader = new FileReader();

reader.readAsDataURL(file);

reader.onload = () =>
typeof reader.result === "string" ? resolve(reader.result) : reject();
});
}
41 changes: 41 additions & 0 deletions src/file/get-file.ts
Original file line number Diff line number Diff line change
@@ -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<File>} The converted File object.
*/
export async function getFile(
url: string,
fileName?: string,
mimeType?: string
): Promise<File | null> {
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);
}
4 changes: 2 additions & 2 deletions src/file/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./convert-base64-to-file";
export * from "./convert-file-to-base64";
export * from "./get-base64";
export * from "./get-file";
2 changes: 1 addition & 1 deletion src/string/convert-listcases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 3 additions & 2 deletions src/string/param-case.ts
Original file line number Diff line number Diff line change
@@ -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, "-");
}
5 changes: 3 additions & 2 deletions src/string/snake-case.ts
Original file line number Diff line number Diff line change
@@ -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, "_");
}
3 changes: 2 additions & 1 deletion src/string/title-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(" ");
}
35 changes: 0 additions & 35 deletions src/url/convert-url-to-file.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/url/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./convert-url-to-file";
export * from "./identify-extension";
export * from "./identify-filename";
3 changes: 3 additions & 0 deletions tests/file/base64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"str": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAMDAwMDAwQEBAQFBQUFBQcHBgYHBwsICQgJCAsRCwwLCwwLEQ8SDw4PEg8bFRMTFRsfGhkaHyYiIiYwLTA+PlT/wgALCAFoAWgBAREA/8QAHgAAAwEAAwADAQAAAAAAAAAAAAIGAQgJCgMFBwT/2gAIAQEAAAAA7JTK8JDcrwkNyvCQ3K8JDcrwkNyvCQ3K8JDQMrwkNyvCQ3K8JDcrwkNyvCQ3K8JDcrwkNMFsQjmWxCOZbEI5lsQjmWxCOZbEI5lsQjmK8I5lsQjmWxCOZbEI5lsQjmWxCOZbEI5lsQAkNyvCQ3K8JDcrwkNyvCQ3K8JDcrwkNyvACOZbEI5lsQjmWxCOZbEI5lsQjmWxCOZbEJAWxCOZbEI5lsQjmWxCOZbEI5lsQjmWxCOY0yvCQ3K8JDcrwkNyvCQ3K8JDcrwkNyvCQ0wWxCOZbEI5lsQjmX7jpF7q/wCZlsQjmWxCOZbEI5ivCOZbEI5lsQjmWxDp369udXdOEcy2IRzLYhHMtiAEhuV4SG5XhIblefhfnv74uiTvx5GEhuV4SG5XhIbleAEcy2IRzLYhHMtivn15f9j3ADgN6JHjmWxCOZbEI5lsQkBbEI5lsQjmWxCO4Ldbno6dPO7zs7CLEI5lsQjmWxCOY0yvCQ3K8JDcrw/KfPD3Y8ww4r9FHob/AGQJDcrwkNyvCQ0wWxCOZbEI5lsQ6WPq+4yvCQ6kpXvGCOZbEI5lsQjmK8I5lsQjmWxCObj70beka0jmWx+g82HdDyeWxCOZbEI5lsQAkNyvCQ3K8JBegPsY7FSQ3K84FdWHoN/orwkNyvCQ3K8AI5lsQjmWxCO69+CnoiYjmWxE8/HLPsmsQjmWxCOZbEJAWxCOZbEI5l/h84Pf3+ostiEcyw/nl9Gv3rLYhHMtiEcxple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wXmsSLqDI2zTJcJIqiaeVWrHQ1ZUsRx3hydYP1ASKnxlyRKsB7Ha5guT9o8MGzFdlnQdQT0S5+plnYNZ+M7SvqloAGmNaWo9kf112ofFIxmtwRbS0tns9oKkvRU+LaWKHYjK/jkmbyivEGUzq254tNqZKRG68V5OOHnkmZGS8EzqAx79/DhKTIPN14v8mXjLVik0pJqaPUDwetskQhqyJatEQ3oJjqbdBeOAxVCGrBwQ7XRdT2VzUr/wBkT9aL8Rlo3XnnCQQbbBMRGSrwRES9Vqz8UOxGFyujgubyivA3tS1arRsWGBjmzE4OP7vcB9HjuzkcktIA4v2bqU92NW1Gvstrxgz76G6qY9zDWFTozUmJJbW8HmXhQwMV8lRfh28wL9sGC5sQF0Mbvrx9FAftFpzJ0xuGKx2VRSabN1RTvXNI1FZBlhlu2IYg02CYRAEQ8kRK51E665ux1VzeP1VzdjqrnUTrrnUTrrnUTrrm7HVXN4/VXN2OqudROuudROuudROuubsdVc3j9Vc3Y6q51E6651E6651E665ux1VzeP1VzdjqrnUTrrnUTrrnUTrrm7HVXN4/VXN2OqudROunBUDA7ZiEJCXFFRTqb/GWa7AmtTEYbdXOM6rZFhNpck8xuWoQuy+z5muZs634u4aw+HatqPS4E+LDelNHFNfctIYCubIXAo1yuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VymT0VymT0VymT0VyuT0VyuT0VyuT0VZ1tQ5cqfJhvRWWGGHUN1SNxBTMEVMH9/xLvOvzVd5/Yu86/NV3n9i7zr81Xef2LvOvzVd5/Yu86/NV3n9i7zr81Xef8A1C//2Q=="
}
12 changes: 0 additions & 12 deletions tests/file/convert-base64-to-file._test.ts

This file was deleted.

19 changes: 19 additions & 0 deletions tests/file/get-base64.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading

0 comments on commit e33ca7a

Please sign in to comment.