Browse Source

cleanup

master
Conduitry 1 year ago
parent
commit
3f6408bfa0
7 changed files with 45 additions and 1142 deletions
  1. +0
    -9
      .eslintrc.yaml
  2. +4
    -1
      .gitignore
  3. +0
    -1089
      package-lock.json
  4. +4
    -6
      package.json
  5. +8
    -8
      rollup.config.js
  6. +4
    -4
      src/index.js
  7. +25
    -25
      src/utils/matchPath.js

+ 0
- 9
.eslintrc.yaml View File

@ -1,9 +0,0 @@
env:
es6: true
browser: true
plugins:
- html
extends: 'eslint:recommended'
parserOptions:
ecmaVersion: 2017
sourceType: module

+ 4
- 1
.gitignore View File

@ -1,2 +1,5 @@
/node_modules/
/dist/
/node_modules/
/package-lock.json
/shrinkwrap.yaml
/yarn.lock

+ 0
- 1089
package-lock.json
File diff suppressed because it is too large
View File


+ 4
- 6
package.json View File

@ -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"
}
}

+ 8
- 8
rollup.config.js View File

@ -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 },
],
}
};

+ 4
- 4
src/index.js View File

@ -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';

+ 25
- 25
src/utils/matchPath.js View File

@ -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…
Cancel
Save