Skip to content

Commit

Permalink
remove ava, increment version number
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblehead committed Sep 11, 2023
1 parent feb7df4 commit be97cd8
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 126 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"rules": {
"global-require": 0,
"no-sequences": 0,
"semi": [2, "never"],
"strict": [2, "never"],
"one-var": [2, {
"let": "always",
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:

strategy:
matrix:
node-version: [12.x, 16.x, 18.x]
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

## 6.1.1 - 2023-09-10

* [add support for option 'ignoreEmptyArray',][610] credit @Sanva
* [add support for option 'ignoreEmptyArray',][611] credit @Sanva
* [remove ava and update unit-test pipeline to node v20][612]

[611]: https://github.com/iambumblehead/form-urlencoded/pull/48
[612]: https://github.com/iambumblehead/form-urlencoded/pull/49


## 6.1.0 - 2022-07-29
Expand Down
32 changes: 16 additions & 16 deletions form-urlencoded.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@ export default (data, opts = {}) => {
const {
sorted, ignorenull, ignoreEmptyArray, useDot,
skipIndex, skipBracket, whitespace = '+'
} = opts;
} = opts

const encode = value => String(value)
.replace(/[^ !'()~*]/gu, encodeURIComponent)
.replace(/ /g, whitespace)
.replace(/[!'()~*]/g, ch =>
`%${ch.charCodeAt().toString(16).slice(-2).toUpperCase()}`);
`%${ch.charCodeAt().toString(16).slice(-2).toUpperCase()}`)

const keys = (obj, keyarr = Object.keys(obj)) =>
sorted ? keyarr.sort() : keyarr;
sorted ? keyarr.sort() : keyarr

const filterjoin = arr => arr.filter(e => e).join('&');
const filterjoin = arr => arr.filter(e => e).join('&')

const objnest = (name, obj) => filterjoin(keys(obj).map(key => useDot
? nest(`${name}.${key}`, obj[key])
: nest(`${name}[${key}]`, obj[key])));
: nest(`${name}[${key}]`, obj[key])))

const arrnest = (name, arr, brackets = skipBracket ? '' : '[]') => arr.length
? filterjoin(arr.map((elem, index) => skipIndex
? nest(name + brackets, elem)
: nest(name + '[' + index + ']', elem)))
: ignoreEmptyArray ? null : encode(name + brackets);
: ignoreEmptyArray ? null : encode(name + brackets)

const setnest = (name, set) => filterjoin(
Array.from(set).map(elem => nest(name, elem)));
Array.from(set).map(elem => nest(name, elem)))

const nest = (name, value, type = typeof value, f = null) => {
if (value === f)
f = ignorenull ? f : encode(name) + '=' + f;
f = ignorenull ? f : encode(name) + '=' + f
else if (/string|number|boolean/.test(type))
f = encode(name) + '=' + encode(value);
f = encode(name) + '=' + encode(value)
else if (Array.isArray(value))
f = arrnest(name, value);
f = arrnest(name, value)
else if (value instanceof Set)
f = setnest(name, value);
f = setnest(name, value)
else if (type === 'object')
f = objnest(name, value);
f = objnest(name, value)

return f;
};
return f
}

return data && filterjoin(keys(data).map(key => nest(key, data[key])));
};
return data && filterjoin(keys(data).map(key => nest(key, data[key])))
}
Loading

0 comments on commit be97cd8

Please sign in to comment.