Introducing neoqs: A Modern Approach to Querystring Parsing
neoqs is a cutting-edge library designed for parsing and stringifying query strings, taking its roots from the popular qs
library. Maintaining full backward compatibility, it brings enhanced features in a modern, lightweight package. Developed in TypeScript, neoqs aims to provide an improved developer experience while eliminating dependencies and polyfills.
Project Overview
- Lead Maintainer: Puru Vijay
- Origins: A fork of the
qs
library by TJ Holowaychuk, with a focus on modernization and security.
Key Features
- Size: At just 3.9KB (min+brotli),
neoqs
is significantly smaller than its predecessor,qs
. - Dependencies: Boasts zero dependencies, which contributes to its light footprint.
- Written in TypeScript: This allows developers to discard the
@types/qs
package. - ESM-first with Legacy Support: Prioritizes ES Module usage but supports older environments via a legacy build.
- Backward Compatible: Retains the API used by
qs
allowing easy swap withneoqs
.
Why Choose neoqs?
If you're currently using qs
in your project, neoqs presents itself as an impeccable drop-in replacement. It offers the same API but with enhanced performance and no dependencies, making it more efficient and secure.
When to Avoid neoqs?
For projects with exceedingly simple query string needs, such as handling only top-level keys or when full backward compatibility isn’t a concern, consider using the URLSearchParams
API for a simplified, native approach.
Build Options
neoqs
features two different builds:
-
Default Build:
- Compatible with
qs
but only available as ESM. - Tailored for modern development with ES2022 targeting Node 18+.
- Size: 3.9KB min+brotli.
- Compatible with
-
Legacy Build:
- Supports ES5 and CommonJS, targeting older browsers and Node versions.
- Theoretically compatible back to Node 4.0.0.
- Size: 4.2KB min+brotli.
Recommended Usage Scenarios
- Library Development with CommonJS Support: Opt for the legacy build.
- Modern Environments: Utilize the default build for the latest features and optimizations without risking compatibility issues with older systems.
Getting Started
Example usage in a modern setup:
import * as qs from 'neoqs';
const obj = qs.parse('a=c');
console.log(obj); // Output: { a: 'c' }
const str = qs.stringify(obj);
console.log(str); // Output: 'a=c'
Advanced Features
- Nested Object Parsing: Allows for parsing complex query strings into deeply nested objects while managing prototype pollution risks through options like
plainObjects
andallowPrototypes
. - Depth Control: Configure parsing depth and enforce strict depth checks for added security.
- Parameter Limiting: Prevent abuse by setting limits on parsed parameters.
- Customizable Encoding: Disable URI encoding, or implement custom encoding strategies to fit specific requirements.
- Scalable Handling of Arrays: Offers multiple strategies for stringifying and parsing arrays to suit diverse application needs.
With these robust features, neoqs
empowers developers to handle query strings with control and precision, making it a worthwhile consideration for anyone seeking a modern replacement for qs
.