Skip to content

Commit

Permalink
feat: rework to use fast-querystring
Browse files Browse the repository at this point in the history
Uses a fork of fast-querystring instead of having to do two passes.
  • Loading branch information
43081j committed Jun 20, 2024
1 parent 6178171 commit f093462
Show file tree
Hide file tree
Showing 11 changed files with 519 additions and 115 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build & Test

on:
push:
branches: [master]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use Node v${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm run test
47 changes: 47 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Publish Release (npm)

on:
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22
- name: Install Dependencies
run: npm ci
- name: Lint
run: npm run lint
- name: Test
run: npm test

publish-npm:
needs: build
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 22.x
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- run: npm ci
- run: npm version ${TAG_NAME} --git-tag-version=false
env:
TAG_NAME: ${{ github.ref_name }}
- run: npm publish --provenance --access public --tag next
if: "github.event.release.prerelease"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
- run: npm publish --provenance --access public
if: "!github.event.release.prerelease"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2024 James Garbutt
Copyright (c) 2022 Yagiz Nizipli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# nanoquery

A lightweight query string parser/stringifier with support for nesting and some
configurability.

Built on top of [fast-querystring](https://github.com/anonrig/fast-querystring).

## Install

```sh
npm i -S nanoquery
```

## Usage

Parsing a query string:

```ts
import {parse} from 'nanoquery';

parse('foo.bar=abc&baz=def');

/*
{
foo: {
bar: 'abc'
},
baz: 'def'
}
*/
```

## License

MIT
17 changes: 12 additions & 5 deletions bench/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Bench} from 'tinybench';
import {parse} from '../lib/main.js';
import {parse as fastParse} from 'fast-querystring';

const inputs = [
'foo=123&bar=456',
Expand All @@ -9,11 +10,17 @@ const inputs = [
];
const bench = new Bench();

bench.add('nanoquery (parse)', () => {
for (const input of inputs) {
parse(input);
}
});
bench
.add('nanoquery (parse)', () => {
for (const input of inputs) {
parse(input);
}
})
.add('fast-querystring (no nesting)', () => {
for (const input of inputs) {
fastParse(input);
}
});

await bench.warmup();
await bench.run();
Expand Down
30 changes: 27 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nanoquery",
"version": "0.0.1",
"version": "0.0.0-dev",
"type": "module",
"description": "A small library for parsing and serialisation query strings",
"main": "lib/main.js",
Expand All @@ -13,7 +13,8 @@
"test": "npm run build && node --test lib/test/**/*_test.js",
"lint": "eslint src",
"format": "prettier --write src",
"bench": "node ./bench/main.js"
"bench": "node ./bench/main.js",
"prepare": "npm run build"
},
"repository": {
"type": "git",
Expand All @@ -34,14 +35,18 @@
"homepage": "https://github.com/es-tooling/nanoquery#readme",
"devDependencies": {
"@eslint/js": "^9.1.1",
"@types/dlv": "^1.1.4",
"@types/node": "^20.12.7",
"c8": "^9.1.0",
"prettier": "^3.2.5",
"tinybench": "^2.8.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.1"
"typescript-eslint": "^7.7.1",
"fast-querystring": "^1.1.2"
},
"dependencies": {
"fast-querystring": "^1.1.2"
"dlv": "^1.1.3",
"dset": "^3.1.3",
"fast-decode-uri-component": "^1.0.1"
}
}
Loading

0 comments on commit f093462

Please sign in to comment.