Skip to content

Commit

Permalink
New defaults function
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed Oct 15, 2013
1 parent b629549 commit 6c102c2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/utils.coffee
Expand Up @@ -67,6 +67,17 @@ exports.round = (value, decimals) ->
######################################################
# HANDY FUNCTIONS

exports.defaults = (obj, defaults) ->

result = _.extend obj

for k, v of defaults
if result[k] in [null, undefined]
result[k] = defaults[k]

result


exports.randomColor = (alpha = 1.0) ->
c = -> parseInt(Math.random() * 255)
"rgba(#{c()}, #{c()}, #{c()}, #{alpha})"
Expand Down

0 comments on commit 6c102c2

Please sign in to comment.