uri-template-router
Version:
Match a URI to a pattern in a collection of URI Templates
62 lines (53 loc) • 3.16 kB
JavaScript
;
const { Router, Route, toViz } = require('./index.js');
const { Node, union, concat, fromString, optional } = require('./lib/fsm.js');
// var base = [
// new Node({'/': 1}, {}, false),
// new Node({}, {}, true),
// ];
// var tag = [
// new Node({'<matches>': 1}, {}, false),
// new Node({'/': 1}, {}, true),
// ];
// console.dir(base);
// console.log(toViz(base));
// console.log(toViz(concat([base, optional(tag)])));
const r = new Router;
r.addTemplate('https://api.github.com/', {}, 'index');
r.addTemplate('https://api.github.com/user', {}, 'foo');
r.addTemplate('https://github.com/settings/connections/applications{/client_id}', {}, '');
r.addTemplate('https://api.github.com/authorizations', {}, 'bar');
r.addTemplate('https://api.github.com/search/code?q={query}{&page,per_page,sort,order}', {}, '');
r.addTemplate('https://api.github.com/search/commits?q={query}{&page,per_page,sort,order}', {}, '');
r.addTemplate('https://api.github.com/user/emails', {}, '');
r.addTemplate('https://api.github.com/emojis', {}, '');
r.addTemplate('https://api.github.com/events', {}, '');
r.addTemplate('https://api.github.com/feeds', {}, '');
r.addTemplate('https://api.github.com/user/followers', {}, '');
r.addTemplate('https://api.github.com/user/following{/target}', {}, '');
r.addTemplate('https://api.github.com/gists{/gist_id}', {}, '');
r.addTemplate('https://api.github.com/hub', {}, '');
r.addTemplate('https://api.github.com/search/issues?q={query}{&page,per_page,sort,order}', {}, '');
r.addTemplate('https://api.github.com/issues', {}, '');
r.addTemplate('https://api.github.com/user/keys', {}, '');
r.addTemplate('https://api.github.com/search/labels?q={query}&repository_id={repository_id}{&page,per_page}', {}, '');
r.addTemplate('https://api.github.com/notifications', {}, '');
r.addTemplate('https://api.github.com/orgs/{org}', {}, '');
r.addTemplate('https://api.github.com/orgs/{org}/repos{?type,page,per_page,sort}', {}, '');
r.addTemplate('https://api.github.com/orgs/{org}/teams', {}, '');
r.addTemplate('https://api.github.com/gists/public', {}, '');
r.addTemplate('https://api.github.com/rate_limit', {}, '');
r.addTemplate('https://api.github.com/repos/{owner}/{repo}', {}, '');
r.addTemplate('https://api.github.com/repos/{owner}/{repo}.html', {}, '');
r.addTemplate('https://api.github.com/search/repositories?q={query}{&page,per_page,sort,order}', {}, '');
r.addTemplate('https://api.github.com/user/repos{?type,page,per_page,sort}', {}, '');
r.addTemplate('https://api.github.com/user/starred{/owner}{/repo}', {}, '');
r.addTemplate('https://api.github.com/gists/starred', {}, '');
r.addTemplate('https://api.github.com/search/topics?q={query}{&page,per_page}', {}, '');
r.addTemplate('https://api.github.com/users/{user}', {}, '');
r.addTemplate('https://api.github.com/user/orgs', {}, '');
r.addTemplate('https://api.github.com/users/{user}/repos{?type,page,per_page,sort}', {}, '');
r.addTemplate('https://api.github.com/search/users?q={query}{&page,per_page,sort,order}', {}, '');
console.log(r.toViz());
// const res = r.resolveURI('https://api.github.com/users/awwright');
// console.log(res.toViz());