qrystr
v0.1.4
Published
Yet another codec for urlencoded data, written from scratch for minimalism, cares about a lot less stuff than node's does. Features include a direction-guessing API and AMD/UMD support.
Downloads
44
Maintainers
Readme
qrystr
Yet another codec for urlencoded data, written from scratch for minimalism, cares about a lot less stuff than node's does. Features include a direction-guessing API and AMD/UMD support.
Still too large a library? You might not need any at all: URLSearchParams are now widely supported.
Usage
from test/usage.js:
var qs = require('qrystr'), eq = assert.deepStrictEqual, sym, x, y, u,
opt, shebang = { prefix: '#!' };
sym = function symmetricEqual(dict, qstr) {
eq(qs(dict), qstr);
eq(qs.stringify(dict), qstr);
eq(qs(qstr), dict);
eq(qs.parse(qstr), dict);
eq(qs('?' + qstr), dict);
eq(qs('#' + qstr), dict);
eq(qs('#!' + qstr, shebang), dict);
};
sym({}, '');
sym({ bar: '42', eq: '=', flag: true, foo: '23' },
'bar=42&eq=%3D&flag&foo=23');
sym({ '@': [ 'Æ', ' ', '?', '&' ], foo: [ 'hi', true, 'cu' ] },
'%40=%C3%86&%40=+&%40=%3F&%40=%26&foo=hi&foo&foo=cu');
x = { empty: [], nope: false, nothing: null, neither: [ null, false ] };
y = [ 23, undefined, 'hi', true, 42, null, 'cu' ];
u = '=23&=hi&&=42&=cu';
eq(qs(x), '');
eq(qs(y), u);
eq(qs(u), { '': [ '23', 'hi', true, '42', 'cu' ] });
eq(qs(x, shebang), '');
eq(qs(y, shebang), '#!' + u);
opt = { prefix: '?' };
eq(qs(x, opt), '');
eq(qs(y, opt), '?' + u);
Known issues
- It can't (yet?) work with deep objects.
- Needs more/better tests and docs. (See source for undocumented features.)
License
ISC