https://github.com/bearstudio/lunalink
Lightweight TypeScript library to efficiently maintain and build URLs
https://github.com/bearstudio/lunalink
alternative builder dynamic link luna parameters ts typescript url
Last synced: 7 months ago
JSON representation
Lightweight TypeScript library to efficiently maintain and build URLs
- Host: GitHub
- URL: https://github.com/bearstudio/lunalink
- Owner: BearStudio
- Created: 2025-02-23T21:28:09.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-05-24T09:10:08.000Z (8 months ago)
- Last Synced: 2025-06-09T04:58:16.373Z (7 months ago)
- Topics: alternative, builder, dynamic, link, luna, parameters, ts, typescript, url
- Language: TypeScript
- Homepage:
- Size: 675 KB
- Stars: 15
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# lunalink

This library is an alternative to [`urlcat`](https://github.com/balazsbotond/urlcat)
which isn't maintained anymore. That is why it is named after my **cat**, Luna ๐โโฌ.
Link is because it is easy to say after `luna`. That's it, that's the whole story.
I ([@yoannfleurydev](https://github.com/yoannfleurydev)), did not want to fork
`urlcat` to challenge myself into reimplementing it. Some API design are made to
simplify my development, I hope it will simplify yours too.
## Features
- ๐ค Tiny (**2.8 kB** minified + gzipped)
- ๐ฆ TypeScript first
- ๐งช Fully tested
## Installation
Install the package using your favorite package manager:
```sh
npm install @bearstudio/lunalink
yarn add @bearstudio/lunalink
pnpm add @bearstudio/lunalink
```
## Usage
Go from this kind of code:
```ts
type EventCategoryType = {
year: number;
typeId: string;
categoryId: string;
filter?: string;
page?: string;
size?: string;
}
const useEventCategory = (params: EventCategoryType) => {
const api = useApi();
return useQuery({
queryKey: ['event', 'type', 'category', params],
queryFn: async () => {
const searchParams = new URLSearchParams(pick(params, ['filter', 'page', 'size']));
const response = await api.get(`demo/event/${params.year}/type/${params.typeId}/category/${params.categoryId}?${searchParams.toString()}`);
return response.json();
}
})
}
```
> ๐ก This sample of code was purely invented for the example.
to this kind of code:
```ts
import { lunalink, ExtractParams } from "@bearstudio/lunalink";
const EventCategoryIdRoute = 'demo/event/:year/type/:typeId/category/:categoryId'
type EventCategoryIdRouteType = ExtractParams & {
filter?: string;
page?: string;
size?: string;
}
const useEventCategory = (params:) => {
const api = useApi();
return useQuery({
queryKey: ['event', 'type', 'category', params],
queryFn: async () => {
const response = await api.get(lunalink(EventTypeCategoryId, params));
return response.json();
}
})
}
```
so you don't have to maintain your type yourself, and enjoy readability.
## API
```ts
import { lunalink, ExtractParams } from "@bearstudio/lunalink";
// lunalink(path, variables, config)
lunalink("a/path/with/:variables", { variables: "a-variable" }, { baseURL: "https://example.org" })
```
## What's inside?
This monorepo includes the following packages/apps:
### Apps and Packages
- `web`: a [Next.js](https://nextjs.org/) app
- `@repo/lunalink`: the source code of the library. Learn mode about it in its dedicated [README](./packages/lunalink/README.md)
- `@repo/eslint-config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
- `@repo/typescript-config`: `tsconfig.json`s used throughout the monorepo
Each package/app is 100% [TypeScript](https://www.typescriptlang.org/).
### Build
To build all apps and packages, run the following command:
```
pnpm build
```
### Develop
To develop all apps and packages, run the following command:
```
pnpm dev
```
## Useful Links
Learn more about the power of Turborepo:
- [Tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks)
- [Caching](https://turbo.build/repo/docs/core-concepts/caching)
- [Remote Caching](https://turbo.build/repo/docs/core-concepts/remote-caching)
- [Filtering](https://turbo.build/repo/docs/core-concepts/monorepos/filtering)
- [Configuration Options](https://turbo.build/repo/docs/reference/configuration)
- [CLI Usage](https://turbo.build/repo/docs/reference/command-line-reference)