sveltejs / sveltejs/kit

Add a way to access available param-matchers from inside a library

Open
#12,094 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

It's currently not possible to access the param-matcher-functions that are available in an App from inside a library. They need to be passed into the library by reference, one-by-one.

I have a library that requires access to the matcher-functions as it operates on routeIDs.

  • Having to pass matchers to the library one-by-one is cumbersome and error-prone since you're likely to forget to add new matchers
  • vite-glob-imports don't work since they don't respect kit.files.params

As discussed in: https://discord.com/channels/457912077277855764/1226858732223205497/1226858732223205497

Describe the proposed solution

A way to access the matcher-functions that are present in an app. For example an $app/matchers module where we can import the matcher functions from. Given that matchers are already shipped to the client this wouldn't make a meaningful bundle-size difference, it's just about exposing them.

Example:

import * as matchers from "$app/matchers"

matchers.int("123") // true
matchers.float("asd") //false

const availableMatchers = Object.keys(matchers) // ["int", "float", "uuid"]
Alternatives considered

Require library users to pass in matcher-functions one by one. This is awkward since they'er all exported as "match" and the matcher name is implicit from the filename.

import { init } from "some-library"
import { match as int } from "../params/int.js"
import { match as float } from "../params/float.js"

init({ matchers: { int, float }})
Importance

nice to have

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how matcher functions from kit.files.params are loaded and shipped to the client, and how libraries handle routeIDs. Compare the proposed $app/matchers module with the one-by-one imports from ../params/*. Done means a library can enumerate and call all matchers available in the app without manual wiring.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.