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

@team4159/hoard.js

v1.1.1

Published

A JavaScript client for Team4159's shop inventory management project.

Downloads

13

Readme

hoard.js

A JavaScript client for Team4159's shop inventory management project.

Installation

In a browser:

<script src="hoard.js"></script>

Using npm:

npm i @team4159/hoard.js --save

Usage

const myHoard = new Hoard("My Hoard Name");

const pencil = { 
    name: 'Pencil', 
    category: 'Writing', 
    amount: 1
}

// Adds a 'Pencil' to the hoard named 'My Hoard Name', then logs it
myHoard.addItem(pencil)
    .then(console.log);

// Logs all Items in the hoard name 'My Hoard Name'
myHoard.getAllItems()
    .then(console.log);

API

Item

Hoard is centered around Item objects with the following schema:

{
    // Name of the item (i.e. Hacksaw)
    name: string,
    // Category the item belongs to (i.e. Saws)
    category: string,
    // Amount of the item in inventory
    amount: number,
    
    // Optional image url
    imageUrl?: string,
    // Optional description
    description?: string,
    
    // Name of the hoard the item belongs to, assigned by the client
    hoardName?: string,
    // Unique MongoDB ObjectID assigned by the server, can be used for calculating the timestamp of the creation of the item
    _id?: string
}

Methods

Synchronous

You should avoid using synchronous methods. They can cause your apps to freeze and your browser to crash. However, on smaller scales, it should be fine to use synchronous methods. Synchronous methods avoid using Promises by instead blocking until the server responds.

The synchronous API is the same as the asynchronous API (see below). Simply append 'Sync' to any asynchronous method to use the equivalent synchronous method. For example:

const data = item.getItemsByCategorySync('Measurement');

// Logs all items in category 'Measurement'
console.log(data);
Asynchronous

The hoard.js client returns asynchronous Promises that are resolved to Items or arrays of Items.

// Adds an Item, resolves to the added Item
hoard.addItem(item);

// Gets all Items, resolves to an array of Items 
hoard.getAllItems();

// Gets a specific item by name, resolves to the specified Item
hoard.getItemByName(item_name);

// Gets a specific item by its MongoDB ObjectID, resolves to the specified Item
hoard.getItemByID(item_id);

// Gets all Items in a certain category, resolves to an array of Items in the category
hoard.getItemsByCategory(category);

// Find an Item by its name and update it, resolves to the updated Item.
hoard.updateItemByName(item_name, updated_item);

// The updated item can be a partial Item object. For example, if you wanted to change the amount of an Item, you would call:
hoard.updateItemByName('Pencil', { amount: 7 });

// Find an Item by its MongoDB ObjectID and update it, resolves to the updated Item.
hoard.updateItemByID(item_id, updated_item);

// Delete an Item by its name, resolves to the deleted Item
hoard.deleteItemByName(item_name);

// Delete an Item by its MongoDB ObjectID, resolves to the deleted Item
hoard.deleteItemByID(item_id);

To use asynchronous methods, employ the .then method. For example, if one wanted to log all 'Power Tools' that were in inventory:

hoard.getItemsByCategory('Power Tools')
    .then(function(data) {
        console.log(data);
    });

The above is equivalent to this:

hoard.getItemsByCategory('Power Tools')
    .then(console.log)