npm.io
0.1.3 • Published 3 years ago

@thumbsmith/url

Licence
ISC
Version
0.1.3
Deps
1
Size
4 kB
Vulns
0
Weekly
0

@thumbsmith/url

Small utility to help with constructing thumbsmith thumbnail URLs

Read more at http://thumbsmith.com/

Installation

npm install @thumbsmith/url

Usage

import getImageUrl from "@thumbsmith/url";

const imageUrl = getImageUrl({
  account: "my-account-name",
  template: "product",
  type: "png", // Optional
  data: {
    title: "Hello world!",
    breadcrumb: ["Products", "Sports", "Bikes"],
    price: 49.99,
  },
});

console.log(imageUrl);
// Result:
// https://cdn.thumbsmith.com/v1/u/my-user-name/product.png?title=Hello%20world%21&breadcrumb%5B0%5D=Products&breadcrumb%5B1%5D=Sports&breadcrumb%5B2%5D=Bikes&price=49.99
Typescript
import getImageUrl from "@thumbsmith/url";

interface ImageProps {
  title: string;
  breadcrumb: string[];
  price: number;
}

const imageUrl = getImageUrl<ImageProps>({
  account: "my-account-name",
  template: "product",
  type: "png", // Optional
  data: {
    title: "Hello world!",
    breadcrumb: ["Products", "Sports", "Bikes"],
    price: 49.99,

    // This line will cause an error
    foo: "bar",
  },
});

See the use a template page for more info.