https://github.com/douglascrockford/TDOP adapted for NodeJS