JSPM

@bearstudio/lunalink

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 129
  • Score
    100M100P100Q83376F
  • License MIT

Lightweight TypeScript library to efficiently maintain and build URLs

Package Exports

    Readme

    @bearstudio/lunalink

    Usage

    Install the package using your favorite package manager:

    npm install @bearstudio/lunalink
    yarn add @bearstudio/lunalink
    pnpm add @bearstudio/lunalink

    Import the tools you need:

    import { ExtractParams, lunalink } from "@bearstudio/lunalink";
    
    const THE_URL_FOR_MY_API_CALL = "/contacts/:id";
    
    // When you need types from 
    type APICallParams = ExtractParams<typeof THE_URL_FOR_MY_API_CALL>;
         // ^? type APICallParams = { id: string; }
    
    // Generate the complete string with type safety
    const response = await fetch(
      lunalink(THE_URL_FOR_MY_API_CALL, {
        id: "9BD30040-ECFE-4D7D-AD0C-E723591E22CB",
      })
    );
    
    // You can also do more, by giving more attributes. It will add them as search params
    // /contacts/9BD30040-ECFE-4D7D-AD0C-E723591E22CB?search=FirstName
    const response = await fetch(
      lunalink(THE_URL_FOR_MY_API_CALL, {
        id: "9BD30040-ECFE-4D7D-AD0C-E723591E22CB",
        search: "FirstName",
      })
    );