Skip to content

Commit

Permalink
remove string case utils and replace them with external package
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkulpinski committed Mar 1, 2024
1 parent 587562e commit 74442eb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 63 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"format": "bun biome format --write ."
},
"dependencies": {
"@uiw/color-convert": "^2.0.9"
"@uiw/color-convert": "^2.0.9",
"scule": "^1.3.0"
},
"devDependencies": {
"@babel/runtime": "^7.23.8",
Expand Down
27 changes: 0 additions & 27 deletions src/helpers/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { describe, expect, it } from "bun:test"

import {
capitalize,
convertNewlines,
getExcerpt,
getInitials,
Expand All @@ -11,8 +10,6 @@ import {
range,
splitArrayChunks,
stripHtml,
toSlugCase,
toTitleCase,
} from "./helpers"

describe("range", () => {
Expand All @@ -23,30 +20,6 @@ describe("range", () => {
})
})

describe("capitalize", () => {
it("capitalizes the first letter of a string", () => {
expect(capitalize("hello")).toEqual("Hello")
expect(capitalize("world")).toEqual("World")
expect(capitalize("")).toEqual("")
})
})

describe("toTitleCase", () => {
it("converts a string to title case", () => {
expect(toTitleCase("the quick brown fox")).toEqual("The Quick Brown Fox")
expect(toTitleCase("jUmPinG jAcKs")).toEqual("Jumping Jacks")
expect(toTitleCase("")).toEqual("")
})
})

describe("toSlugCase", () => {
it("converts a string to slug case", () => {
expect(toSlugCase("The Quick Brown Fox")).toEqual("the-quick-brown-fox")
expect(toSlugCase("jumping jacks")).toEqual("jumping-jacks")
expect(toSlugCase("")).toEqual("")
})
})

describe("getShortcutLabel", () => {
it("returns the uppercase key if metaKey is not provided", () => {
expect(getShortcutLabel({ key: "a" })).toEqual("A")
Expand Down
35 changes: 0 additions & 35 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,6 @@ export const sleep = async (delay: number) => {
new Promise(resolve => setTimeout(resolve, delay))
}

/**
* Capitalizes the first letter of a string.
* @param value - The string to capitalize.
* @return The capitalized string.
*/
export const capitalize = (value: string) => {
return value.charAt(0).toUpperCase() + value.slice(1)
}

/**
* Converts a string to title case.
* @param string - The string to convert.
* @returns The converted string.
*/
export const toTitleCase = (string: string | undefined) => {
return string?.toLowerCase().split(" ").map(capitalize).join(" ")
}

/**
* Converts a string to slug case.
* @param string - The string to convert.
* @returns The converted string.
*/
export const toSlugCase = (string?: string) => {
let slug = string || ""

slug = slug.toLowerCase()
slug = slug.replace(/^\s+|\s+$/g, "")
slug = slug.replace(/[^a-z0-9 -]/g, "")
slug = slug.replace(/\s+/g, "-")
slug = slug.replace(/-+/g, "-")

return encodeURI(slug)
}

/**
* Returns a label for the first search key shortcut found.
* @returns The label for the shortcut.
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export type ValidatePath<T, K extends string> = K extends ""
: Extract<keyof T, string>
: Extract<keyof T, string>

// External exports
export * from "scule"

// Internal exports
export * from "./colors/colors"
export * from "./errors/errors"
export * from "./events/events"
Expand Down

0 comments on commit 74442eb

Please sign in to comment.