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

shopkeepr

v1.0.2

Published

Shopkeepr makes it easy for you to add merchants/stores/shopkeepers to your JavaScript game.

Downloads

22

Readme

NPM version Known Vulnerabilities npm NPM downloads Gitter

Table of Contents

Overview

Shopkeepr is used to create and manage virtual shops within your JavaScript game. Support for sub-inventories, two pricing models, and sell/buy functionality make it a one stop for all shop/reward centers for your game.

Every shop in your game should be a new instance of a Shopkeepr. In every new instance of Shopkeepr, you have a main inventory and within this main inventory you can create as many unique sub-inventories as you want in order to better filter and categorize your items.

Installation

To install shopkeepr you can use:

$ npm install shopkeepr

and then to reference in your project:

// Node
const Shopkeepr = require('shopkeepr');

// Webpack
import Shopkeepr from 'shopkeepr';

// Browser Import
import shopShopkeeprkeepr from 'node_modules/shopkeepr/shopkeepr.js';

Initialization

To create a new shop, simply create a new instance of Shopkeepr with the name of the shop.

const runeShop = new Shopkeepr('Rune Shop');

Here are all of the initialization options available:

| param | type | description | default | |------------------- |--------- |---------------------------------------------------- |--------- | | name | string | The name of this shop. | | | options | Object | | | | options.currency | Array | Defines the currencies used in this shop | ['gold'] | | options.initialGold | Array | The amount of gold this shop starts out with | [100] |

In regards to currency and startingMoney, they are both defined as arrays and they should have the same length. For example, if you set a three tier currency system using ['gold', 'silver', 'copper'] you should set the startingMoney in the same order. So if you wanted to have 1 gold, 5 silver, and 10 copper you would set startingMoney to [1, 5, 7].

Getting Started

If you're just interested in the API then look below but if you want a beginner friendly in-depth guide about the components of Shopkeepr checkout the getting started guide.

API

Below are the methods available to various parts of Shopkeepr, if any of these confuse you, you might want to check out the getting started guide first.

General Properties

These properties are available to use on an instance of Shopkeepr:

name

Getter that returns the name of the shop.

example:

const shop = new Shopkeepr('General Store');

console.log(shop.name); // General Store

wallet

Gets the money currently in the coin pouch. If using a single tier system this will return a number but if using a three tiered system this will return an object.

*example:

// Setting up a one tier system:
const options = {
  currency: ['gold']
  startingMoney: [100]
};

const shop = new Shopkeepr('General Store', options);

console.log(shop.wallet); // 100

// Setting up a three tier system:
const options = {
  currency: ['gold', 'silver', 'copper'],
  startingMoney: [1, 50, 70]
};

const shop = new Shopkeepr('General Store', options);

console.log(shop.wallet); // { gold: 1, silver: 50, copper: 70 }

Selling/Buying

The following properties and methods are related to selling/buying from the shop and handling money.

sell

Sells an item from this shop.

This removes the item from the shop's inventory and adds the cost of the item to the shop's coin pouch.

| param | type | description | default | |------- |------ |----------------------------------- |--------- | | item | Item | The item to sell from the shop | |

example:

shopkeepr.inventory.addItem({ name: 'mana potion', sellPrice: 5, buyPrice: 4, regen: 10 });

const potion = shopkeepr.inventory.getItem('mana potion');

shopkeepr.sell(potion);

// The shop now removes the item from its inventory and adds 5 coins to its pouch.

buy

Buys an item from the player and adds it to the shop's inventory.

| param | type | description | default | |------- |------ |----------------------------------- |--------- | | item | Item | The item to sell to the shop | |

example:

const item = { name: 'mana potion', sellPrice: 5, buyPrice: 4, regen: 10 };

shopkeepr.buy(item);

// The show now adds the item to its inventory and removes 4 coins from its pouch.

Coins

The following properties and methods are available to use with the shop's coin pouch.

Inventory

The following properties and methods are available to use with the shop's inveontory.

addItem

Adds an item to the inventory. Remember that items at the very least need to have a name, sellPrice, and buyPrice property. Check the getting started guide guide if you need more in-depth information about this.

| param | type | description | default | |------- |------ |----------------------------------- |--------- | | item | Item | The item to add to the inventory. | |

example:

const potion = { name: 'mana potion', sellPrice: 5, buyPrice: 4, regen: 10 };

shopkeepr.inventory.addItem(potion);

getItem

Gets an item from the inventory.

| param | type | description | default | |------- |------- |--------------------------------------- |--------- | | name | string | The name of the item in the inventory | |

example:

const potion = { name: 'mana potion', sellPrice: 5, buyPrice: 4, regen: 10 };

shopkeepr.inventory.addItem(potion);

const myPotion = shopkeepr.inventory.getItem('mana potion');

getItems

Returns one or more items that belong to one or more filters.

Using this without any arguments will return all items from the inventory.

| param | type | description | default | |--------- |------- |--------------------------------------- |--------- | | filters | Array | The filters to search for | |

example:

const manaRing = { name: 'ring of mana', sellPrice: 5, buyPrice: 4, filters: ['mana', 'ring'] };
const manaPotion = { name: 'mana potion', sellPrice: 5, buyPrice: 4, filters: ['mana', 'potion'] };
const healthPotion = { name: 'health potion', sellPrice: 5, buyPrice: 4, filters: ['health', 'potion'] };

shopkeepr.inventory.addItem(manaRing);
shopkeepr.inventory.addItem(manaPotion);
shopkeepr.inventory.addItem(healthPotion);

const myPotion = shopkeepr.inventory.getItems(['potion']); // Returns an array containing the mana and health potions.

removeItem

Removes an item from the inventory.

| param | type | description | default | |------- |------ |--------------------------------------- |--------- | | item | Item | The item to remove from the inventory. | |

example:

const potion = { name: 'mana potion', sellPrice: 5, buyPrice: 4, regen: 10 };

shopkeepr.inventory.addItem(potion);

shopkeepr.inventory.removeItem(potion);

Tests

To run the tests for Shopkeepr use:

$ npm run test

License

MIT