API for ordering Singaporean Coffee
Kopi.JS is an incredibly lightweight JavaScript library for parsing Kopi ingredients and converting them to a legit Kopi order string. It can also do it the other way around. It's built in ES6 and tested with Mocha.
Because we need specs for Singapore Coffee!
It all started from this Twitter conversation: https://twitter.com/laktek/status/400080522656759808
Requires Grunt.
npm install
- set up all the toolsnpm test
- run the specsnpm run dist
- generate the distribution files indist
folder
Kopi.js can do two important things:
- Accept a bunch of ingredients and generate the string for you.
- Parse a Kopi order string and return the ingredients for you.
Kopi
is a singleton, like JSON
. The methods available are also similar:
Kopi.parse
Kopi.stringify
Kopi.parse('Kopi O');
// return {water: 0.5, coffee: 0.5, condensed_milk: 0, evaporated_milk: 0, sugar: 0, state: 'warm'}
Ingredients:
water
- number, default1
, 0 to 1coffee
- number, default0
, 0 to 1condensed_milk
(sweetened) - number, default0
, 0 to 1evaporated_milk
(unsweetened), number, default0
, 0 to 1sugar
- number, default0
, 0 to infinitestate
- boolean, defaultwarm
, other values:lukewarm
andiced
The sum of water
, coffee
, condensed_milk
and evaporated_milk
is always 1.
Kopi.stringify({water: .5, coffee: .5});
// return 'Kopi O'
That simple.