Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vue-i18n-routing

Package Overview
Dependencies
Maintainers
1
Versions
239
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vue-i18n-routing - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

23

dist/vue-i18n-routing.d.ts

@@ -7,11 +7,12 @@ import type { Composer } from '@intlify/vue-i18n-bridge';

import type { Locale } from '@intlify/vue-i18n-bridge';
import type { RawLocation } from '@intlify/vue-router-bridge';
import { Location as Location_2 } from '@intlify/vue-router-bridge';
import { RawLocation } from '@intlify/vue-router-bridge';
import type { Ref } from 'vue-demi';
import { Route } from '@intlify/vue-router-bridge';
import type { RouteConfig } from '@intlify/vue-router-bridge';
import type { RouteLocation } from '@intlify/vue-router-bridge';
import { RouteLocation } from '@intlify/vue-router-bridge';
import { RouteLocationNormalized } from '@intlify/vue-router-bridge';
import { RouteLocationNormalizedLoaded } from '@intlify/vue-router-bridge';
import type { RouteLocationRaw } from '@intlify/vue-router-bridge';
import type { Router } from '@intlify/vue-router-bridge';
import { RouteLocationRaw } from '@intlify/vue-router-bridge';
import { Router } from '@intlify/vue-router-bridge';
import type { RouterOptions } from '@intlify/vue-router-bridge';

@@ -454,3 +455,5 @@ import type { useRoute } from '@intlify/vue-router-bridge';

*/
export declare function localeLocation(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): Location | RouteLocation | undefined;
export declare function localeLocation(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): Location_2 | (RouteLocation & {
href: string;
}) | undefined;

@@ -646,3 +649,11 @@ /**

export declare function resolveRoute(this: RoutingProxy, route: any, locale?: Locale): any;
export declare function resolveRoute(this: RoutingProxy, route: RawLocation | RouteLocationRaw, locale?: Locale): {
location: Location_2;
route: Route;
href: string;
normalizedTo: Location_2;
resolved: Route;
} | (RouteLocation & {
href: string;
}) | null | undefined;

@@ -649,0 +660,0 @@ export { Route }

@@ -29,2 +29,41 @@ var VueI18nRouting = function(exports, VueRouter3, vueDemi, vueI18nBridge) {

const isObject = (val) => val !== null && typeof val === "object";
const PLUS_RE = /\+/g;
function decode(text = "") {
try {
return decodeURIComponent("" + text);
} catch {
return "" + text;
}
}
function decodeQueryKey(text) {
return decode(text.replace(PLUS_RE, " "));
}
function decodeQueryValue(text) {
return decode(text.replace(PLUS_RE, " "));
}
function parseQuery(parametersString = "") {
const object = {};
if (parametersString[0] === "?") {
parametersString = parametersString.slice(1);
}
for (const parameter of parametersString.split("&")) {
const s = parameter.match(/([^=]+)=?(.*)/) || [];
if (s.length < 2) {
continue;
}
const key = decodeQueryKey(s[1]);
if (key === "__proto__" || key === "constructor") {
continue;
}
const value = decodeQueryValue(s[2] || "");
if (object[key] === void 0) {
object[key] = value;
} else if (Array.isArray(object[key])) {
object[key].push(value);
} else {
object[key] = [object[key], value];
}
}
return object;
}
const TRAILING_SLASH_RE = /\/$|\/\?/;

@@ -57,2 +96,10 @@ function hasTrailingSlash(input = "", queryParameters = false) {

}
function parsePath(input = "") {
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
return {
pathname,
search,
hash
};
}
const inBrowser = typeof window !== "undefined";

@@ -636,35 +683,22 @@ function warn(msg, err) {

}
function resolveBridgeRoute(val) {
return isV4Route() ? val : val.route;
function isV4Router(val) {
return vueDemi.isVue3;
}
function resolvedRouteToObject(route) {
const r = resolveBridgeRoute(route);
const encodedPath = encodeURI(r.path);
const queryString = r.fullPath.indexOf("?") >= 0 ? r.fullPath.substring(r.fullPath.indexOf("?")) : "";
const resolvedObject = {
...r,
fullPath: encodedPath + queryString,
path: encodedPath,
href: encodedPath + queryString
};
return vueDemi.isVue3 ? resolvedObject : { ...route, route: resolvedObject };
}
function resolve(router, route, strategy, locale) {
if (vueDemi.isVue3 && strategy === "prefix") {
if (isArray(route.matched) && route.matched.length > 0) {
return route.matched[0];
}
const [rootSlash, restPath] = split(route.path, 1);
const targetPath = `${rootSlash}${locale}${restPath === "" ? restPath : `/${restPath}`}`;
const _route = router.options.routes.find((r) => r.path === targetPath);
if (_route == null) {
return route;
} else {
const _resolvableRoute = assign({}, route, _route);
_resolvableRoute.path = targetPath;
return router.resolve(_resolvableRoute);
}
} else {
var _a, _b;
if (isV4Router()) {
return router.resolve(route);
}
if (strategy !== "prefix") {
return router.resolve(route);
}
const [rootSlash, restPath] = split(route.path, 1);
const targetPath = `${rootSlash}${locale}${restPath === "" ? restPath : `/${restPath}`}`;
const _route = (_b = (_a = router.options) == null ? void 0 : _a.routes) == null ? void 0 : _b.find((r) => r.path === targetPath);
if (_route == null) {
return router.resolve(route);
}
const _resolvableRoute = assign({}, route, _route);
_resolvableRoute.path = targetPath;
return router.resolve(_resolvableRoute);
}

@@ -690,12 +724,13 @@ const RESOLVED_PREFIXED = /* @__PURE__ */ new Set(["prefix_and_default", "prefix_except_default"]);

function localePath(route, locale) {
var _a;
const localizedRoute = resolveRoute.call(this, route, locale);
return localizedRoute == null ? "" : vueDemi.isVue3 ? localizedRoute.redirectedFrom || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath;
return localizedRoute == null ? "" : isV4Route() ? ((_a = localizedRoute.redirectedFrom) == null ? void 0 : _a.fullPath) || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath;
}
function localeRoute(route, locale) {
const resolved = resolveRoute.call(this, route, locale);
return resolved == null ? void 0 : vueDemi.isVue3 ? resolved : resolved.route;
return resolved == null ? void 0 : isV4Route() ? resolved : resolved.route;
}
function localeLocation(route, locale) {
const resolved = resolveRoute.call(this, route, locale);
return resolved == null ? void 0 : vueDemi.isVue3 ? resolved : resolved.location;
return resolved == null ? void 0 : isV4Route() ? resolved : resolved.location;
}

@@ -707,14 +742,17 @@ function resolveRoute(route, locale) {

const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash, prefixable: prefixable2 } = getI18nRoutingOptions(router, this);
let _route = route;
let _route;
if (isString(route)) {
if (_route[0] === "/") {
const [path, search] = route.split("?");
const query = Object.fromEntries(new URLSearchParams(search));
_route = { path, query };
if (route[0] === "/") {
const { pathname: path, search, hash } = parsePath(route);
const query = parseQuery(search);
_route = { path, query, hash };
} else {
_route = { name: route };
}
} else {
_route = route;
}
let localizedRoute = assign({}, _route);
if (localizedRoute.path && !localizedRoute.name) {
const isRouteLocationPathRaw = (val) => "path" in val && !!val.path && !("name" in val);
if (isRouteLocationPathRaw(localizedRoute)) {
let _resolvedRoute = null;

@@ -749,3 +787,3 @@ try {

} else {
if (!localizedRoute.name && !localizedRoute.path) {
if (!localizedRoute.name && !("path" in localizedRoute)) {
localizedRoute.name = getRouteBaseName.call(this, this.route);

@@ -767,3 +805,3 @@ }

try {
const resolvedRoute = resolvedRouteToObject(router.resolve(localizedRoute));
const resolvedRoute = router.resolve(localizedRoute);
if (isV4Route(resolvedRoute) ? resolvedRoute.name : resolvedRoute.route.name) {

@@ -774,5 +812,6 @@ return resolvedRoute;

} catch (e) {
if (vueDemi.isVue3 && e.type === 1) {
if (vueDemi.isVue2) {
return null;
} else if (vueDemi.isVue2) {
}
if (vueDemi.isVue3 && typeof e === "object" && "type" in e && e.type === 1) {
return null;

@@ -1166,3 +1205,3 @@ }

}
const VERSION = "1.1.2";
const VERSION = "1.1.3";
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;

@@ -1169,0 +1208,0 @@ exports.DEFAULT_DETECTION_DIRECTION = DEFAULT_DETECTION_DIRECTION;

@@ -32,2 +32,41 @@ "use strict";

const isObject = (val) => val !== null && typeof val === "object";
const PLUS_RE = /\+/g;
function decode(text = "") {
try {
return decodeURIComponent("" + text);
} catch {
return "" + text;
}
}
function decodeQueryKey(text) {
return decode(text.replace(PLUS_RE, " "));
}
function decodeQueryValue(text) {
return decode(text.replace(PLUS_RE, " "));
}
function parseQuery(parametersString = "") {
const object = {};
if (parametersString[0] === "?") {
parametersString = parametersString.slice(1);
}
for (const parameter of parametersString.split("&")) {
const s = parameter.match(/([^=]+)=?(.*)/) || [];
if (s.length < 2) {
continue;
}
const key = decodeQueryKey(s[1]);
if (key === "__proto__" || key === "constructor") {
continue;
}
const value = decodeQueryValue(s[2] || "");
if (object[key] === void 0) {
object[key] = value;
} else if (Array.isArray(object[key])) {
object[key].push(value);
} else {
object[key] = [object[key], value];
}
}
return object;
}
const TRAILING_SLASH_RE = /\/$|\/\?/;

@@ -60,2 +99,10 @@ function hasTrailingSlash(input = "", queryParameters = false) {

}
function parsePath(input = "") {
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1);
return {
pathname,
search,
hash
};
}
const inBrowser = typeof window !== "undefined";

@@ -639,35 +686,22 @@ function warn(msg, err) {

}
function resolveBridgeRoute(val) {
return isV4Route() ? val : val.route;
function isV4Router(val) {
return vueDemi.isVue3;
}
function resolvedRouteToObject(route) {
const r = resolveBridgeRoute(route);
const encodedPath = encodeURI(r.path);
const queryString = r.fullPath.indexOf("?") >= 0 ? r.fullPath.substring(r.fullPath.indexOf("?")) : "";
const resolvedObject = {
...r,
fullPath: encodedPath + queryString,
path: encodedPath,
href: encodedPath + queryString
};
return vueDemi.isVue3 ? resolvedObject : { ...route, route: resolvedObject };
}
function resolve(router, route, strategy, locale) {
if (vueDemi.isVue3 && strategy === "prefix") {
if (isArray(route.matched) && route.matched.length > 0) {
return route.matched[0];
}
const [rootSlash, restPath] = split(route.path, 1);
const targetPath = `${rootSlash}${locale}${restPath === "" ? restPath : `/${restPath}`}`;
const _route = router.options.routes.find((r) => r.path === targetPath);
if (_route == null) {
return route;
} else {
const _resolvableRoute = assign({}, route, _route);
_resolvableRoute.path = targetPath;
return router.resolve(_resolvableRoute);
}
} else {
var _a, _b;
if (isV4Router()) {
return router.resolve(route);
}
if (strategy !== "prefix") {
return router.resolve(route);
}
const [rootSlash, restPath] = split(route.path, 1);
const targetPath = `${rootSlash}${locale}${restPath === "" ? restPath : `/${restPath}`}`;
const _route = (_b = (_a = router.options) == null ? void 0 : _a.routes) == null ? void 0 : _b.find((r) => r.path === targetPath);
if (_route == null) {
return router.resolve(route);
}
const _resolvableRoute = assign({}, route, _route);
_resolvableRoute.path = targetPath;
return router.resolve(_resolvableRoute);
}

@@ -693,12 +727,13 @@ const RESOLVED_PREFIXED = /* @__PURE__ */ new Set(["prefix_and_default", "prefix_except_default"]);

function localePath(route, locale) {
var _a;
const localizedRoute = resolveRoute.call(this, route, locale);
return localizedRoute == null ? "" : vueDemi.isVue3 ? localizedRoute.redirectedFrom || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath;
return localizedRoute == null ? "" : isV4Route() ? ((_a = localizedRoute.redirectedFrom) == null ? void 0 : _a.fullPath) || localizedRoute.fullPath : localizedRoute.route.redirectedFrom || localizedRoute.route.fullPath;
}
function localeRoute(route, locale) {
const resolved = resolveRoute.call(this, route, locale);
return resolved == null ? void 0 : vueDemi.isVue3 ? resolved : resolved.route;
return resolved == null ? void 0 : isV4Route() ? resolved : resolved.route;
}
function localeLocation(route, locale) {
const resolved = resolveRoute.call(this, route, locale);
return resolved == null ? void 0 : vueDemi.isVue3 ? resolved : resolved.location;
return resolved == null ? void 0 : isV4Route() ? resolved : resolved.location;
}

@@ -710,14 +745,17 @@ function resolveRoute(route, locale) {

const { routesNameSeparator, defaultLocale, defaultLocaleRouteNameSuffix, strategy, trailingSlash, prefixable: prefixable2 } = getI18nRoutingOptions(router, this);
let _route = route;
let _route;
if (isString(route)) {
if (_route[0] === "/") {
const [path, search] = route.split("?");
const query = Object.fromEntries(new URLSearchParams(search));
_route = { path, query };
if (route[0] === "/") {
const { pathname: path, search, hash } = parsePath(route);
const query = parseQuery(search);
_route = { path, query, hash };
} else {
_route = { name: route };
}
} else {
_route = route;
}
let localizedRoute = assign({}, _route);
if (localizedRoute.path && !localizedRoute.name) {
const isRouteLocationPathRaw = (val) => "path" in val && !!val.path && !("name" in val);
if (isRouteLocationPathRaw(localizedRoute)) {
let _resolvedRoute = null;

@@ -752,3 +790,3 @@ try {

} else {
if (!localizedRoute.name && !localizedRoute.path) {
if (!localizedRoute.name && !("path" in localizedRoute)) {
localizedRoute.name = getRouteBaseName.call(this, this.route);

@@ -770,3 +808,3 @@ }

try {
const resolvedRoute = resolvedRouteToObject(router.resolve(localizedRoute));
const resolvedRoute = router.resolve(localizedRoute);
if (isV4Route(resolvedRoute) ? resolvedRoute.name : resolvedRoute.route.name) {

@@ -777,5 +815,6 @@ return resolvedRoute;

} catch (e) {
if (vueDemi.isVue3 && e.type === 1) {
if (vueDemi.isVue2) {
return null;
} else if (vueDemi.isVue2) {
}
if (vueDemi.isVue3 && typeof e === "object" && "type" in e && e.type === 1) {
return null;

@@ -1169,3 +1208,3 @@ }

}
const VERSION = "1.1.2";
const VERSION = "1.1.3";
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;

@@ -1172,0 +1211,0 @@ exports.DEFAULT_DETECTION_DIRECTION = DEFAULT_DETECTION_DIRECTION;

{
"name": "vue-i18n-routing",
"description": "The i18n routing with using vue-i18n",
"version": "1.1.2",
"version": "1.1.3",
"scripts": {

@@ -6,0 +6,0 @@ "dev": "vite",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc