Skip to content

Commit

Permalink
add custom wrapper around slugify function
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkulpinski committed Mar 25, 2024
1 parent 90cd196 commit 35f20a3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@curiousleaf/utils",
"description": "A lightweight set of utilities",
"version": "1.0.19",
"version": "1.0.20",
"license": "MIT",
"type": "module",
"author": {
Expand Down
12 changes: 12 additions & 0 deletions src/helpers/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isCuid,
isTruthy,
range,
slugify,
splitArrayChunks,
stripHtml,
} from "./helpers"
Expand Down Expand Up @@ -63,6 +64,17 @@ describe("getExcerpt", () => {
})
})

describe("slugify", () => {
it("should slugify the input string", () => {
expect(slugify("HelloWorld")).toEqual("helloworld")
expect(slugify("Hello World")).toEqual("hello-world")
expect(slugify("HelloWorld", true)).toEqual("hello-world")
expect(slugify("Lorem Ipsum Dolor Sit Amet")).toEqual("lorem-ipsum-dolor-sit-amet")
expect(slugify("1234")).toEqual("1234")
expect(slugify("")).toEqual("")
})
})

describe("isCuid", () => {
it("checks if a given string is a valid cuid", () => {
expect(isCuid("clixluz61002mk9stbofhbkv6")).toEqual(true)
Expand Down
13 changes: 13 additions & 0 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import slugifyString from "@sindresorhus/slugify"

/**
* A collection of helper functions used throughout the application.
*/
Expand Down Expand Up @@ -77,6 +79,17 @@ export const getExcerpt = (content: string | undefined | null, length = 250) =>
return text
}

/**
* Converts a string into a slugified version.
*
* @param input The string to be slugified.
* @param decamelize Whether to decamelize the string. Defaults to false.
* @returns The slugified string.
*/
export const slugify = (input: string, decamelize = false): string => {
return slugifyString(input, { decamelize })
}

/**
* Check if a given string is a valid cuid
* @param id A string to check
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export type ValidatePath<T, K extends string> = K extends ""

// External exports
export * from "scule"
export { default as slugify } from "@sindresorhus/slugify"

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

0 comments on commit 35f20a3

Please sign in to comment.