@hobenakicoffee/libraries 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hobenakicoffee/libraries",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "type": "module",
5
5
  "types": "src/index.ts",
6
6
  "exports": {
package/src/App.tsx CHANGED
@@ -1,6 +1,7 @@
1
1
  import { useState } from "react";
2
2
  import { Button } from "./components/ui/button";
3
3
  import { Calendar } from "./components/ui/calendar";
4
+ import { getProductLink } from "./utils/get-product-link";
4
5
 
5
6
  const App = () => {
6
7
  const [date, setDate] = useState<Date | undefined>(new Date());
@@ -20,6 +21,7 @@ const App = () => {
20
21
  onSelect={setDate}
21
22
  selected={date}
22
23
  />
24
+ {getProductLink("leo", "example-product-slug")}
23
25
  </div>
24
26
  </div>
25
27
  );
@@ -0,0 +1,36 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { getProductLink } from "./get-product-link";
3
+
4
+ describe("getProductLink", () => {
5
+ test("builds product link with default baseUrl", () => {
6
+ const result = getProductLink("johndoe", "my-product");
7
+ expect(result).toBe(
8
+ "https://hobenakicoffee.com/@johndoe/shops/products/my-product"
9
+ );
10
+ });
11
+
12
+ test("builds product link with custom baseUrl", () => {
13
+ const result = getProductLink(
14
+ "johndoe",
15
+ "my-product",
16
+ "https://custom.com"
17
+ );
18
+ expect(result).toBe(
19
+ "https://custom.com/@johndoe/shops/products/my-product"
20
+ );
21
+ });
22
+
23
+ test("sanitizes username with whitespace", () => {
24
+ const result = getProductLink(" john doe ", "my-product");
25
+ expect(result).toBe(
26
+ "https://hobenakicoffee.com/@johndoe/shops/products/my-product"
27
+ );
28
+ });
29
+
30
+ test("does not encode slug - passes through as-is", () => {
31
+ const result = getProductLink("johndoe", "my product 123");
32
+ expect(result).toBe(
33
+ "https://hobenakicoffee.com/@johndoe/shops/products/my-product-123"
34
+ );
35
+ });
36
+ });
@@ -0,0 +1,10 @@
1
+ import { getUserPageLink } from "./get-user-page-link";
2
+
3
+ export function getProductLink(
4
+ username: string,
5
+ slug: string,
6
+ baseUrl = "https://hobenakicoffee.com"
7
+ ) {
8
+ const sanitizedSlug = slug.trim().replace(/\s+/g, "-");
9
+ return `${getUserPageLink(username, baseUrl)}/shops/products/${sanitizedSlug}`;
10
+ }
@@ -5,6 +5,7 @@ export * from "./format-date";
5
5
  export * from "./format-number";
6
6
  export * from "./format-plain-text";
7
7
  export * from "./get-newsletter-post-link";
8
+ export * from "./get-product-link";
8
9
  export * from "./get-social-handle";
9
10
  export * from "./get-social-link";
10
11
  export * from "./get-user-name-initials";