Skip to content

Instantly share code, notes, and snippets.

@soapie
Forked from jacob414/repr.coffee
Last active December 22, 2015 02:59
Show Gist options
  • Select an option

  • Save soapie/6407110 to your computer and use it in GitHub Desktop.

Select an option

Save soapie/6407110 to your computer and use it in GitHub Desktop.

Revisions

  1. soapie revised this gist Sep 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion repr.coffee
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,6 @@ repr = (o, depth=0, max=2) ->
    if Array.isArray o
    '[' + [''+repr(e, depth + 1, max) for e in o] + ']'
    else
    '{' + [''+k+':'+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
    '{' + [''+k+':'+repr(o[k], depth + 1, max) for k in Object.keys(o)] + '}'
    when 'undefined' then 'undefined'
    else o.toString # bool or number
  2. soapie revised this gist Sep 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion repr.coffee
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ repr = (o, depth=0, max=2) ->
    when 'function' then 'function'
    when 'object'
    if o is null then 'null'
    if _.isArray o
    if Array.isArray o
    '[' + [''+repr(e, depth + 1, max) for e in o] + ']'
    else
    '{' + [''+k+':'+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
  3. soapie revised this gist Sep 1, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion repr.coffee
    Original file line number Diff line number Diff line change
    @@ -12,4 +12,4 @@ repr = (o, depth=0, max=2) ->
    else
    '{' + [''+k+':'+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
    when 'undefined' then 'undefined'
    else o
    else o.toString # bool or number
  4. @jacob414 jacob414 revised this gist Jul 5, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions repr.coffee
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ repr = (o, depth=0, max=2) ->
    '<..>'
    else
    switch typeof o
    when 'string' then "\"#{o}\""
    when 'string' then "\"#{o.replace /"/g, '\\"'}\""
    when 'function' then 'function'
    when 'object'
    if o is null then 'null'
    @@ -12,4 +12,4 @@ repr = (o, depth=0, max=2) ->
    else
    '{' + [''+k+':'+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
    when 'undefined' then 'undefined'
    else o
    else o
  5. @jacob414 jacob414 revised this gist Jul 5, 2012. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions repr.coffee
    Original file line number Diff line number Diff line change
    @@ -3,10 +3,13 @@ repr = (o, depth=0, max=2) ->
    '<..>'
    else
    switch typeof o
    when 'string' then "\"#{o}\""
    when 'function' then 'function'
    when 'object'
    if o is null then 'null'
    if _.isArray(o) then o
    if _.isArray o
    '[' + [''+repr(e, depth + 1, max) for e in o] + ']'
    else
    '{' + [''+k+': '+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
    '{' + [''+k+':'+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
    when 'undefined' then 'undefined'
    else o
  6. @jacob414 jacob414 created this gist Dec 9, 2010.
    12 changes: 12 additions & 0 deletions repr.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    repr = (o, depth=0, max=2) ->
    if depth > max
    '<..>'
    else
    switch typeof o
    when 'object'
    if o is null then 'null'
    if _.isArray(o) then o
    else
    '{' + [''+k+': '+repr(o[k], depth + 1, max) for k in _.keys(o)] + '}'
    when 'undefined' then 'undefined'
    else o