Skip to content

Commit

Permalink
[Tests] add editorconfig-tools
Browse files Browse the repository at this point in the history
 - also, whitespace tweaks to comply
  • Loading branch information
ljharb committed Jun 14, 2017
1 parent e25af9b commit b9519c9
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 132 deletions.
30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 140

[test/*]
max_line_length = off

[*.md]
max_line_length = off

[*.json]
max_line_length = off

[Makefile]
max_line_length = off

[CHANGELOG.md]
indent_style = space
indent_size = 2

[LICENSE]
indent_size = 2
max_line_length = off
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"no-continue": 1,
"no-magic-numbers": 0,
"no-restricted-syntax": [2, "BreakStatement", "DebuggerStatement", "ForInStatement", "LabeledStatement", "WithStatement"],
"operator-linebreak": [2, "after"],
"operator-linebreak": [2, "before"],
}
}
76 changes: 38 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ For example, the string `'foo[bar]=baz'` converts to:

```javascript
assert.deepEqual(qs.parse('foo[bar]=baz'), {
foo: {
bar: 'baz'
}
foo: {
bar: 'baz'
}
});
```

Expand All @@ -63,19 +63,19 @@ URI encoded strings work too:

```javascript
assert.deepEqual(qs.parse('a%5Bb%5D=c'), {
a: { b: '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'
foo: {
bar: {
baz: 'foobarbaz'
}
}
}
});
```

Expand All @@ -84,19 +84,19 @@ By default, when nesting objects **qs** will only parse up to 5 children deep. T

```javascript
var expected = {
a: {
b: {
c: {
d: {
e: {
f: {
'[g][h][i]': 'j'
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);
Expand Down Expand Up @@ -240,19 +240,19 @@ assert.equal(unencoded, 'a[b]=c');

Encoding can be disabled for keys by setting the `encodeValuesOnly` option to `true`:
```javascript
var encodedValues = qs.stringify(
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
{ encodeValuesOnly: true }
)
var encodedValues = qs.stringify(
{ a: 'b', c: ['d', 'e=f'], f: [['g'], ['h']] },
{ encodeValuesOnly: true }
);
assert.equal(encodedValues,'a=b&c[0]=d&c[1]=e%3Df&f[0][0]=g&f[1][0]=h');
```

This encoding can also be replaced by a custom encoding method set as `encoder` option:

```javascript
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str) {
// Passed in values `a`, `b`, `c`
return // Return encoded string
// Passed in values `a`, `b`, `c`
return // Return encoded string
}})
```

Expand All @@ -262,8 +262,8 @@ Analogue to the `encoder` there is a `decoder` option for `parse` to override de

```javascript
var decoded = qs.parse('x=z', { decoder: function (str) {
// Passed in values `x`, `z`
return // Return decoded string
// Passed in values `x`, `z`
return // Return decoded string
}})
```

Expand Down Expand Up @@ -357,7 +357,7 @@ You may use the `sort` option to affect the order of parameter keys:

```javascript
function alphabeticalSort(a, b) {
return a.localeCompare(b);
return a.localeCompare(b);
}
assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort }), 'a=c&b=f&z=y');
```
Expand All @@ -368,17 +368,17 @@ pass an array, it will be used to select properties and array indices for string

```javascript
function filterFunc(prefix, value) {
if (prefix == 'b') {
// Return an `undefined` value to omit a property.
return;
}
if (prefix == 'e[f]') {
return value.getTime();
}
if (prefix == 'e[g][0]') {
return value * 2;
}
return value;
if (prefix == 'b') {
// Return an `undefined` value to omit a property.
return;
}
if (prefix == 'e[f]') {
return value.getTime();
}
if (prefix == 'e[g][0]') {
return value * 2;
}
return value;
}
qs.stringify({ a: 'b', c: 'd', e: { f: new Date(123), g: [2] } }, { filter: filterFunc });
// 'a=b&c=d&e[f]=123&e[g][0]=4'
Expand Down
38 changes: 19 additions & 19 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "qs",
"main": "dist/qs.js",
"homepage": "https://github.com/hapijs/qs",
"authors": [
"Nathan LaFreniere <quitlahok@gmail.com>"
],
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
"keywords": [
"querystring",
"qs"
],
"license": "BSD-3-Clause",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
"name": "qs",
"main": "dist/qs.js",
"homepage": "https://github.com/hapijs/qs",
"authors": [
"Nathan LaFreniere <quitlahok@gmail.com>"
],
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
"keywords": [
"querystring",
"qs"
],
"license": "BSD-3-Clause",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
26 changes: 13 additions & 13 deletions component.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "qs",
"repository": "hapijs/qs",
"description": "query-string parser / stringifier with nesting support",
"version": "6.4.0",
"keywords": ["querystring", "query", "parser"],
"main": "lib/index.js",
"scripts": [
"lib/index.js",
"lib/parse.js",
"lib/stringify.js",
"lib/utils.js"
],
"license": "BSD-3-Clause"
"name": "qs",
"repository": "hapijs/qs",
"description": "query-string parser / stringifier with nesting support",
"version": "6.4.0",
"keywords": ["querystring", "query", "parser"],
"main": "lib/index.js",
"scripts": [
"lib/index.js",
"lib/parse.js",
"lib/stringify.js",
"lib/utils.js"
],
"license": "BSD-3-Clause"
}
10 changes: 5 additions & 5 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ var parseObject = function parseObjectRecursive(chain, val, options) {
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root;
var index = parseInt(cleanRoot, 10);
if (
!isNaN(index) &&
root !== cleanRoot &&
String(index) === cleanRoot &&
index >= 0 &&
(options.parseArrays && index <= options.arrayLimit)
!isNaN(index)
&& root !== cleanRoot
&& String(index) === cleanRoot
&& index >= 0
&& (options.parseArrays && index <= options.arrayLimit)
) {
obj = [];
obj[index] = parseObject(chain, val, options);
Expand Down
19 changes: 11 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ exports.encode = function (str) {
var c = string.charCodeAt(i);

if (
c === 0x2D || // -
c === 0x2E || // .
c === 0x5F || // _
c === 0x7E || // ~
(c >= 0x30 && c <= 0x39) || // 0-9
(c >= 0x41 && c <= 0x5A) || // a-z
(c >= 0x61 && c <= 0x7A) // A-Z
c === 0x2D // -
|| c === 0x2E // .
|| c === 0x5F // _
|| c === 0x7E // ~
|| (c >= 0x30 && c <= 0x39) // 0-9
|| (c >= 0x41 && c <= 0x5A) // a-z
|| (c >= 0x61 && c <= 0x7A) // A-Z
) {
out += string.charAt(i);
continue;
Expand All @@ -135,7 +135,10 @@ exports.encode = function (str) {

i += 1;
c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF));
out += hexTable[0xF0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3F)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]; // eslint-disable-line max-len
out += hexTable[0xF0 | (c >> 18)]
+ hexTable[0x80 | ((c >> 12) & 0x3F)]
+ hexTable[0x80 | ((c >> 6) & 0x3F)]
+ hexTable[0x80 | (c & 0x3F)];
}

return out;
Expand Down
Loading

0 comments on commit b9519c9

Please sign in to comment.