Files
buuh/packages/core/lib/query.js
T
Bendik Aagaard LynghaugandClaude Fable 5 4ad3d02207 feat(core): add @choojs/core — ESM port of choo with consolidated nano* internals
Same public API as choo 7.1.0 (use/route/start/mount/toString/emit; choo()
callable with or without new, Choo exported). nanobus, nanorouter+wayfarer,
nanolru+component cache, nanoraf, nanohref, nanotiming, document-ready and
scroll-to-anchor are ported into lib/ with per-file attribution; nanoquery
is replaced by URLSearchParams. The v7 node test suite is ported from tape
to node:test and passes unchanged in behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014NgfSjHE11oFpoSnLVKLXd
2026-09-08 15:59:26 +02:00

24 lines
689 B
JavaScript

// Replaces nanoquery 1.3.0 (MIT) with the platform's URLSearchParams.
// Semantics preserved: returns a plain object; repeated keys become arrays.
import { equal } from './assert.js'
export default function nanoquery (url) {
equal(typeof url, 'string', 'nanoquery: url should be type string')
const query = {}
const index = url.indexOf('?')
if (index === -1) return query
const params = new URLSearchParams(url.slice(index + 1))
for (const [key, value] of params) {
if (Object.hasOwn(query, key)) {
if (Array.isArray(query[key])) query[key].push(value)
else query[key] = [query[key], value]
} else {
query[key] = value
}
}
return query
}