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

product-inventory-statuses

v1.0.3

Published

product stock status indicator

Downloads

22

Readme

Product Inventory Statuses

This is a utility function designed to calculate the status of a product's availability based on its publication date and inventory across different warehouses. It can be used both in Nuxt.js applications (e.g., as a global utility) and in AWS Node.js Lambdas.

Installation

Install the package via npm:

npm install product-inventory-statuses

Usage

Importing and using the function in your project

You can use the calculateProductStatus function to calculate the status of the product.

Parameters:

  • publicationdate (string | null): The publication date of the product. If the date is unknown, use "9999-12-31" or null.
  • inventories (Array<object>): An array of inventory objects. Each object should have:
    • warehouseID (string): The ID of the warehouse.
    • inventoryAmount (number): The amount of inventory in that warehouse.

Return values:

The function returns different status codes depending on the inventory and the publication date:

  • 10: "In Stock" and also on sale (Not implemented yet, reserved for future use).
  • 20: "In Stock" (The product is available in the store).
  • 30: "Orderable" (The product is not in stock at the store but available at another warehouse).
  • 40: "We accept pre-orders" (The product is out of stock, but the publication date is in the future).
  • 50: "Out of stock" (The product is out of stock both at the store and the warehouse, and the publication date is past or now).
  • 60: "" (No information, not available).

Example usage in Nuxt.js:

You can place the utility function in the utils directory of your Nuxt app and use it globally. Here's an example of how you would use the package in a Nuxt.js application:

// Import the function
import { calculateProductStatus } from 'product-inventory-statuses';

// Example inventory data
const inventories = [
  { warehouseID: '6a7528da-5096-4d0e-b864-08539b66c9fa', inventoryAmount: 10 },
  { warehouseID: 'other-warehouse-id', inventoryAmount: 5 }
];

// Call the function
const status = calculateProductStatus('2024-10-15', inventories);

console.log(status); // Output: 20, because there is stock in the store

Example usage in AWS Lambda:

You can also use this utility in AWS Node.js Lambda functions:

// Import the function
const { calculateProductStatus } = require('product-inventory-statuses');

exports.handler = async (event) => {
  const inventories = [
    { warehouseID: '6a7528da-5096-4d0e-b864-08539b66c9fa', inventoryAmount: 0 },
    { warehouseID: 'other-warehouse-id', inventoryAmount: 0 }
  ];

  const status = calculateProductStatus('2024-12-31', inventories);

  return {
    statusCode: 200,
    body: JSON.stringify({ status })
  };
};

Publishing your package to npm

To publish this package to npm, follow these steps:

  1. First, make sure you have a valid npm account. If you don't have one, create an account at npmjs.com.
  2. Login to npm:
npm login
  1. Ensure your package.json file is correctly set up. Here's an example:
{
  "name": "product-inventory-statuses",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "description": "Utility to calculate product availability status",
  "author": "Your Name",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}
  1. Publish the package:
npm publish

Once the package is published, you can install it in your projects by running:

npm install product-inventory-statuses

License

This project is licensed under the MIT License.