vue-i18n-routing
Advanced tools
Comparing version 0.0.0-ca50166 to 0.0.0-d4abcf5
@@ -1,5 +0,130 @@ | ||
const VueI18nRouting = { | ||
routes: [] | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __propIsEnum = Object.prototype.propertyIsEnumerable; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __spreadValues = (a, b) => { | ||
for (var prop in b || (b = {})) | ||
if (__hasOwnProp.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
if (__getOwnPropSymbols) | ||
for (var prop of __getOwnPropSymbols(b)) { | ||
if (__propIsEnum.call(b, prop)) | ||
__defNormalProp(a, prop, b[prop]); | ||
} | ||
return a; | ||
}; | ||
console.log("this is vue-i18n-rouging!"); | ||
export { VueI18nRouting }; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
import { isVue2 } from "vue-demi"; | ||
const VUE_I18N_ROUTING_DEFAULTS = { | ||
defaultLocale: "en-US", | ||
trailingSlash: false, | ||
routesNameSeparator: "___", | ||
defaultLocaleRouteNameSuffix: "default" | ||
}; | ||
function adjustRoutePathForTrailingSlash(pagePath, trailingSlash, isChildWithRelativePath) { | ||
return pagePath.replace(/\/+$/, "") + (trailingSlash ? "/" : "") || (isChildWithRelativePath ? "" : "/"); | ||
} | ||
function localizeRoutes(routes, { | ||
defaultLocale = VUE_I18N_ROUTING_DEFAULTS.defaultLocale, | ||
trailingSlash = VUE_I18N_ROUTING_DEFAULTS.trailingSlash, | ||
routesNameSeparator = VUE_I18N_ROUTING_DEFAULTS.routesNameSeparator, | ||
defaultLocaleRouteNameSuffix = VUE_I18N_ROUTING_DEFAULTS.defaultLocaleRouteNameSuffix, | ||
localeCodes = [] | ||
} = {}) { | ||
function makeLocalizedRoutes(route, allowedLocaleCodes, isChild = false, isExtraPageTree = false) { | ||
if (route.redirect && (!route.component || !route.file)) { | ||
return [route]; | ||
} | ||
const targetLocales = allowedLocaleCodes; | ||
return targetLocales.reduce((_routes, locale) => { | ||
const { name } = route; | ||
let { path } = route; | ||
const localizedRoute = __spreadValues({}, route); | ||
if (name) { | ||
localizedRoute.name = `${name}${routesNameSeparator}${locale}`; | ||
} | ||
if (route.children) { | ||
localizedRoute.children = route.children.reduce((children, child) => [...children, ...makeLocalizedRoutes(child, [locale], true, isExtraPageTree)], []); | ||
} | ||
const isDefaultLocale = locale === defaultLocale; | ||
if (isDefaultLocale) { | ||
if (!isChild) { | ||
const defaultRoute = __spreadProps(__spreadValues({}, localizedRoute), { path }); | ||
if (name) { | ||
defaultRoute.name = `${localizedRoute.name}${routesNameSeparator}${defaultLocaleRouteNameSuffix}`; | ||
} | ||
if (route.children) { | ||
defaultRoute.children = []; | ||
for (const childRoute of route.children) { | ||
defaultRoute.children = defaultRoute.children.concat(makeLocalizedRoutes(childRoute, [locale], true, true)); | ||
} | ||
} | ||
_routes.push(defaultRoute); | ||
} else if (isChild && isExtraPageTree && name) { | ||
localizedRoute.name += `${routesNameSeparator}${defaultLocaleRouteNameSuffix}`; | ||
} | ||
} | ||
const isChildWithRelativePath = isChild && !path.startsWith("/"); | ||
const shouldAddPrefix = !isChildWithRelativePath && !isDefaultLocale; | ||
if (shouldAddPrefix) { | ||
path = `/${locale}${path}`; | ||
} | ||
if (path) { | ||
path = adjustRoutePathForTrailingSlash(path, trailingSlash, isChildWithRelativePath); | ||
} | ||
localizedRoute.path = path; | ||
_routes.push(localizedRoute); | ||
return _routes; | ||
}, []); | ||
} | ||
return routes.reduce((localized, route) => [...localized, ...makeLocalizedRoutes(route, localeCodes || [])], []); | ||
} | ||
const VueI18nRoutingPlugin = function(vueApp, { | ||
router, | ||
i18n, | ||
defaultLocale = VUE_I18N_ROUTING_DEFAULTS.defaultLocale, | ||
trailingSlash = VUE_I18N_ROUTING_DEFAULTS.trailingSlash, | ||
routesNameSeparator = VUE_I18N_ROUTING_DEFAULTS.routesNameSeparator, | ||
defaultLocaleRouteNameSuffix = VUE_I18N_ROUTING_DEFAULTS.defaultLocaleRouteNameSuffix, | ||
localeCodes = [] | ||
} = {}) { | ||
if (router == null) { | ||
throw new Error("TODO"); | ||
} | ||
if (isVue2) { | ||
const _router = router; | ||
const VueRouter = _router.constructor; | ||
const routes = _router.options.routes || []; | ||
const localizedRoutes = localizeRoutes(routes, { | ||
localeCodes, | ||
defaultLocale, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
const newRouter = new VueRouter({ mode: "history", routes: [] }); | ||
_router.matcher = newRouter.matcher; | ||
localizedRoutes.forEach((route) => { | ||
_router.addRoute(route); | ||
}); | ||
} else { | ||
const _router = router; | ||
const routes = _router.options.routes || []; | ||
const localizedRoutes = localizeRoutes(routes, { | ||
localeCodes, | ||
defaultLocale, | ||
trailingSlash, | ||
routesNameSeparator, | ||
defaultLocaleRouteNameSuffix | ||
}); | ||
console.log("vue3 routes", routes, localizedRoutes); | ||
routes.forEach((r) => _router.removeRoute(r.name)); | ||
localizedRoutes.forEach((route) => _router.addRoute(route)); | ||
} | ||
console.log("install vue-i18n-rouging!", router, i18n, defaultLocale, trailingSlash, routesNameSeparator, defaultLocaleRouteNameSuffix, localeCodes); | ||
}; | ||
const VERSION = "0.0.0"; | ||
export { VERSION, VueI18nRoutingPlugin, localizeRoutes }; |
{ | ||
"name": "vue-i18n-routing", | ||
"description": "The i18n routing with using vue-i18n", | ||
"version": "0.0.0-ca50166", | ||
"version": "0.0.0-d4abcf5", | ||
"dependencies": { | ||
"vue": "next", | ||
"vue-router": "next" | ||
"vue-demi": "*" | ||
}, | ||
"devDependencies": { | ||
"@vitejs/plugin-vue": "^1.9.3", | ||
"vite": "^2.6.4" | ||
"vite": "^2.6.4", | ||
"vite-plugin-dts": "^0.9.6", | ||
"vue": "^3.2.23", | ||
"vue-router": "^4.0.12", | ||
"vue2": "npm:vue@2", | ||
"vue-router3": "npm:vue-router@latest", | ||
"rimraf": "^3.0.2", | ||
"@microsoft/api-extractor": "^7.18.20", | ||
"api-docs-gen": "^0.4.0" | ||
}, | ||
"peerDependencies": { | ||
"@vue/composition-api": "^1.4.0", | ||
"vue": "^2.6.14 || ^3.2.0", | ||
"vue-router": "^3.5.3 || ^4.0.0" | ||
}, | ||
"peerDependenciesMeta": { | ||
"@vue/composition-api": { | ||
"optional": true | ||
} | ||
}, | ||
"keywords": [ | ||
@@ -20,10 +36,19 @@ "i18n", | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"index.mjs", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"main": "./dist/vue-i18n-routing.umd.js", | ||
"main": "./dist/vue-i18n-routing.cjs.js", | ||
"module": "./dist/vue-i18n-routing.es.js", | ||
"unpkg": "dist/vue-i18n-routing.iife.js", | ||
"jsdelivr": "dist/vue-i18n-routing.iife.js", | ||
"types": "dist/vue-i18n-routing.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/vue-i18n-routing.es.js", | ||
"require": "./dist/vue-i18n-routing.umd.js" | ||
"import": { | ||
"node": "./index.mjs", | ||
"default": "./dist/vue-i18n-routing.es.js" | ||
}, | ||
"require": "./dist/vue-i18n-routing.cjs.js" | ||
} | ||
@@ -54,4 +79,6 @@ }, | ||
"dev": "vite", | ||
"build": "vite build" | ||
"build": "vite build", | ||
"typecheck": "tsc -p . --noEmit", | ||
"build:docs": "api-docs-gen ./temp/vue-i18n-routing.api.json -c ./docsgen.config.js -o ./ -g noprefix" | ||
} | ||
} |
@@ -7,4 +7,8 @@ # vue-i18n-routing | ||
## 🤝 API | ||
About details, See the [API References]('./api.md) | ||
## ©️ License | ||
[MIT](http://opensource.org/licenses/MIT) |
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
15534
8
207
13
4
9
2
1
+ Addedvue-demi@*
+ Added@vue/composition-api@1.7.2(transitive)
+ Addedvue@2.6.14(transitive)
+ Addedvue-demi@0.14.10(transitive)
+ Addedvue-router@4.5.0(transitive)
- Removedvue@next
- Removedvue-router@next
- Removedvue-router@4.0.13(transitive)