A JavaScript function for parsing a spec formatted string.
const parse = require("spec-js-parser");
const { compute, eventNames } = parse(`
[playback] is [paused]
given that [playback] is [paused]
then the [pause button] is [hidden]
and the [play button] is [visible]
given that [playback] is [resumed]
then the [play button] is [hidden]
and the [pause button] is [visible]
when the [user] [taps] the [play button]
then [playback] is [resumed]
when the [user] [taps] the [pause button]
then [playback] is [paused]
`);
eventNames;
/*
[ 'user taps play button', 'user taps pause button' ]
*/
const state = compute();
/*
{
'playback': 'paused',
'pause button' : 'hidden',
'play button' : 'visible'
}
*/
compute(state, "user taps play button");
/*
{
'playback': 'resumed',
'pause button' : 'visible',
'play button' : 'hidden'
}
*/
MIT © Matt Donkin