cola

Superfluous syntactic sugar for CoffeeScript, inspired by Scala

npm install cola
2 downloads in the last week
8 downloads in the last month

node-cola

Superfluous syntactic sugar for CoffeeScript, inspired by Scala.

Scala + Coffee = Cola (or scoffee?)


{Regex, Extract, Case} = require './cola'

# simple match (no arg for the callback)
mi6  = Case (s) -> s is "James Bond"

# extractor (must return a list of callback arguments)
name = Extract (s) -> r = s.split " "; [r[0], r[1]] if r[1]

# will execute all matches, asynchrounously. does not return a result.
"James Bond".matches [
  Regex(/James/)     ->  console.log "My name is Bond."
  mi6                ->  console.log "007"
  name (first, last) ->  console.log "#{first} #{last}."
]

# will match first, synchronously
result = "James Bond".match [
  Regex(/James/)     ->  console.log "My name is Bond."
  mi6                ->  console.log "007"
  name (first, last) ->  console.log "#{first} #{last}."
]

if you don't like enclosing blocks with special characters, you can also use a map. The syntax is not that nice, however, since you have to define accessors/keys :( (their values is ignored by match)


"James Bond".match
  a: Regex(/James/)     ->  console.log "My name is Bond."
  b: mi6                ->  console.log "007"
  c: name (first, last) ->  console.log "#{first} #{last}."
npm loves you