@aaronhayes/qstring 中文文档教程
qstring
构建查询字符串的最简单方法。 一种轻量级、易于使用的方式来构建包括查询字符串在内的完整 url。 小于 400B 缩小 & G压缩!
流行的query-string只处理部分querystring部分,所以还有一步构建最终的url。 API 的灵感来自 JedWatson 的 Classnames 包。
Install
$ npm install --save @aaronhayes/qstring
$ yarn add @aaronhayes/qstring
Usage
import qstring, { ArrayFormat } from '@aaronhayes/qstring';
const qs = qstring('https://myapi.com', {
foo: 'bar',
foobar: true,
foo3: null,
foo4: undefined
});
console.log(qs);
// https://myapi.com?foo=bar&foobar=true
const qs = qstring(
'https://myapi.com',
{
foo: ['hello', 'world'],
cat: 'dog'
}
);
console.log(qs);
// https://myapi.com?foo=hello&foo=world&cat=dog
const qs = qstring(
'https://myapi.com',
{
foo: ['hello', 'world'],
cat: 'dog'
},
ArrayFormat.comma
);
console.log(qs);
// https://myapi.com?foo=hello,world&cat=dog
See Also
qstring
The easiest way to build querystrings. A lightweight, easy to use way to build full urls including the querystring. Less than 400B Minified & GZipped!
The popular query-string only handles the part querystring part, so there is another step of building the final url. The API inspired by JedWatson's Classnames Package.
Install
$ npm install --save @aaronhayes/qstring
$ yarn add @aaronhayes/qstring
Usage
import qstring, { ArrayFormat } from '@aaronhayes/qstring';
const qs = qstring('https://myapi.com', {
foo: 'bar',
foobar: true,
foo3: null,
foo4: undefined
});
console.log(qs);
// https://myapi.com?foo=bar&foobar=true
const qs = qstring(
'https://myapi.com',
{
foo: ['hello', 'world'],
cat: 'dog'
}
);
console.log(qs);
// https://myapi.com?foo=hello&foo=world&cat=dog
const qs = qstring(
'https://myapi.com',
{
foo: ['hello', 'world'],
cat: 'dog'
},
ArrayFormat.comma
);
console.log(qs);
// https://myapi.com?foo=hello,world&cat=dog