npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodecrumbs

v1.0.2

Published

a lightweight and portable breadcrumbs library for node

Downloads

5

Readme

Nodecrumbs

Easy and compact breadcrumbs library for node

To install:

npm install nodecrumbs --save

The way it works is it parses the request URI, ie. /home/about/company into an an iterable array of breadcrumb objects so that you can render something like: "Home | About | Company" in your markup with all the necessary links without you having to worry about the formatting, names or links.

Examples

In your router create a breadcrumbs array like the following:

var nodecrumbs = require('nodecrumbs').Nodecrumbs;

app.get('/', (req, res) => {
    var crumbs = new Nodecrumbs(req);
    //parse the crumbs into an array and then pass it into your view

This will return you an instance of the Nodecrumbs object of which you can:

var crumbsArray = crumbs.parse();

This will give you an iterable object which you pass into and loop in your templates, though a premade render function using the initial nodecrumbs object (not the parsed array) is available to the lazier ones (example used uses EJS template library):

<%- nodecrumbs.render(); %>

Will render the default breadcrumbs markup

To manually render the breadcrumbs, you would iterate the crumbs array and use the getUri() and getName() methods respectively:

<ul>
<% for(var crumb in crumbs) {%>
    <li><a href="<%= crumbsArray[crumb].getUri(); %>"><%= crumbsArray[crumb].getName(); %></a></li>
<% } %>
</ul>

Documentaion

The Nodecrumbs constructor takes the following arguments:

Nodecrumbs(req, format = 'standard', home='home')

Request

The request object captured by your request listener (e.g express.js)

Format:

'upper', 'lower', ''standard' - (string) how the breadcrumbs should be formatted

Home:

defaults to ''home' - (string) alias for the first breadcrumb linking to home

Testing

Test cases can be checked with npm test

Feel free to contribute!