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

@truck/stack

v1.0.1

Published

A JavaScript implementation of the Stack data structure

Downloads

1

Readme

Build Status Coverage Status semantic-release

Stack

A JavaScript Stack data structure.

A Stack follows a LIFO (Last-In-First-Out) methodology, just like pancakes in a plate.

Installation

Install @truck/stack via npm:

$ npm install --save @truck/stack

Methods

Methods > constructor(maximumLength?: int)

Build a new stack. Pass an optional maximumLength which will limit the Stack length, the default is 65535.

Methods > empty(): void (O(1))

Empties the Stack, resetting the length back to 0.

Methods > isEmpty(): boolean (O(1))

Checks whether the Stack is empty.

Methods > isFull(): boolean (O(1))

Checks whether the Stack is full.

Methods > peek(): any (O(1))

Get the item at the front of the Stack without removing it.

Methods > pop(): any (O(1))

Removes the top (last inserted) value from the Stack and returns it.

Methods > push(value: any): void (O(1))

Adds a value to the top of the Stack. Throws a RangeError when the addition will exceed the maximum length allowed (defined in the constructor).

Methods > toArray(): any[] (O(n))

Returns the Stack as an array.

Properties

Properties > .length: number

Returns the current length of the Stack.

Examples

A Stack is a standard class which can be instantiated with the new keyword:

// Build a new Stack with a maximum length of 10 values
const stack = new Stack(10);
// Get the length of the Stack
let length = Stack.length; // 0
// Add some values to the Stack
stack.push(1);
stack.push('two');
stack.push({ three: 'three' });
stack.push(false);
// Check if the Stack is full
if (!stack.isFull()) {
  stack.push('FIVE');
}
// Get the length of the Stack
length = Stack.length; // 5
// Get the Stack as an array
const stackAsArray = stack.toArray(); // [1, 'two', { three: 'three' }, false, 'FIVE']
// Remove the values from the Stack
stack.pop(); // 'FIVE'
stack.pop(); // false
stack.pop(); // { three: 'three' }
stack.pop(); // 'two'
// Check if the Stack is empty
if (!stack.isEmpty()) {
  stack.pop(); // 1
}
// Get the length of the Stack
length = Stack.length; // 0

Testing

Use the following command to run all the tests described below together:

$ docker-compose run --rm app npm test

Testing > Commit messages

Commit messages are linted through the use of husky and @commitlint/cli using the @commitlint/config-conventional commit convention.

Please read through the AngularJS Git Commit Message Conventions to get a better understanding of how commit messages are formatted.

After doing an npm install the required git hooks wil be added automatically and commit messages will be linted automatically.

Testing > Linting

Linting is done using eslint using the eslint-config-airbnb-base configuration with very few alterations, all of which can be seen in the .eslintrc file in the root of this repository.

Linting can be run in isolation through the command:

$ docker-compose run --rm app npm run test:lint

Testing > Auditing

Auditing of dependencies is done through the npm audit command-line tool.

Auditing can be run in isolation through the command:

$ docker-compose run --rm app npm run test:vulnerabilities

Testing > Unit testing

Unit testing is done with jest. The test file for each file to be tested is to be placed alongside the file in testing and marked with the .test.js extension.

Unit testing can be run in isolation through the command:

$ docker-compose run --rm app npm run test:scripts

Contributing

Contributions are always welcome, just submit a PR to get the conversation going. Please make sure all tests pass before submitting a PR.

Contributing > Releases

The moment a PR is merged into the master branch semantic-release will kick-off a new release, thus the importance of clear commit messages.