Sha256: 40bcd1cff576cc783b6503052f31e69d610189cc02e4e59310ac744a09d054c0
Contents?: true
Size: 1.44 KB
Versions: 1
Compression:
Stored size: 1.44 KB
Contents
window.Brainstem ?= {} class window.Brainstem.Utils @warn: (args...) -> console?.log "Error:", args... @throwError: (message) -> throw new Error("#{Backbone.history.getFragment()}: #{message}") @matches: (obj1, obj2) -> if @empty(obj1) && @empty(obj2) true else if obj1 instanceof Array && obj2 instanceof Array obj1.length == obj2.length && _.every obj1, (value, index) => @matches(value, obj2[index]) else if obj1 instanceof Object && obj2 instanceof Object obj1Keys = _(obj1).keys() obj2Keys = _(obj2).keys() obj1Keys.length == obj2Keys.length && _.every obj1Keys, (key) => @matches(obj1[key], obj2[key]) else String(obj1) == String(obj2) @empty: (thing) -> if thing == null || thing == undefined || thing == "" true if thing instanceof Array thing.length == 0 || thing.length == 1 && @empty(thing[0]) else if thing instanceof Object _.keys(thing).length == 0 else false @extractArray: (option, options) -> result = options[option] result = [result] unless result instanceof Array _.compact(result) @wrapObjects: (array) -> output = [] _(array).each (elem) => if elem.constructor == Object for key, value of elem o = {} o[key] = @wrapObjects(if value instanceof Array then value else [value]) output.push o else o = {} o[elem] = [] output.push o output
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
brainstem-js-0.3.0 | vendor/assets/javascripts/brainstem/utils.coffee |