Skip to content

A continuation of HomeBox the inventory and organization system built for the Home User

refactor: remove strings lib (#405)

Tonya2ae1115a3e50
diff --git a/frontend/lib/strings/index.test.ts b/frontend/lib/strings/index.test.ts
deleted file mode 100644
index e07faee6..00000000
--- a/frontend/lib/strings/index.test.ts
+++ /dev/null
@@ -1,56 +0,0 @@
-import { describe, test, expect } from "vitest";
-import { titlecase, capitalize, truncate } from ".";
-
-describe("title case tests", () => {
- test("should return the same string if it's already title case", () => {
- expect(titlecase("Hello World")).toBe("Hello World");
- });
-
- test("should title case a lower case word", () => {
- expect(titlecase("hello")).toBe("Hello");
- });
-
- test("should title case a sentence", () => {
- expect(titlecase("hello world")).toBe("Hello World");
- });
-
- test("should title case a sentence with multiple words", () => {
- expect(titlecase("hello world this is a test")).toBe("Hello World This Is A Test");
- });
-});
-
-describe("capitilize tests", () => {
- test("should return the same string if it's already capitalized", () => {
- expect(capitalize("Hello")).toBe("Hello");
- });
-
- test("should capitalize a lower case word", () => {
- expect(capitalize("hello")).toBe("Hello");
- });
-
- test("should capitalize a sentence", () => {
- expect(capitalize("hello world")).toBe("Hello world");
- });
-
- test("should capitalize a sentence with multiple words", () => {
- expect(capitalize("hello world this is a test")).toBe("Hello world this is a test");
- });
-});
-
-describe("truncase tests", () => {
- test("should return the same string if it's already truncated", () => {
- expect(truncate("Hello", 5)).toBe("Hello");
- });
-
- test("should truncate a lower case word", () => {
- expect(truncate("hello", 3)).toBe("hel...");
- });
-
- test("should truncate a sentence", () => {
- expect(truncate("hello world", 5)).toBe("hello...");
- });
-
- test("should truncate a sentence with multiple words", () => {
- expect(truncate("hello world this is a test", 10)).toBe("hello worl...");
- });
-});
diff --git a/frontend/lib/strings/index.ts b/frontend/lib/strings/index.ts
deleted file mode 100644
index 9f23e90c..00000000
--- a/frontend/lib/strings/index.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-export function titlecase(str: string) {
- return str
- .split(" ")
- .map(word => word[0].toUpperCase() + word.slice(1))
- .join(" ");
-}
-
-export function capitalize(str: string) {
- return str[0].toUpperCase() + str.slice(1);
-}
-
-export function truncate(str: string, length: number) {
- return str.length > length ? str.substring(0, length) + "..." : str;
-}
diff --git a/frontend/pages/item/[id]/index/edit.vue b/frontend/pages/item/[id]/index/edit.vue
index 47e76474..52642667 100644
--- a/frontend/pages/item/[id]/index/edit.vue
+++ b/frontend/pages/item/[id]/index/edit.vue
@@ -3,7 +3,6 @@
import { AttachmentTypes } from "~~/lib/api/types/non-generated";
import { useLabelStore } from "~~/stores/labels";
import { useLocationStore } from "~~/stores/locations";
- import { capitalize } from "~~/lib/strings";
import Autocomplete from "~~/components/Form/Autocomplete.vue";
import MdiDelete from "~icons/mdi/delete";
import MdiPencil from "~icons/mdi/pencil";
@@ -378,7 +377,7 @@
});
const attachmentOpts = Object.entries(AttachmentTypes).map(([key, value]) => ({
- text: capitalize(key),
+ text: key[0].toUpperCase() + key.slice(1),
value,
}));