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 in dist
folderKopi.js can do two important things:
Kopi
Kopi
is a singleton, like JSON
. The methods available are also similar:
Kopi.parse
Kopi.stringify
Kopi.parse
Kopi.parse('Kopi O');
// return {water: 0.5, coffee: 0.5, condensed_milk: 0, evaporated_milk: 0, sugar: 0, state: 'warm'}
Ingredients:
water
- number, default 1
, 0 to 1coffee
- number, default 0
, 0 to 1condensed_milk
(sweetened) - number, default 0
, 0 to 1evaporated_milk
(unsweetened), number, default 0
, 0 to 1sugar
- number, default 0
, 0 to infinitestate
- boolean, default warm
, other values: lukewarm
and iced
The sum of water
, coffee
, condensed_milk
and evaporated_milk
is always 1.
Kopi.stringify
Kopi.stringify({water: .5, coffee: .5});
// return 'Kopi O'
That simple.