sanctuary-show
Advanced tools
Comparing version 1.0.0 to 2.0.0
78
index.js
@@ -39,10 +39,10 @@ //. # sanctuary-show | ||
if (typeof module === 'object' && typeof module.exports === 'object') { | ||
module.exports = f(); | ||
module.exports = f (); | ||
} else if (typeof define === 'function' && define.amd != null) { | ||
define([], f); | ||
define ([], f); | ||
} else { | ||
self.sanctuaryShow = f(); | ||
self.sanctuaryShow = f (); | ||
} | ||
}(function() { | ||
} (function() { | ||
@@ -60,6 +60,11 @@ 'use strict'; | ||
return function(k) { | ||
return show(k) + ': ' + show(o[k]); | ||
return show (k) + ': ' + show (o[k]); | ||
}; | ||
} | ||
// sortedKeys :: Object -> Array String | ||
function sortedKeys(o) { | ||
return (Object.keys (o)).sort (); | ||
} | ||
//# show :: Showable a => a -> String | ||
@@ -111,49 +116,48 @@ //. | ||
function show(x) { | ||
if (seen.indexOf(x) >= 0) return '<Circular>'; | ||
if (seen.indexOf (x) >= 0) return '<Circular>'; | ||
switch (Object.prototype.toString.call(x)) { | ||
switch (Object.prototype.toString.call (x)) { | ||
case '[object Boolean]': | ||
return typeof x === 'object' ? | ||
'new Boolean (' + show(x.valueOf()) + ')' : | ||
x.toString(); | ||
'new Boolean (' + show (x.valueOf ()) + ')' : | ||
x.toString (); | ||
case '[object Number]': | ||
return typeof x === 'object' ? | ||
'new Number (' + show(x.valueOf()) + ')' : | ||
1 / x === -Infinity ? '-0' : x.toString(10); | ||
'new Number (' + show (x.valueOf ()) + ')' : | ||
1 / x === -Infinity ? '-0' : x.toString (10); | ||
case '[object String]': | ||
return typeof x === 'object' ? | ||
'new String (' + show(x.valueOf()) + ')' : | ||
JSON.stringify(x); | ||
'new String (' + show (x.valueOf ()) + ')' : | ||
JSON.stringify (x); | ||
case '[object Date]': | ||
return 'new Date (' + | ||
show(isNaN(x.valueOf()) ? NaN : x.toISOString()) + | ||
show (isNaN (x.valueOf ()) ? NaN : x.toISOString ()) + | ||
')'; | ||
case '[object Error]': | ||
return 'new ' + x.name + ' (' + show(x.message) + ')'; | ||
return 'new ' + x.name + ' (' + show (x.message) + ')'; | ||
case '[object Arguments]': | ||
return 'function () { return arguments; } (' + | ||
Array.prototype.map.call(x, show).join(', ') + | ||
(Array.prototype.map.call (x, show)).join (', ') + | ||
')'; | ||
case '[object Array]': | ||
seen.push(x); | ||
seen.push (x); | ||
try { | ||
return '[' + x.map(show).concat( | ||
Object.keys(x) | ||
.sort() | ||
.filter(function(k) { return !/^\d+$/.test(k); }) | ||
.map(entry(x)) | ||
).join(', ') + ']'; | ||
return '[' + ((x.map (show)).concat ( | ||
sortedKeys (x) | ||
.filter (function(k) { return !(/^\d+$/.test (k)); }) | ||
.map (entry (x)) | ||
)).join (', ') + ']'; | ||
} finally { | ||
seen.pop(); | ||
seen.pop (); | ||
} | ||
case '[object Object]': | ||
seen.push(x); | ||
seen.push (x); | ||
try { | ||
@@ -163,11 +167,27 @@ return ( | ||
(x.constructor == null || x.constructor.prototype !== x) ? | ||
x[$$show]() : | ||
'{' + Object.keys(x).sort().map(entry(x)).join(', ') + '}' | ||
x[$$show] () : | ||
'{' + ((sortedKeys (x)).map (entry (x))).join (', ') + '}' | ||
); | ||
} finally { | ||
seen.pop(); | ||
seen.pop (); | ||
} | ||
case '[object Set]': | ||
seen.push (x); | ||
try { | ||
return 'new Set (' + show (Array.from (x.values ())) + ')'; | ||
} finally { | ||
seen.pop (); | ||
} | ||
case '[object Map]': | ||
seen.push (x); | ||
try { | ||
return 'new Map (' + show (Array.from (x.entries ())) + ')'; | ||
} finally { | ||
seen.pop (); | ||
} | ||
default: | ||
return String(x); | ||
return String (x); | ||
@@ -174,0 +194,0 @@ } |
{ | ||
"name": "sanctuary-show", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Evaluable string representations", | ||
@@ -18,3 +18,3 @@ "license": "MIT", | ||
"devDependencies": { | ||
"sanctuary-scripts": "1.5.x" | ||
"sanctuary-scripts": "4.0.x" | ||
}, | ||
@@ -21,0 +21,0 @@ "scripts": { |
@@ -33,3 +33,3 @@ # sanctuary-show | ||
### <a name="show" href="https://github.com/sanctuary-js/sanctuary-show/blob/v1.0.0/index.js#L63">`show :: Showable a => a -> String`</a> | ||
### <a name="show" href="https://github.com/sanctuary-js/sanctuary-show/blob/v2.0.0/index.js#L68">`show :: Showable a => a -> String`</a> | ||
@@ -36,0 +36,0 @@ Returns a useful string representation of the given value. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8624
170