Skip to content

Instantly share code, notes, and snippets.

@frostney
Created March 10, 2013 00:13
Show Gist options
  • Save frostney/5126442 to your computer and use it in GitHub Desktop.
Save frostney/5126442 to your computer and use it in GitHub Desktop.
Small utility library
do (root = exports ? window.eos or= {}) ->
root.each = (object, callback) ->
if Array.isArray object
callback key, value for value, key in object
else
callback key, value for own key, value of object
null
root.isEmptyObject = (object) -> Object.keys(object).length is 0
root.isPlainObject = (object) ->
return false if typeof value is 'object' for own key, value of object
root.noop = ->
cleanArray = (object) ->
for i in object
unless i? then continue else i
cleanObject = (object) ->
newObject = {}
for own key, value of object
if i? then newObject[key] = value
newObject
root.clean = (object) ->
if Array.isArray object
cleanArray object
else
cleanObject object
root.unique = (array) ->
newArray = []
for i in array
newArray.push i unless newArray.indexOf i >= 0
newArray
root.contains = (array, part) -> array.indexOf(part) >= 0
root.toArray = (value) ->
if typeof value is 'object'
Object.keys value
else
value.split('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment