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

beer-me

v1.1.2

Published

Library to (not so) randomly pick beers for you.

Downloads

17

Readme

beer-me npm version

Library to (not so) randomly pick beers for you.

Requirements

This library works with a list of beers from the metro online grocery website that you can extract using feed-me.

const metro = require('feed-me')
const fs = require('fs')

metro.getAllResults({ category: 'beverages/beer-cider' })
  .then(JSON.stringify)
  .then(json => fs.writeFileSync('beers.json', json))

The expected format of a beer object is the following:

{
  "brand": "Brasserie Dieu du Ciel!",
  "name": "Disco Soleil kumquats IPA strong beer",
  "weight": "341 ml - bottle",
  "price": 2.39,
  "image": {
    "small": "https://product-images.metro.ca/images/h0b/h4c/8883933675550.jpg",
    "large": "https://product-images.metro.ca/images/h41/h2e/8883934593054.jpg"
  },
  "link": "https://www.metro.ca/en/online-grocery/aisles/beverages/beer-cider/artisanal-beer-microbrewery/disco-soleil-kumquats-ipa-strong-beer/p/696859060489",
  "category": "beverages/beer-cider/artisanal-beer-microbrewery"
}

For convenience, I added a static version of that list in the beers branch.

Usage

const beer = require('beer-me')
const beers = require('./beers').map(beer.formatify)

console.log(beer.beerMe(beers, 48))

You will get a selection of beers in the same format, but with a number of items that will match the desired number of beers (given as second argument).

Getting actual beers

For some reason, even if you search in the beverages/beer-cider categories, you get, stuff that is definitely not beer:

  • beverages/beer-cider/cider
  • beverages/beer-cider/non-alcoholic-beer
  • beverages/juices-drinks/sparkling-juices-drinks
  • beverages/soft-drinks/ginger-ale
  • beverages/wines-cocktails-coolers/cocktails-other-wines
  • beverages/wines-cocktails-coolers/sparkling-wine

By calling:

const actualBeers = beers.filter(beer.isActualBeer)

You get only beers from the following categories:

  • beverages/beer-cider/artisanal-beer-microbrewery
  • beverages/beer-cider/classic-beer
  • beverages/beer-cider/classic-light-beer
  • beverages/beer-cider/imported-beer
  • beverages/beer-cider/specialty-flavoured-beer

Parsing beer format

beer.parseFormat('740•ml - can') // { count: 1, size: 740, type: 'can' }
beer.parseFormat('24x330•ml - cans') // { count: 24, size: 330, type: 'cans' }
beer.parseFormat('1.18•L - bottle') // { count: 1, size: 1180, type: 'bottle' }
beer.parseFormat('12x341•ml - bottles') // { count: 12, size: 341, type: 'bottles' }

You can also use the following:

const parsedBeers = beers.map(beer.formatify)

After what all the beers will have a format property with the count, size and type.

This is especially useful to filter beers:

const packsOfCans = parsedBeers.filter(beer => beer.format.type === 'cans')
const packsOfBottles = parsedBeers.filter(beer => beer.format.type === 'bottles')
const bigPacksOfBottles = packsOfBottles.filter(beer => beer.format.count >= 24)

This is also needed for the beerMe algorithm.

Real life example

Get packs of between 12 and 24 bottles (less than 500 ml) of beer from a given list of brands, to get a total of 48 bottles:

const beer = require('beer-me')
const beers = require('./beers')
const brands = require('./brands') // An array of brand names to pick.

const set = beers
  .map(beer.formatify)
  .filter(beer.isActualBeer)
  .filter(beer => beer.format.type === 'bottles')
  .filter(beer => beer.format.count >= 12 && beer.format.count <= 24)
  .filter(beer => beer.format.size < 500)
  .filter(beer => brands.includes(beer.brand))

const selection = beer.beerMe(set, 48)