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

galvanize-game-mechanics

v1.0.0

Published

Package to provide game mechanics for Galvanize exercises.

Downloads

22

Readme

Galvanize Game Mechanics

A small package that gives you some game mechanics with which to build other projects.

Libraries:

  1. Kingdom
  2. Fortune Teller
  3. Users Service

Castles

Create a Kingdom with up to three castles. Each castle is randomly assigned health and can be attacked.

Kingdom

Example on how to use kingdoms.

const Kingdom = require('galvanize-game-mechanics').Kingdom
// With no name, will be assigned a random name
const kingdom = new Kingdom()

// This will create a new Kingdom with the specific
// name of 'My Kingdom'
const otherKingdom = new Kingdom('My Kingdom')

// If you want to rename a kingdom, you can assign a
// new name to it.
kingdom.name = 'My Secondary Kingdom'

// Creates a new Castle called 'Castle A'
kingdom.createCastle('Castle A')

// Creates a new Castle with a random name
kingdom.createCastle()

// The last castle will not be created as there are already
// three castles at that point
kingdom.createCastle() // Does create a castle
kingdom.createCastle() // Will not create a castle

// Select castles via the `.castles` property
const castle = kingdom.castles[0]

// Will attack the castle for a random amount of damage.
// The `result` will be the `castle`
const resultA = kingdom.attackCastle(castle.id)

// Will rebuild the castle for a random amount of health.
// The `result` will be the `castle`
const resultB = kingdom.buildCastle(castle.id)

// Will return `false` if the castle cannot be found
const invalidCastle = kingdom.attackCastle('INVALID ID') // returns `false`

Fortune Teller

Ask the fortune teller a question and we promise you'll receive a spooky and mystical response! 🔮

FortuneTeller

Example on how to use the fortune teller.

const FortuneTeller = require('galvanize-game-mechanics').FortuneTeller

// Ask the FortuneTeller a question with the .ask method which
// returns a native JavaScript Promise.
const ask1 = FortuneTeller.ask('Will I became rich and famous?')

ask1.then(result => {
  // `result` will return an object with two keys: `question` and `response`.
  // `question` is the question you asked and `response` is a random fortune.
  console.log(result)
})

// If you call the `.ask()` method without a question, it will return an error.
const ask2 = FortuneTeller.ask()

ask1.catch(error => {
  // `error` will return an object with a single key, `error`. That value
  // will be an object with the key `message`.
  console.error(error)
})

// You can speed up the time it takes to answer a question by entering an
// optional second argument with the amount of time to wait in milliseconds.
const ask3 = FortuneTeller.ask('Will I become rich and famous?', 100)

ask3.then(result => {
  // This will resolve faster than the previous successful `.ask()`
  console.log(result)
})

Users Service

Create, retrieve, and remove users that are validated through the joi library.

UsersService

Example on how to use UsersService.

const UsersService = require('galvanize-game-mechanics').UsersService

// Will return an empty array
UsersService.users

// Users must be entered as an object and should include:
// - a valid email
// - a username with numbers, letters, and underscores only
const valid = {
  email: '[email protected]',
  username: 'users_service'
}
const user = UsersService.create(valid)

// The user will now have a UUID under the 'id' property
console.log(user.id, user)

// Returns the user object
UsersService.find(user.id)

// Will now return an array of one item
UsersService.users

// Will throw a ValidationError. To access the message of
// the error, call `.message` on the caught error
const invalid = {
  email: 'users.service',
  username: 'users-service'
}
UsersService.create(invalid)

// Removes the user object from the service. It will return
// the user that has been deleted.
UsersService.destroy(user.id)