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

@intlify/vue-router-bridge

Package Overview
Dependencies
Maintainers
2
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@intlify/vue-router-bridge - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0-c9b0866

161

lib/index.d.ts

@@ -1,9 +0,166 @@

import type { RouteLocationNormalizedLoaded, Router } from 'vue-router'
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { RouteLocationNormalizedLoaded, Router, RouteRecord, RouteMeta, NavigationGuard } from 'vue-router'
/**
* shim vue-router@3 typings
*/
// Stub VueRouter class interfaces
declare type VueRouter = {
app: Vue
options: RouterOptions
mode: RouterMode
currentRoute: Route
beforeEach(guard: NavigationGuard): Function
beforeResolve(guard: NavigationGuard): Function
afterEach(hook: (to: Route, from: Route) => any): Function
push(location: RawLocation): Promise<Route>
push(location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void
replace(location: RawLocation): Promise<Route>
replace(location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void
go(n: number): void
back(): void
forward(): void
match(raw: RawLocation, current?: Route, redirectedFrom?: Location): Route
getMatchedComponents(to?: RawLocation | Route): Component[]
onReady(cb: Function, errorCb?: ErrorHandler): void
onError(cb: ErrorHandler): void
addRoutes(routes: RouteConfig[]): void
AddRoute(parent: string, route: RouteConfig): void
AddRoute(route: RouteConfig): void
resolve(
to: RawLocation,
current?: Route,
append?: boolean
): {
location: Location
route: Route
href: string
normalizedTo: Location
resolved: Route
}
}
declare type ErrorHandler = (err: Error) => void
declare type RouterMode = 'hash' | 'history' | 'abstract'
declare type Dictionary<T> = { [key: string]: T }
declare interface Location {
name?: string
path?: string
hash?: string
query?: Dictionary<string | (string | null)[] | null | undefined>
params?: Dictionary<string>
append?: boolean
replace?: boolean
}
declare type RawLocation = string | Location
declare interface Route {
path: string
name?: string | null
hash: string
query: Dictionary<string | (string | null)[]>
params: Dictionary<string>
fullPath: string
matched: RouteRecord[]
redirectedFrom?: string
meta?: RouteMeta
}
declare type RedirectOption = RawLocation | ((to: Route) => RawLocation)
declare interface PathToRegexpOptions {
sensitive?: boolean
strict?: boolean
end?: boolean
}
declare type Vue = any // emulate Vue (v2)
declare type Component = any // emulate Vue Component (v2)
declare type Position = { x: number; y: number }
declare type PositionResult = Position | { selector: string; offset?: Position; behavior?: ScrollBehavior } | void
declare interface RouterOptions {
routes?: RouteConfig[]
mode?: RouterMode
fallback?: boolean
base?: string
linkActiveClass?: string
linkExactActiveClass?: string
parseQuery?: (query: string) => Record<string, any>
stringifyQuery?: (query: Record<string, any>) => string
scrollBehavior?: (
to: Route,
from: Route,
savedPosition: Position | void
) => PositionResult | Promise<PositionResult> | undefined | null
}
declare type RoutePropsFunction = (route: Route) => Record<string, anu>
declare interface _RouteConfigBase {
path: string
name?: string
children?: RouteConfig[]
redirect?: RedirectOption
alias?: string | string[]
meta?: RouteMeta
beforeEnter?: NavigationGuard
caseSensitive?: boolean
pathToRegexpOptions?: PathToRegexpOptions
}
declare interface RouteConfigSingleView extends _RouteConfigBase {
component?: Component
props?: boolean | Rect | RoutePropsFunction
}
declare interface RouteConfigMultipleViews extends _RouteConfigBase {
components?: Dictionary<Component>
props?: Dictionary<boolean | Record<string, any> | RoutePropsFunction>
}
declare type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews
declare interface RouteRecordPublic {
path: string
components: Dictionary<Component>
instances: Dictionary<Vue>
name?: string
redirect?: RedirectOption
meta: any
beforeEnter?: (route: Route, redirect: (location: RawLocation) => void, next: () => void) => any
props:
| boolean
| Record<string, any>
| RoutePropsFunction
| Dictionary<boolean | Record<string, any> | RoutePropsFunction>
}
/**
* Returns the router instance. Equivalent to using `$router` inside templates.
*/
declare function useRouter<T = Router>(): T
/**
* Returns the current route location. Equivalent to using `$route` inside templates.
*/
declare function useRoute<T = RouteLocationNormalizedLoaded>(): T
/**
* Wheter the current vue-router version is 3
*/
declare const isVueRouter3: boolean
/**
* Wheter the current vue-router version is 4
*/
declare const isVueRouter4: boolean
export { useRouter, useRoute, isVueRouter3, isVueRouter4 }
// export vue-router@4 typings
export * from 'vue-router'
export {
useRouter,
useRoute,
isVueRouter3,
isVueRouter4,
RouterMode,
RawLocation,
RedirectOption,
RouteConfig,
RouteRecordPublic,
Location,
Route
}
// export dummy VueRouter class
export default VueRouter
/* eslint-enable @typescript-eslint/no-explicit-any */

@@ -0,12 +1,112 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
import VueRouter from 'vue-router'
import type { ComputedRef } from '@vue/composition-api'
import type { Route } from 'vue-router'
import type { Route, RouterOptions } from 'vue-router'
/**
* shim vue-router@4 typings
*/
declare type Router = any
declare type RouterHistory = any
declare type RouteRecordRaw = any
declare type PathParserOptions = any
declare type RouterMatcher = any
/**
* Creates a Router instance that can be used by a Vue app.
*
* @param options - {@link RouterOptions}
*/
declare function createRouter(options: RouterOptions): Router
/**
* Creates a in-memory based history. The main purpose of this history is to handle SSR. It starts in a special location that is nowhere.
* It's up to the user to replace that location with the starter location by either calling `router.push` or `router.replace`.
*
* @param base - Base applied to all urls, defaults to '/'
* @returns a history object that can be passed to the router constructor
*/
declare function createMemoryHistory(base?: string): RouterHistory
/**
* Creates a Router Matcher.
*
* @internal
* @param routes - array of initial routes
* @param globalOptions - global route options
*/
declare function createRouterMatcher(routes: RouteRecordRaw[], globalOptions: PathParserOptions): RouterMatcher
/**
* Creates a hash history. Useful for web applications with no host (e.g.
* `file://`) or when configuring a server to handle any URL is not possible.
*
* @param base - optional base to provide. Defaults to `location.pathname +
* location.search` If there is a `<base>` tag in the `head`, its value will be
* ignored in favor of this parameter **but note it affects all the
* history.pushState() calls**, meaning that if you use a `<base>` tag, it's
* `href` value **has to match this parameter** (ignoring anything after the
* `#`).
*
* @example
* ```js
* // at https://example.com/folder
* createWebHashHistory() // gives a url of `https://example.com/folder#`
* createWebHashHistory('/folder/') // gives a url of `https://example.com/folder/#`
* // if the `#` is provided in the base, it won't be added by `createWebHashHistory`
* createWebHashHistory('/folder/#/app/') // gives a url of `https://example.com/folder/#/app/`
* // you should avoid doing this because it changes the original url and breaks copying urls
* createWebHashHistory('/other-folder/') // gives a url of `https://example.com/other-folder/#`
*
* // at file:///usr/etc/folder/index.html
* // for locations with no `host`, the base is ignored
* createWebHashHistory('/iAmIgnored') // gives a url of `file:///usr/etc/folder/index.html#`
* ```
*/
declare function createWebHashHistory(base?: string): RouterHistory
/**
* Creates an HTML5 history. Most common history for single page applications.
*
* @param base -
*/
declare function createWebHistory(base?: string): RouterHistory
/**
* Returns the router instance. Equivalent to using `$router` inside templates.
*/
declare function useRouter<T = VueRouter>(): T
/**
* Returns the current route location. Equivalent to using `$route` inside templates.
*/
declare function useRoute<T = ComputedRef<Route>>(): T
/**
* Wheter the current vue-router version is 3
*/
declare const isVueRouter3: boolean
/**
* Wheter the current vue-router version is 4
*/
declare const isVueRouter4: boolean
export { useRouter, useRoute, isVueRouter3, isVueRouter4 }
// export vue-router@4 typings
export * from 'vue-router'
export {
useRouter,
useRoute,
isVueRouter3,
isVueRouter4,
createRouter,
createMemoryHistory,
createRouterMatcher,
createWebHashHistory,
createWebHistory
}
export default VueRouter
/* eslint-enable @typescript-eslint/no-explicit-any */

@@ -1,9 +0,166 @@

import type { RouteLocationNormalizedLoaded, Router } from 'vue-router'
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { RouteLocationNormalizedLoaded, Router, RouteRecord, RouteMeta, NavigationGuard } from 'vue-router'
/**
* shim vue-router@3 typings
*/
// Stub VueRouter class interfaces
declare type VueRouter = {
app: Vue
options: RouterOptions
mode: RouterMode
currentRoute: Route
beforeEach(guard: NavigationGuard): Function
beforeResolve(guard: NavigationGuard): Function
afterEach(hook: (to: Route, from: Route) => any): Function
push(location: RawLocation): Promise<Route>
push(location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void
replace(location: RawLocation): Promise<Route>
replace(location: RawLocation, onComplete?: Function, onAbort?: ErrorHandler): void
go(n: number): void
back(): void
forward(): void
match(raw: RawLocation, current?: Route, redirectedFrom?: Location): Route
getMatchedComponents(to?: RawLocation | Route): Component[]
onReady(cb: Function, errorCb?: ErrorHandler): void
onError(cb: ErrorHandler): void
addRoutes(routes: RouteConfig[]): void
AddRoute(parent: string, route: RouteConfig): void
AddRoute(route: RouteConfig): void
resolve(
to: RawLocation,
current?: Route,
append?: boolean
): {
location: Location
route: Route
href: string
normalizedTo: Location
resolved: Route
}
}
declare type ErrorHandler = (err: Error) => void
declare type RouterMode = 'hash' | 'history' | 'abstract'
declare type Dictionary<T> = { [key: string]: T }
declare interface Location {
name?: string
path?: string
hash?: string
query?: Dictionary<string | (string | null)[] | null | undefined>
params?: Dictionary<string>
append?: boolean
replace?: boolean
}
declare type RawLocation = string | Location
declare interface Route {
path: string
name?: string | null
hash: string
query: Dictionary<string | (string | null)[]>
params: Dictionary<string>
fullPath: string
matched: RouteRecord[]
redirectedFrom?: string
meta?: RouteMeta
}
declare type RedirectOption = RawLocation | ((to: Route) => RawLocation)
declare interface PathToRegexpOptions {
sensitive?: boolean
strict?: boolean
end?: boolean
}
declare type Vue = any // emulate Vue (v2)
declare type Component = any // emulate Vue Component (v2)
declare type Position = { x: number; y: number }
declare type PositionResult = Position | { selector: string; offset?: Position; behavior?: ScrollBehavior } | void
declare interface RouterOptions {
routes?: RouteConfig[]
mode?: RouterMode
fallback?: boolean
base?: string
linkActiveClass?: string
linkExactActiveClass?: string
parseQuery?: (query: string) => Record<string, any>
stringifyQuery?: (query: Record<string, any>) => string
scrollBehavior?: (
to: Route,
from: Route,
savedPosition: Position | void
) => PositionResult | Promise<PositionResult> | undefined | null
}
declare type RoutePropsFunction = (route: Route) => Record<string, anu>
declare interface _RouteConfigBase {
path: string
name?: string
children?: RouteConfig[]
redirect?: RedirectOption
alias?: string | string[]
meta?: RouteMeta
beforeEnter?: NavigationGuard
caseSensitive?: boolean
pathToRegexpOptions?: PathToRegexpOptions
}
declare interface RouteConfigSingleView extends _RouteConfigBase {
component?: Component
props?: boolean | Rect | RoutePropsFunction
}
declare interface RouteConfigMultipleViews extends _RouteConfigBase {
components?: Dictionary<Component>
props?: Dictionary<boolean | Record<string, any> | RoutePropsFunction>
}
declare type RouteConfig = RouteConfigSingleView | RouteConfigMultipleViews
declare interface RouteRecordPublic {
path: string
components: Dictionary<Component>
instances: Dictionary<Vue>
name?: string
redirect?: RedirectOption
meta: any
beforeEnter?: (route: Route, redirect: (location: RawLocation) => void, next: () => void) => any
props:
| boolean
| Record<string, any>
| RoutePropsFunction
| Dictionary<boolean | Record<string, any> | RoutePropsFunction>
}
/**
* Returns the router instance. Equivalent to using `$router` inside templates.
*/
declare function useRouter<T = Router>(): T
/**
* Returns the current route location. Equivalent to using `$route` inside templates.
*/
declare function useRoute<T = RouteLocationNormalizedLoaded>(): T
/**
* Wheter the current vue-router version is 3
*/
declare const isVueRouter3: boolean
/**
* Wheter the current vue-router version is 4
*/
declare const isVueRouter4: boolean
export { useRouter, useRoute, isVueRouter3, isVueRouter4 }
// export vue-router@4 typings
export * from 'vue-router'
export {
useRouter,
useRoute,
isVueRouter3,
isVueRouter4,
RouterMode,
RawLocation,
RedirectOption,
RouteConfig,
RouteRecordPublic,
Location,
Route
}
// export dummy VueRouter class
export default VueRouter
/* eslint-enable @typescript-eslint/no-explicit-any */

10

package.json
{
"name": "@intlify/vue-router-bridge",
"version": "0.1.0",
"version": "0.2.0-c9b0866",
"description": "Vue Router bridging for Vue 2 & Vue 3",
"scripts": {
"postinstall": "node ./scripts/postinstall.js"
},
"peerDependencies": {

@@ -67,3 +64,6 @@ "@vue/composition-api": "^1.0.0-rc.1",

"access": "public"
},
"scripts": {
"postinstall": "node ./scripts/postinstall.js"
}
}
}

@@ -11,2 +11,4 @@ # @intlify/vue-router-bridge

- `useRoute`
- Stubbed Vue Router 4 APIs on Vue Router 3
- About details [here](https://github.com/intlify/bridging/blob/63b1fb5dab4be772f4f564f023e9028979d37196/packages/vue-router-bridge/lib/v3/index.d.ts#L7-L75)
- Auto detect Vue Router version on bundling

@@ -90,5 +92,5 @@ - Manual switch versions

```sh
npx vue-router-switch 2
npx vue-router-switch 3
# or
npx vue-router-switch 3
npx vue-router-switch 4
```

@@ -101,5 +103,5 @@

```sh
npx vue-router-switch 2 vue2
npx vue-router-switch 3 vue-router3
# or
npx vue-router-switch 3 vue3
npx vue-router-switch 4 vue-router4
```

@@ -120,4 +122,4 @@ ### 🩹 Auto Fix

"scripts": {
"test:3": "vue-router-switch 2 vue-router3 && jest",
"test:4": "vue-router-switch 3 && jest",
"test:3": "vue-router-switch 3 vue-router3 && jest",
"test:4": "vue-router-switch 4 && jest",
},

@@ -136,3 +138,3 @@ "devDependencies": {

"scripts": {
"test:3": "vue-router-switch 4 && jest",
"test:3": "vue-router-switch 3 && jest",
"test:4": "vue-router-switch 4 vue-router4 && jest",

@@ -142,3 +144,3 @@ },

"vue-router": "^3.0.0",
"vue-router4": "npm:vue-router@43"
"vue-router4": "npm:vue-router@4"
},

@@ -145,0 +147,0 @@ }

@@ -22,7 +22,9 @@ const fs = require('fs') // eslint-disable-line @typescript-eslint/no-var-requires

function copy(name, version, router) {
function copy(name, version, router, esm = false) {
const src = path.join(dir, `v${version}`, name)
const dest = path.join(dir, name)
let content = fs.readFileSync(src, 'utf-8')
content = content.replace(/'router'/g, `'${router}'`)
content = esm
? content.replace(/from 'vue-router'/g, `from '${router}'`)
: content.replace(/require\('vue-router'\)/g, `require('${router}')`)
try {

@@ -34,2 +36,11 @@ fs.unlinkSync(dest)

function checkVueRouter(pkg) {
const router = loadModule(pkg)
if (!router) {
warn('Vue Router plugin is not found. Please run "npm install vue-router" to install.')
return false
}
return true
}
function checkVCA() {

@@ -46,2 +57,5 @@ const VCA = loadModule('@vue/composition-api')

router = router || 'vue-router'
if (!checkVueRouter(router)) {
return
}
if (version === 3 && !checkVCA()) {

@@ -51,4 +65,4 @@ return

copy('index.cjs', version, router)
copy('index.mjs', version, router)
copy('index.d.ts', version, router)
copy('index.mjs', version, router, true)
copy('index.d.ts', version, router, true)
}

@@ -55,0 +69,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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