@sjcrh/proteinpaint-shared 2.99.0 → 2.99.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/doc.js +4 -8
- package/src/joinUrl.js +7 -0
- package/src/urljson.js +28 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjcrh/proteinpaint-shared",
|
|
3
|
-
"version": "2.99.
|
|
3
|
+
"version": "2.99.1",
|
|
4
4
|
"description": "ProteinPaint code that is shared between server and client-side workspaces",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"./*": "./src/*"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "esbuild src/*.ts --platform=node --outdir=src/ --format=esm",
|
|
12
|
+
"build": "esbuild src/*.ts --platform=node --outdir=src/ --format=esm && prettier --no-semi --use-tabs --write src/urljson.js src/joinUrl.js src/doc.js",
|
|
13
13
|
"prepack": "npm run build",
|
|
14
14
|
"test": "ls src/test/*.spec* | xargs node"
|
|
15
15
|
},
|
package/src/doc.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
const test = {}
|
|
1
|
+
const test = {}
|
|
2
2
|
function doc(opts) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
test[opts.type] = opts.test;
|
|
3
|
+
if (opts.type in test) throw `test['${opts.type}'] already exists`
|
|
4
|
+
test[opts.type] = opts.test
|
|
6
5
|
}
|
|
7
|
-
export {
|
|
8
|
-
doc,
|
|
9
|
-
test
|
|
10
|
-
};
|
|
6
|
+
export { doc, test }
|
package/src/joinUrl.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function joinUrl(p1, p2) {
|
|
2
|
+
if (typeof p1 != 'string' || typeof p2 != 'string') throw `both arguments must be string type`
|
|
3
|
+
if (!p1 || !p2) throw 'blank string not allowed'
|
|
4
|
+
if (p1.indexOf('?') != -1) throw 'search string not allowed'
|
|
5
|
+
return (p1.endsWith('/') ? p1 : p1 + '/') + (p2.startsWith('/') ? p2.substring(1) : p2)
|
|
6
|
+
}
|
|
7
|
+
export { joinUrl }
|
package/src/urljson.js
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
|
-
import { isNumeric } from
|
|
2
|
-
const reserved = [
|
|
3
|
-
const delimiters = ['"',
|
|
1
|
+
import { isNumeric } from './helpers.js'
|
|
2
|
+
const reserved = ['false', 'true', 'null', 'undefined']
|
|
3
|
+
const delimiters = ['"', '{', '[']
|
|
4
4
|
function encode(rawObject) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
const params = []
|
|
6
|
+
for (const [key, value] of Object.entries(rawObject)) {
|
|
7
|
+
if (typeof value == 'string' && !isNumeric(value) && !reserved.includes(value) && !delimiters.includes(value[0])) {
|
|
8
|
+
params.push(`${key}=${encodeURIComponent(value)}`)
|
|
9
|
+
} else if (value !== void 0) {
|
|
10
|
+
params.push(`${key}=${encodeURIComponent(JSON.stringify(value))}`)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return params.join('&')
|
|
14
14
|
}
|
|
15
15
|
function decode(query) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const encoding = query.encoding
|
|
17
|
+
for (const [key, value] of Object.entries(query)) {
|
|
18
|
+
if (
|
|
19
|
+
encoding == 'json' ||
|
|
20
|
+
value == 'null' || // not new, always been
|
|
21
|
+
value == 'true' || // NEED TO FIND-REPLACE CODE THAT USES value == 'true'
|
|
22
|
+
value == 'false' || // NEED TO FIND-REPLACE CODE THAT USES value == 'false'
|
|
23
|
+
isNumeric(value) || // NEED TO check
|
|
24
|
+
(value.startsWith('"') && value.endsWith('"')) ||
|
|
25
|
+
(value.startsWith('{') && value.endsWith('}')) ||
|
|
26
|
+
(value.startsWith('[') && value.endsWith(']'))
|
|
27
|
+
)
|
|
28
|
+
query[key] = JSON.parse(value)
|
|
29
|
+
}
|
|
30
|
+
return query
|
|
26
31
|
}
|
|
27
|
-
export {
|
|
28
|
-
decode,
|
|
29
|
-
encode
|
|
30
|
-
};
|
|
32
|
+
export { decode, encode }
|