# qs <sup>[![Version Badge][2]][1]</sup>
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
A querystring parsing and stringifying library with some added security.
Lead Maintainer: [Jordan Harband](https://github.com/ljharb)
The **qs** module was originally created and maintained by [TJ Holowaychuk](https://github.com/visionmedia/node-querystring).
## Usage
```javascript
var qs = require('qs');
var assert = require('assert');
var obj = qs.parse('a=c');
assert.deepEqual(obj, { a: 'c' });
var str = qs.stringify(obj);
assert.equal(str, 'a=c');
```
### Parsing Objects
[](#preventEval)
```javascript
qs.parse(string, [options]);
```
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`.
For example, the string `'foo[bar]=baz'` converts to:
```javascript
assert.deepEqual(qs.parse('foo[bar]=baz'), {
foo: {
bar: 'baz'
}
});
```
When using the `plainObjects` option the parsed value is returned as a null object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
```javascript
var nullObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
assert.deepEqual(nullObject, { a: { hasOwnProperty: 'b' } });
```
By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use `plainObjects` as mentioned above, or set `allowPrototypes` to `true` which will allow user input to overwrite those properties. *WARNING* It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option.
```javascript
var protoObject = qs.parse('a[hasOwnProperty]=b', { allowPrototypes: true });
assert.deepEqual(protoObject, { a: { hasOwnProperty: 'b' } });
```
URI encoded strings work too:
```javascript
assert.deepEqual(qs.parse('a%5Bb%5D=c'), {
a: { b: 'c' }
});
```
You can also nest your objects, like `'foo[bar][baz]=foobarbaz'`:
```javascript
assert.deepEqual(qs.parse('foo[bar][baz]=foobarbaz'), {
foo: {
bar: {
baz: 'foobarbaz'
}
}
});
```
By default, when nesting objects **qs** will only parse up to 5 children deep. This means if you attempt to parse a string like
`'a[b][c][d][e][f][g][h][i]=j'` your resulting object will be:
```javascript
var expected = {
a: {
b: {
c: {
d: {
e: {
f: {
'[g][h][i]': 'j'
}
}
}
}
}
}
};
var string = 'a[b][c][d][e][f][g][h][i]=j';
assert.deepEqual(qs.parse(string), expected);
```
This depth can be overridden by passing a `depth` option to `qs.parse(string, [options])`:
```javascript
var deep = qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
assert.deepEqual(deep, { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } });
```
The depth limit helps mitigate abuse when **qs** is used to parse user input, and it is recommended to keep it a reasonably small number.
For similar reasons, by default **qs** will only parse up to 1000 parameters. This can be overridden by passing a `parameterLimit` option:
```javascript
var limited = qs.parse('a=b&c=d', { parameterLimit: 1 });
assert.deepEqual(limited, { a: 'b' });
```
To bypass the leading question mark, use `ignoreQueryPrefix`:
```javascript
var prefixed = qs.parse('?a=b&c=d', { ignoreQueryPrefix: true });
assert.deepEqual(prefixed, { a: 'b', c: 'd' });
```
An optional delimiter can also be passed:
```javascript
var delimited = qs.parse('a=b;c=d', { delimiter: ';' });
assert.deepEqual(delimited, { a: 'b', c: 'd' });
```
Delimiters can be a regular expression too:
```javascript
var regexed = qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ });
assert.deepEqual(regexed, { a: 'b', c: 'd', e: 'f' });
```
Option `allowDots` can be used to enable dot notation:
```javascript
var withDots = qs.parse('a.b=c', { allowDots: true });
assert.deepEqual(withDots, { a: { b: 'c' } });
```
If you have to deal with legacy browsers or services, there's
also support for decoding percent-encoded octets as iso-8859-1:
```javascript
var oldCharset = qs.parse('a=%A7', { charset: 'iso-8859-1' });
assert.deepEqual(oldCharset, { a: '§' });
```
Some services add an initial `utf8=✓` value to forms so that old
Internet Explorer versions are more likely to submit the form as
utf-8. Additionally, the server can check the value against wrong
encodings of the checkmark character and detect that a query string
or `application/x-www-form-urlencoded` body was *not* sent as
utf-8, eg. if the form had an `accept-charset` parameter or the
containing page had a different character set.
**qs** supports this mechanism via the `charsetSentinel` option.
If specified, the `utf8` parameter will be omitted from the
returned object. It will be used to switch to `iso-8859-1`/`utf-8`
mode depending on how the checkmark is encoded.
**Important**: When you specify both the `charset` option and the
`charsetSentinel` option, the `charset` will be overridden when
the request contains a `utf8` parameter from which the actual
charset can be deduced. In that sense the `charset` will behave
as the default charset rather than the authoritative charset.
```javascript
var detectedAsUtf8 = qs.parse('utf8=%E2%9C%93&a=%C3%B8', {
charset: 'iso-8859-1',
charsetSentinel: true
});
assert.deepEqual(detectedAsUtf8, { a: 'ø' });
// Browsers encode the checkmark as ✓ when submitting as iso-8859-1:
var detectedAsIso8859_1 = qs.parse('utf8=%26%2310003%3B&a=%F8', {
charset: 'utf-8',
charsetSentinel: true
});
assert.deepEqual(detectedAsIso8859_1, { a: 'ø' });
```
If you want to decode the `&#...;` syntax to the actual character,
you can specify the `interpretNumericEntities` option as well:
```javascript
var detectedAsIso8859_1 = qs.parse('a=%26%239786%3B', {
charset: 'iso-8859-1',
interpretNumericEntities: true
});
assert.deepEqual(detectedAsIso8859_1, { a: '☺' });
```
It also works when the charset has been detected in `charsetSentinel`
mode.
### Parsing Arrays
**qs** can also parse arrays using a similar `[]` notation:
```javascript
var withArray = qs.parse('a[]=b&a[]=c');
assert.deepEqual(withArray, { a: ['b', 'c'] });
```
You may specify an index as well:
```javascript
var withIndexes = qs.parse('a[1]=c&a[0]=b');
assert.deepEqual(withIndexes, { a: ['b', 'c'] });
```
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number
to create an array. When creating arrays with specific indices, **qs** will compact a sparse array to only the existing values preserving
their order:
```javascript
var noSparse = qs.parse('a[1]=b&a[15]=c');
assert.deepEqual(noSparse, { a: ['b', 'c'] });
```
You may also use `allowSparse` option to parse sparse arrays:
```javascript
var sparseArray = qs.parse('a[1]=2&a[3]=5', { allowSparse: true });
assert.deepEqual(sparseArray, { a: [, '2', , '5'] });
```
Note that an empty string is also a value, and will be preserved:
```javascript
var withEmptyString = qs.parse('a[]=&a[]=b');
assert.deepEqual(withEmptyString, { a: ['', 'b'] });
var withIndexedEmptyString = qs.parse('a[0]=b&a[1]=&a[2]=c');
assert.deepEqual(withIndexedEmptyString, { a: ['b', '', 'c'] });
```
**qs** will also limit specifying indices in an array to a maximum index of `20`. Any array members with an index of greater than `20` will
instead
没有合适的资源?快使用搜索试试~ 我知道了~
微信小程序项目-美食列表
共524个文件
js:154个
md:108个
json:81个
需积分: 1 0 下载量 156 浏览量
2024-05-13
21:45:56
上传
评论
收藏 5.34MB ZIP 举报
温馨提示
内容:微信小程序——美食列表源码 适用人群:小程序开发初学者 其他:下载了资源的伙计麻烦点个免费的关注和点赞
资源推荐
资源详情
资源评论
收起资源包目录
微信小程序项目-美食列表 (524个子文件)
mime.cmd 316B
.editorconfig 540B
.editorconfig 286B
.eslintignore 10B
.eslintignore 10B
.eslintrc 1KB
.eslintrc 1022B
.eslintrc 585B
.eslintrc 247B
.eslintrc 231B
.eslintrc 180B
.eslintrc 176B
.eslintrc 172B
.eslintrc 164B
6b41b8ef2edb71df237dc84ad97793fe484797.jpg 172KB
ecfae46d44390d0fad40b4dacbd04213334496.jpg 155KB
__45042322__1416996.jpg 155KB
__47190232__7563879.jpg 148KB
0306a219ae56c2a8bd93fb91a9b034e6336340.jpg 135KB
__46146569__6411830.jpg 131KB
2a4ca81a2a6e43649c815a9a44ce891f362231.jpg 128KB
e94d919267508bfcfb1b629d8727c17f106610.jpg 124KB
__45049923__6050023.jpg 123KB
71143bedc401441202d6cab04a04cf85108784.jpg 121KB
f78bc7c15702b7f3fe7021ebf17494ef357509.jpg 116KB
4cbf9155ddf4075df7c442945de5277e396004.jpg 116KB
aa3906333aed718ad8cf3c2a9ca4a7c3346489.jpg 113KB
e72d342d802c410f6622f5e36f265176312462.jpg 110KB
55feb9a557b54ab5594b3efdc51b6e8f277046.jpg 107KB
c274f0927931d6be76b156cccf14ab7c252781.jpg 93KB
8ce591879123fe1dcf6d48c022c7bd8f260331.jpg 87KB
9f7fc7c9e7dca62deb8c8e297ca4686b70710.jpg 71KB
__48385594__1448848.jpg 68KB
ea766dbba77f00bd37643c9697bc01c8153096.jpg 64KB
e724e21efcaa3219e38497b340e08d01153620.jpg 61KB
2cd60840a9952e6366e99202881d1c57152524.jpg 60KB
0339a1bb9e5e3bb59350d15af9847bd0147857.jpg 58KB
acb1b6e571229803ddcbc48708020f38147357.jpg 55KB
c23c7c29e74602f9939158c3f3e21fda141581.jpg 55KB
ad87ab62a9daeb88e67e4e9a2ec97323141365.jpg 53KB
b7a446c030060222597d454ccb3e29b2136826.jpg 52KB
99a6e8bb98bed7c724ca63e091693d94139085.jpg 51KB
c2ce13dc00d3a99551c4ceed3a335b60136735.jpg 50KB
fcc7c3ec2ba903cb4b75232e2b35db6650472.jpg 49KB
0b4003327bef5c16677d26b904b3f3f0129083.jpg 48KB
9f2b7f9e012fcbdfeac7933183c33517135253.jpg 47KB
169bab75ef27222be4b56f8229c213cb128037.jpg 47KB
37628d111617d3b7a1565996ed059927131383.jpg 46KB
2f6a1aae6e6a72c05b89b65b3c0d90f446665.jpg 46KB
68405bb25b7510424aa45b36016e2dcf124862.jpg 45KB
35a158f022bc41433fb2a94ef7b81477127695.jpg 45KB
8d154dd60be1cb05d7aef075a3e46765121513.jpg 43KB
2ebad3638ae63edd7c4c1d8033d578ec119900.jpg 43KB
e68910d95f9c4056e2066a23e708f35b43639.jpg 42KB
e5d43f4230aec5444fe72160de740f31119005.jpg 42KB
484a437d64fff67e051fe254d7395cad121490.jpg 42KB
3057d6e185181f1a4819424b2a3fa56f118050.jpg 42KB
c40ee7af26d65a44626f7cc905e2c7c3117336.jpg 42KB
c0609cbcfd1f1a95256fe25dc30d9238119711.jpg 41KB
a8b49f497c9b7fc68449000711f587c5117154.jpg 41KB
f077a13f324aaf0db0b75163eaf29f3d110649.jpg 41KB
9aa8f3d00cd6caae6bd506ba1d9a1e69117204.jpg 38KB
d7377b700bd01dfcfdcf3bb20be32949112265.jpg 38KB
8286612e525aee2cc83760bbe2ff3c7b106503.jpg 38KB
9cdf099d87d0dbc027fe8c1ccae6017d104798.jpg 37KB
bf53d96ec2272d19d087d72d67df565f37970.jpg 37KB
cc9138c67cf7cec2789a5b13bb7132dc43167.jpg 37KB
ac106e3c34373dbeb7ecdb11d0a9938337722.jpg 37KB
7d9cd35c3e1815830cd1376e71faa686108274.jpg 37KB
91c1f50b978a6b5c2850c7b4f4577fe637117.jpg 36KB
32a178b1a223a52301be30287aaa9bc136898.jpg 36KB
5a66ad072d784e828172c6ac23df9f26112275.jpg 36KB
4e01539cd10265284b7b895746aea54836686.jpg 36KB
39ac88a1f8ef7c4686019c206da0766536494.jpg 36KB
e6ddb4f0532fc1e028e5d3b5a62ef71535980.jpg 35KB
3e028a516f458b38485205acb1412de435804.jpg 35KB
0f6bbcb4b9f37de4b4a875d314175d25109824.jpg 34KB
a56133247578dadd95f444ff6315f0e134886.jpg 34KB
e88d92d039eb53d084a307a886d04611102578.jpg 34KB
ffead6264d34e3c0f0ba3b33e55e57ed109930.jpg 34KB
843f3a97e4c2ec24888a0501b3ccda9198016.jpg 34KB
f69589ef518f9b264b21005bdcf683b4102030.jpg 33KB
c9f1c341821b4656f81bfb976cbfa55c32496.jpg 32KB
2846ed948e95eef4c4d50edaf52a483432023.jpg 31KB
b4e94fa5cdb1838bc362ea5b985ba1ae92457.jpg 31KB
1a71f6f0fc3370fe061d0894b530e71d94674.jpg 31KB
bfeb6437bbb3a125bee67473c52de9a978845.jpg 30KB
db80ebddd202b27bba28d7cd1ae9273629749.jpg 29KB
9dc80616b6178221cf61df4b9dc0d1d929640.jpg 29KB
99b0a33bff1190385b53405dfd5fcc8628228.jpg 28KB
76eb2d45ecdf7c82e0e5fb94059d7ed927134.jpg 26KB
0de97931592d5f006a713ce2f22b41a826964.jpg 26KB
a684723c1ccbb89675ac14c89ce203a513606.jpg 13KB
qs.js 67KB
parse.js 34KB
stringify.js 32KB
sbcs-data-generated.js 31KB
response.js 27KB
index.js 23KB
dbcs-codec.js 21KB
共 524 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
钞人本仁
- 粉丝: 200
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功