cleanup
This commit is contained in:
parent
c30ec39bd6
commit
3f6408bfa0
7 changed files with 45 additions and 1142 deletions
|
@ -1,9 +0,0 @@
|
|||
env:
|
||||
es6: true
|
||||
browser: true
|
||||
plugins:
|
||||
- html
|
||||
extends: 'eslint:recommended'
|
||||
parserOptions:
|
||||
ecmaVersion: 2017
|
||||
sourceType: module
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
|||
/node_modules/
|
||||
/dist/
|
||||
/node_modules/
|
||||
/package-lock.json
|
||||
/shrinkwrap.yaml
|
||||
/yarn.lock
|
||||
|
|
1089
package-lock.json
generated
1089
package-lock.json
generated
File diff suppressed because it is too large
Load diff
10
package.json
10
package.json
|
@ -1,12 +1,10 @@
|
|||
{
|
||||
"scripts": {
|
||||
"build": "rollup -c",
|
||||
"lint": "eslint src rollup.config.js --ext .js,.html"
|
||||
"build": "rollup -c"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.1.1",
|
||||
"eslint-plugin-html": "^3.0.0",
|
||||
"rollup": "^0.43.0",
|
||||
"rollup-plugin-svelte": "^2.0.2"
|
||||
"rollup": "^1.1.0",
|
||||
"rollup-plugin-svelte": "^5.0.0",
|
||||
"svelte": "^3.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import svelte from 'rollup-plugin-svelte'
|
||||
import svelte from 'rollup-plugin-svelte';
|
||||
|
||||
export default {
|
||||
entry: './src/index.js',
|
||||
sourceMap: true,
|
||||
plugins: [ svelte() ],
|
||||
targets: [
|
||||
{ dest: './dist/index.cjs.js', format: 'cjs' },
|
||||
{ dest: './dist/index.es.js', format: 'es' },
|
||||
input: './src/index.js',
|
||||
external: name => /^[@a-z]/.test(name),
|
||||
plugins: [svelte()],
|
||||
output: [
|
||||
{ file: 'dist/index.cjs.js', format: 'cjs', sourcemap: true },
|
||||
{ file: 'dist/index.es.js', format: 'esm', sourcemap: true },
|
||||
],
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
export { default as Redirect } from './components/Redirect.html'
|
||||
export { default as Route } from './components/Route.html'
|
||||
export { default as Router } from './components/Router.html'
|
||||
export { default as matchPath } from './utils/matchPath.js'
|
||||
export { default as Redirect } from './components/Redirect.html';
|
||||
export { default as Route } from './components/Route.html';
|
||||
export { default as Router } from './components/Router.html';
|
||||
export { default as matchPath } from './utils/matchPath.js';
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
let cache = new Map()
|
||||
let escapeRe = /[\\^$.*+?()[\]{}|]/g
|
||||
let paramRe = /:\w+/
|
||||
const cache = new Map();
|
||||
const escapeRe = /[\\^$.*+?()[\]{}|]/g;
|
||||
const paramRe = /:\w+/;
|
||||
|
||||
export default function matchPath(pathname, { path, exact }) {
|
||||
let key = path + !!exact
|
||||
let regex
|
||||
let names
|
||||
export default (pathname, { path, exact }) => {
|
||||
const key = path + !!exact;
|
||||
let regex;
|
||||
let names;
|
||||
if (cache.has(key)) {
|
||||
({ regex, names } = cache.get(key))
|
||||
({ regex, names } = cache.get(key));
|
||||
} else {
|
||||
let rest = path
|
||||
regex = '^'
|
||||
names = []
|
||||
let match
|
||||
while ((match = rest.match(paramRe))) {
|
||||
regex += rest.slice(0, match.index).replace(escapeRe, '\\$&') + '([^/]+)'
|
||||
names.push(match[0].slice(1))
|
||||
rest = rest.slice(match.index + match[0].length)
|
||||
let rest = path;
|
||||
regex = '^';
|
||||
names = [];
|
||||
let match;
|
||||
while (match = rest.match(paramRe)) {
|
||||
regex += rest.slice(0, match.index).replace(escapeRe, '\\$&') + '([^/]+)';
|
||||
names.push(match[0].slice(1));
|
||||
rest = rest.slice(match.index + match[0].length);
|
||||
}
|
||||
regex += rest.replace(escapeRe, '\\$&') + (exact ? '$' : '(?=\\/|$)')
|
||||
regex = new RegExp(regex)
|
||||
cache.set(key, { regex, names })
|
||||
regex += rest.replace(escapeRe, '\\$&') + (exact ? '$' : '(?=\\/|$)');
|
||||
regex = new RegExp(regex);
|
||||
cache.set(key, { regex, names });
|
||||
}
|
||||
let match = pathname.match(regex)
|
||||
const match = pathname.match(regex);
|
||||
if (!match) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
let params = {}
|
||||
const params = {};
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
params[names[i]] = match[i + 1]
|
||||
params[names[i]] = match[i + 1];
|
||||
}
|
||||
return { path, url: match[0], params }
|
||||
}
|
||||
return { path, url: match[0], params };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue