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

sectioned-list

v1.1.0

Published

A list of arrays with predefined max lengths. Add to the list and items flow into sections.

Downloads

7

Readme

A list of arrays with predefined max lengths. Add to the list and items flow into sections.

Usage, Tests & Contributing

npm install --save sectioned-list

sectioned-list

Usage

  • new constructor(config) Create a new instance with a config object.

  • addItem(<any>) Adds an item to the next section that has space for it.

  • addItems(Array<any>) Adds the items to the list by calling addItem() for each item in order.

  • sections Get all sections in the list. A section's items can be accessed via its items field. You can also access a section's index in the list and size, the number of fields it has, fields.

  • sectionedItems Get an array of the items in the list in their section arrays. The returned value looks like this: Array<Array<any>>

  • addSectionSize Add a section size specification to the list. There is no way to remove a section size specification.

There may be other public fields you can access, but they are not necessary, so we've omitted them here.

See the tests (tests/sectionedList_test.js) to see how these methods are used.

config object

When creating an instance, you can specify an optional configuration object with the following fields:

  • sectionSizes

sectionSizes: Array<Number>

You can specify an array of numbers to define the max size of your sections. If you don't specify this, it will default to [10], which will give all your sections a max size of 10.

Say you provide the following array of section sizes: [3, 5, 10]. As you add items to the list, it will first create a section with the first 3 items, then another section with the next 5 items, and subsequent items will create subsequent sections of max-10 items. So, if you have 34 items to add to your sectioned list, the sections would look like this:

- 3 items
- 5 items
- 10 items
- 10 items
- 6 items

Empty sections

You can even specify empty sections by doing something like this: [3, 5, 0, 10, 0, 20]. 0 indicates an empty section.

Why would you do this? Perhaps you're using your sectioned list to display the items of the sections on a web page and want to use the empty sections to display advertisements.

So if you specify [3, 5, 0, 10, 0, 20] for your section sizes and use the empty sections to show advertisements, the web page would look something like this with 55 items:

- 3 items
- 5 items
- An advertisement
- 10 items
- Another advertisement
- 20 items
- 17 items

Note that if your last section size is empty, any subsequent sections will default to a max size of 10.

Tests

We use mocha and chai. Run npm test

Contributing

Feel free to open a pull request!

Created by Lincoln W Daniel.