Skip to content

Commit a880513

Browse files
committed
Make positional argument shifting more robust
1 parent c7be495 commit a880513

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,14 @@ export default (opts = {}) => {
101101
if (api && typeof api === 'object') return setOpts(api)
102102

103103
return new Promise((resolve, reject) => {
104-
if (!Number.isInteger(id) && typeof id !== 'string') {
105-
contextData = jwt
106-
jwt = body
107-
body = id
108-
id = null
104+
const idWellFormed = Number.isFinite(+id) || typeof id === 'string'
105+
106+
if (!idWellFormed) {
107+
if (jwt) contextData = jwt
108+
if (typeof body === 'string') jwt = body
109+
if (typeof id === 'object') body = id
110+
111+
id = undefined
109112
}
110113

111114
const handleError = (e) => {
@@ -120,7 +123,8 @@ export default (opts = {}) => {
120123
}
121124

122125
if (typeof body !== 'object') {
123-
jwt = body
126+
if (jwt) contextData = jwt
127+
if (typeof body === 'string') jwt = body
124128
body = undefined
125129
}
126130

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "get-scrud",
3-
"version": "2.0.0-beta.1",
3+
"version": "2.0.0-beta.2",
44
"description": "Client for SCRUD style rest APIs",
55
"main": "index.js",
66
"type": "module",

0 commit comments

Comments
 (0)