Skip to content

Commit

Permalink
fix: spliceUrlParam remove encodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
saqqdy committed Aug 9, 2024
1 parent e7cdd1b commit f2fc704
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change logs

## 2024.08.09 v5.20.0

1. `spliceUrlParam` Breaking change: remove encodeURIComponent

## 2024.05.30 v5.19.2

1. upgrade `await-to-done`, fix types
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1533,6 +1533,8 @@ declare function parseUrlParam(url: string, covert?: boolean): Record<string, un

Splice URL parameters (single layer only)

> v5.20.0 Breaking change: remove encodeURIComponent

- Since: `5.3.0`

- Arguments:
Expand All @@ -1548,8 +1550,8 @@ Splice URL parameters (single layer only)
- Example:

```ts
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined', key4: '测试' })
// ?key1=100&key2=true&key3=null&key4=undefined&key5=%E6%B5%8B%E8%AF%95
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined', key5: '测试' })
// ?key1=100&key2=true&key3=null&key4=undefined&key5=测试
spliceUrlParam({ key1: '100', key2: 'true', key3: 'null', key4: 'undefined' }, true)
// ?key1=100&key2=true&key3=&key4=
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-cool",
"description": "Collection of common JavaScript / TypeScript utilities",
"version": "5.19.2",
"version": "5.20.0",
"packageManager": "[email protected]",
"main": "dist/index.cjs.js",
"module": "dist/index.esm-bundler.js",
Expand Down
8 changes: 3 additions & 5 deletions src/spliceUrlParam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* @example
* ```js
* spliceUrlParam('\{"key1":"100","key2":"true","key3":"null","key4":"undefined","key4":"测试"\}')
* // ?key1=100&key2=true&key3=null&key4=undefined&key5=%E6%B5%8B%E8%AF%95
* spliceUrlParam('\{"key1":"100","key2":"true","key3":"null","key4":"undefined","key5":"测试"\}')
* // ?key1=100&key2=true&key3=null&key4=undefined&key5=测试
*
* spliceUrlParam('\{"key1":"100","key2":"true","key3":"null","key4":"undefined"\}', true)
* // ?key1=100&key2=true&key3=&key4=
Expand Down Expand Up @@ -32,9 +32,7 @@ function spliceUrlParam<T extends Record<string, unknown>>(
const result: string[] = []
for (key in params) {
typeof key === 'string' &&
result.push(
`${key}=${encodeURIComponent('' + (covert ? params[key] ?? '' : params[key]))}`
)
result.push(`${key}=${'' + (covert ? params[key] ?? '' : params[key])}`)
}

if (withQuestionsMark) return '?' + result.join('&')
Expand Down

0 comments on commit f2fc704

Please sign in to comment.