JavaScript library implementing a finite state machine