Skip to content

Instantly share code, notes, and snippets.

@soapie
soapie / repr.js
Last active October 29, 2023 12:18
Simple repr function for javascript.
'use strict';
var ELIDED = '<..>';
function repr(thing, depth, max) {
if (depth === undefined) { depth = 0; }
if (max === undefined) { max = 2; }
if (isPrim(thing)) {
return showPrim(thing);
@soapie
soapie / repr.coffee
Last active December 22, 2015 02:59 — forked from jacob414/repr.coffee
repr = (o, depth=0, max=2) ->
if depth > max
'<..>'
else
switch typeof o
when 'string' then "\"#{o.replace /"/g, '\\"'}\""
when 'function' then 'function'
when 'object'
if o is null then 'null'
if Array.isArray o