@ossy/router 1.39.7 → 1.40.0
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/build/router.js +1 -1
- package/package.json +2 -2
package/build/router.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{padWithSlash as t}from"./utli.js";class e{static of(t){return new e(t)}constructor({pages:t,defaultLanguage:e,supportedLanguages:a}){this.pages=t||[],this.defaultLanguage=e,this.supportedLanguages=a||[]}getPageById(t){var e;return null!==(e=this.pages.find(e=>e.id===t))&&void 0!==e?e:this.pages.find(t=>"404"===t.id)}getPageByUrl(e){var a;if("string"!=typeof e||0===(null===(a=this.pages)||void 0===a?void 0:a.length))return;let
|
|
1
|
+
import{padWithSlash as t}from"./utli.js";class e{static of(t){return new e(t)}constructor({pages:t,defaultLanguage:e,supportedLanguages:a}){this.pages=t||[],this.defaultLanguage=e,this.supportedLanguages=a||[]}getPageById(t){var e;return null!==(e=this.pages.find(e=>e.id===t))&&void 0!==e?e:this.pages.find(t=>"404"===t.id)}getPageByUrl(e){var a;if("string"!=typeof e||0===(null===(a=this.pages)||void 0===a?void 0:a.length))return;let s;try{s=new URL(e)}catch(t){s=new URL(e,"http://localhost.com")}const i=t(s.pathname),n=i.split("/").filter(t=>!!t),r=this.pages.find(e=>("string"==typeof e.path?[e.path]:Object.entries(e.path).map(([t,e])=>`/${t}${e}`)).map(t).includes(i));if(r)return r;const u=this.pages.find(t=>("string"==typeof t.path?[t.path]:Object.entries(t.path).map(([t,e])=>`/${t}${e}`)).map(t=>t.split("/").filter(t=>!!t).reduce((t,e,a)=>e.startsWith(":")?t+n[a]+"/":t+e+"/","/")).includes(i));if(u)return u;if(this.supportedLanguages.length>1&&this.defaultLanguage&&0===n.length){const e=t(`/${this.defaultLanguage}/`),a=this.pages.find(a=>{if("object"!=typeof a.path||!a.path)return!1;return Object.entries(a.path).map(([e,a])=>t(`/${e}${a}`)).includes(e)});if(a)return a}}getParamsFromUrl(e){var a,s,i;if("string"!=typeof e||0===(null===(a=this.pages)||void 0===a?void 0:a.length))return{};let n;try{n=new URL(e)}catch(t){n=new URL(e,"http://localhost.com")}const r=t(n.pathname).split("/").filter(t=>!!t),u=this.getPageByUrl(e);let g={};if("string"==typeof(null==u?void 0:u.path)){u.path.split("/").filter(t=>!!t).forEach((t,e)=>{t.startsWith(":")&&(g[t.slice(1)]=r[e])})}if("object"==typeof(null==u?void 0:u.path)&&u.path){const t=r[0]||"";let e,a;this.supportedLanguages.length>1&&!!this.defaultLanguage?(e=this.supportedLanguages.includes(t)?t:this.defaultLanguage,a=this.supportedLanguages.includes(t)?r.slice(1):r):t&&void 0!==u.path[t]?(e=t,a=r.slice(1)):(e=this.defaultLanguage||Object.keys(u.path)[0]||"",a=r),g.language=e;(null!==(i=null===(s=u.path[e])||void 0===s?void 0:s.split("/").filter(t=>!!t))&&void 0!==i?i:[]).forEach((t,e)=>{t.startsWith(":")&&(g[t.slice(1)]=a[e])})}else if(this.supportedLanguages.length>1&&this.defaultLanguage){const t=r[0]||"";g.language=this.supportedLanguages.includes(t)?t:this.defaultLanguage}else this.defaultLanguage&&(g.language=this.defaultLanguage);return g}getPathname({id:t,params:e,language:a}){const s=this.getPageById(t);if(!s)return;let i=s.path;if("object"==typeof i){if(!a)throw new Error("[Router][getPathname()] Language is required for multi language router");return e?i[a].split("/").filter(t=>!!t).reduce((t,a)=>{if(a.startsWith(":")){const s=a.replace(":","");return t+"/"+e[s]}return t+"/"+a},`/${a}`):"/"+a+i[a]}return"string"==typeof i?e&&i.includes(":")?i.split("/").filter(t=>!!t).reduce((t,a)=>{if(a.startsWith(":")){const s=a.replace(":","");return t+"/"+e[s]}return t+"/"+a},""):i:void 0}}export{e as Router};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.40.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ossy-se/packages.git"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"access": "public",
|
|
45
45
|
"registry": "https://registry.npmjs.org"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "d9d31182be64a448d575da432af2830d909ad4b9"
|
|
48
48
|
}
|