url-breadcrumb
A simple function that creates a breadcrumb array from an url path string
- works on the server as well as in the browser
- the path string must start with a slash '/'
- node.js e.g.
req.url
- browser e.g.
window.pathname
install
npm install --save url-breadcrumb
usage
var breadcrumb = ;var crumbs = ; crumbs = ;// -> [{name: '⌂', NAME: '⌂', url: '/'}] crumbs = ;/* ->[ {name: '⌂', NAME: '⌂', url: '/'}, {name: 'A - B', NAME: 'a - b', url: '/A%20-%20B'}]*/ crumbs = ;/* ->[ {name: 'home', NAME: 'home', url: '/'}, {name: 'users', NAME: 'users', url: '/users'}, {name: 'profile', NAME: 'profile', url: '/users/profile'}, {name: 'change', NAME: 'change', url: '/users/profile/change'}, {name: 'address', NAME: 'address', url: '/users/profile/change/address'}]*/ crumbs = ;/* ->[ {name: '⌂', NAME: '⌂', url: '/'}, {name: 'users', NAME: 'users', url: '/users/'}, {name: 'profile', NAME: 'profile', url: '/users/profile/'}, {name: 'change', NAME: 'change', url: '/users/profile/change/'}, {name: 'address', NAME: 'address', url: '/users/profile/change/address'}]*/
Check test.js for more examples.
options
the following optional options can be provided as {Object} in the second argument.
- home {String}: name for the home link
- endingSlash {Boolean}: true, if the url elements should contain the ending slash '/'
- beautify {Function}: beautify function
test
npm test
license
MIT
author
Andi Neck | @andineck | andi.neck@intesso.com | intesso