caring-route 0.0.5 → 1.0.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/dist/index.js +1 -1
- package/package.json +10 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t={},e=!0,r="brackets"){
|
|
1
|
+
function t(t={},e=!0,r="brackets"){const a=e?"?":"",o=[];-1==["indices","brackets","repeat","comma"].indexOf(r)&&(r="brackets");for(const e in t){const a=t[e];if(!(["",void 0,null].indexOf(a)>=0))if(a.constructor===Array)switch(r){case"indices":for(let t=0;t<a.length;t++)o.push(`${e}[${t}]=${a[t]}`);break;case"brackets":default:a.forEach((t=>{o.push(`${e}[]=${t}`)}));break;case"repeat":a.forEach((t=>{o.push(`${e}=${t}`)}));break;case"comma":let t="";a.forEach((e=>{t+=(t?",":"")+e})),o.push(`${e}=${t}`)}else o.push(`${e}=${a}`)}return o.length?a+o.join("&"):""}const e=["navigateTo","redirectTo","reLaunch"];function r(t){const{routeUrl:e,routeType:r="navigateTo",delta:a=1,events:o}=t;return new Promise(((t,n)=>{uni[r]({url:e,delta:a,events:o,success:e=>t(e),fail:t=>n(t)})}))}class a{handleParams(t={}){const e={};for(let r in t)"object"==typeof t[r]&&(e[r]=encodeURIComponent(JSON.stringify(t[r]))),"string"==typeof t[r]&&t[r].includes("http")&&(t[r]=encodeURIComponent(t[r]));return Object.assign(t,e)}query(t){const e={};for(const r in t)if("object"!=typeof t[r]){const a=decodeURIComponent(t[r]);(a.startsWith("{")||a.startsWith("["))&&"string"==typeof a&&(e[r]=JSON.parse(a))}return Object.assign(t,e)}navigate(t,e){return!!t&&("string"==typeof t?(e||(e={}),e.routeUrl=this.mixinParam(t,e),r(e)):(a=t,"[object Object]"===Object.prototype.toString.call(a)?((e=t).routeUrl=t.url,e.routeType=t.type||"navigateTo",Reflect.deleteProperty(e,"url"),Reflect.deleteProperty(e,"type"),e.routeUrl=this.mixinParam(e.routeUrl,e.params),r(e)):void 0));var a}mixinParam(e,r){e=e&&this.addRootPath(e);let a="";return/.*\/.*\?.*=.*/.test(e)?(a=t(this.handleParams(r),!1),e+"&"+a):(a=t(this.handleParams(r)),e+a)}to(t,e){const r={routeType:"navigateTo",routeUrl:t,params:e};this._navigateMethod(r)}back(t){const e={routeType:"navigateBack",delta:t};this._navigateMethod(e)}tab(t){const e={routeType:"switchTab",routeUrl:t};this._navigateMethod(e)}direct(t,e){const r={routeType:"redirectTo",routeUrl:t,params:e};this._navigateMethod(r)}launch(t,e){const r={routeType:"reLaunch",routeUrl:t,params:e};this._navigateMethod(r)}_navigateMethod(t){return e.includes(t.routeType)?t.routeUrl=this.mixinParam(t.routeUrl,t.params):t.routeUrl=t.routeUrl&&this.addRootPath(t.routeUrl),r(t)}addRootPath(t){return"/"===t[0]?t:`/${t}`}}var o=function(){const t=new a,e=a.prototype.navigate.bind(t);return Object.setPrototypeOf(e,t),e}();export{o as default};
|
package/package.json
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "caring-route",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "适用于uni-app的路由跳转库",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
11
10
|
"build": "rollup -c"
|
|
12
11
|
},
|
|
13
12
|
"type": "module",
|
|
14
13
|
"keywords": [],
|
|
15
14
|
"author": "风度万人迷",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Fascinating-W/caring-route"
|
|
18
|
+
},
|
|
16
19
|
"license": "ISC",
|
|
17
20
|
"devDependencies": {
|
|
21
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
18
22
|
"@rollup/plugin-terser": "^0.4.1",
|
|
19
23
|
"rollup": "^3.21.5"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"caring-utils": "^0.0.1"
|
|
20
27
|
}
|
|
21
28
|
}
|