UNPKG

@motorcycle/router

Version:

Standard Router Driver for Motorcycle.js

41 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function isStrictlyInScope(namespace) { return function (location) { var pathParts = splitPath(location.path); return namespace.every(function (v, i) { return pathParts[i] === v; }); }; } exports.isStrictlyInScope = isStrictlyInScope; function getFilteredPath(namespace, path) { return '/' + filterPath(splitPath(path), namespace); } exports.getFilteredPath = getFilteredPath; function getUnfilteredPath(namespace, path) { return path.replace(getFilteredPath(namespace, path), ''); } exports.getUnfilteredPath = getUnfilteredPath; function newLocation(location, pathname) { var l = {}; var keys = Object.keys(location); for (var i = 0; i < keys.length; ++i) { l[keys[i]] = location[keys[i]]; } l.pathname = pathname; return l; } exports.newLocation = newLocation; function splitPath(path) { return path.split('/').filter(function (p) { return p.length > 0; }); } exports.splitPath = splitPath; function filterPath(pathParts, namespace) { return pathParts.filter(function (part) { return namespace.indexOf(part) < 0; }).join('/'); } exports.filterPath = filterPath; function pathJoin(parts) { var replace = new RegExp('/{1,}', 'g'); return parts.join('/').replace(replace, '/'); } exports.pathJoin = pathJoin; //# sourceMappingURL=helpers.js.map