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

@rrgayhart/load-machine

v1.0.2

Published

'my first npm module'

Downloads

4

Readme

Load Machine

A small library that creates button assignments for loading a vending machine. Created for a Turing School of Software and Design lesson Build an NPM Module

Installation

npm install @rrgayhart/load-machine

Usage

loadMachine(items, [opts])

  • items: required can be an array of multiple items or single object, string, number

  • opts: optional if included, will be an object allowing the following keys

    • height: max height of the vending machine

      • default: 8
    • width: width of vending machine

      • default: 6

    storage: an object with existing items


  var loadMachine = require('load-machine');

  var candies = [
    {name: 'Twix Bar'},
    {name: 'Snickers'}
  ]

  var result = loadMachine(candies);

  // console.log(result)
  // {
    // a1: {name: 'Twix Bar'},
    // a2: {name: 'Snickers'}
  // }

  loadMachine({name: 'Smarties'})

  // {
    // a1: {name: 'Twix Bar'},
    // a2: {name: 'Snickers'},
    // a3: {name: 'Smarties'}
  // }

Tests

npm test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Background

Relates to lesson Build an NPM Module

Steps I took to create this module

Creating

mkdir load-machine

cd load-machine

Where do we start writing code?

touch index.js

This code is going to be used by other people. So write tests.

  npm i mocha -D
  npm i chai -D
  mkdir test && touch test/test.js

Update scripts in the package.json

"scripts": {
  "test": "mocha --reporter spec"
}

Packaging

Creating a User

  npm adduser
  npm login

documentation

NPM init

I have made sure my app is up on Github first (allows NPM to autofill the repository details, which is nice)

Now I'll set npm up by running:

  npm init --scope=username

Note: I am namespacing my module, so that I don't hijack a name that someone else could use for a far better npm module than this one :D

The resulting JSON looks like:

{
  "name": "@rrgayhart/load-machine",
  "version": "1.0.0",
  "description": "'my first npm module'",
  "main": "index.js",
  "scripts": {
    "test": "mocha --reporter nyan",
    "lint": "eslint .",
    "lint-fix": "eslint . --fix"
  },
  "author": "Romeeka Gayhart",
  "license": "MIT",
  "devDependencies": {
    "chai": "^3.5.0",
    "eslint": "^3.19.0",
    "mocha": "^3.2.0"
  },
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "chai": "^3.5.0",
    "eslint": "^3.19.0"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/rrgayhart/load-machine.git"
  },
  "keywords": [
    "vending",
    "machine"
  ],
  "bugs": {
    "url": "https://github.com/rrgayhart/load-machine/issues"
  },
  "homepage": "https://github.com/rrgayhart/load-machine#readme"
}

Testing Locally

I wanted to test my module out in my project locally, before pushing it up to production.

In order to do that, I created a 'link'. See the npm-link documentation.

In my local module directory:

  cd load-machine
  npm link

In the directory of the project where I am using my module:

cd project
git checkout -b 'npm-refactor'
npm link load-machine

I can now use my local module as a module within my existing Vending Machine project!

  // in my actual project

  var loadMachine = require('load-machine');

  // ...

VendingMachine.prototype.loadMachine = function(input){
  loadMachine(input, {storage: this.inventory})
};

Deploying to NPM

  npm publish

Because I scoped my module, I will have to tell NPM that I want it to be public.

So I actually used:

 npm publish --access=public

I can now go into my project and add the project directly

npm install --save @rrgayhart/load-machine

And I will call use the module by requiring it by it's name (without the scope)

var loadMachine = require('load-machine')

And if I instantly regret my actions....

  npm unpublish [PACKAGE NAME]