@templmf/temp-solf-lmf 0.0.111 → 0.0.112

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/test.js +26 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@templmf/temp-solf-lmf",
3
- "version": "0.0.111",
3
+ "version": "0.0.112",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/test.js ADDED
@@ -0,0 +1,26 @@
1
+ function appendParam(url, key, value) {
2
+ const encoded = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`
3
+
4
+ const hashIndex = url.indexOf('#')
5
+
6
+ // 没有 hash
7
+ if (hashIndex === -1) {
8
+ return url + (url.includes('?') ? '&' : '?') + encoded
9
+ }
10
+
11
+ const beforeHash = url.slice(0, hashIndex)
12
+ const afterHash = url.slice(hashIndex + 1)
13
+
14
+ // # 后已经有 query
15
+ if (afterHash.includes('?')) {
16
+ return `${beforeHash}#${afterHash}&${encoded}`
17
+ }
18
+
19
+ // # 前已经有 query
20
+ if (beforeHash.includes('?')) {
21
+ return `${beforeHash}&${encoded}#${afterHash}`
22
+ }
23
+
24
+ // 默认拼到 hash 后
25
+ return `${beforeHash}#${afterHash}?${encoded}`
26
+ }