Skip to content

Commit c6caf1e

Browse files
Merge pull request #303 from sanctuary-js/davidchambers/inspect
provide custom ‘inspect’ behaviour in Node without using ‘require’
2 parents 2ac4810 + 6371406 commit c6caf1e

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
{
3838
"files": ["index.js"],
39-
"globals": {"Deno": false},
39+
"globals": {"Deno": false, "Symbol": false},
4040
"rules": {
4141
"multiline-comment-style": ["off"]
4242
}

index.js

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,9 @@
184184

185185
'use strict';
186186

187-
var util = {inspect: {}};
188-
189187
/* istanbul ignore else */
190188
if (typeof module === 'object' && typeof module.exports === 'object') {
191-
module.exports = f (require ('util'),
192-
require ('sanctuary-either'),
189+
module.exports = f (require ('sanctuary-either'),
193190
require ('sanctuary-show'),
194191
require ('sanctuary-type-classes'),
195192
require ('sanctuary-type-identifiers'));
@@ -198,18 +195,15 @@
198195
'sanctuary-show',
199196
'sanctuary-type-classes',
200197
'sanctuary-type-identifiers'],
201-
function(Either, show, Z, type) {
202-
return f (util, Either, show, Z, type);
203-
});
198+
f);
204199
} else {
205-
self.sanctuaryDef = f (util,
206-
self.sanctuaryEither,
200+
self.sanctuaryDef = f (self.sanctuaryEither,
207201
self.sanctuaryShow,
208202
self.sanctuaryTypeClasses,
209203
self.sanctuaryTypeIdentifiers);
210204
}
211205

212-
} (function(util, Either, show, Z, type) {
206+
} (function(Either, show, Z, type) {
213207

214208
'use strict';
215209

@@ -220,10 +214,6 @@
220214
var hasOwnProperty = Object.prototype.hasOwnProperty;
221215
var toString = Object.prototype.toString;
222216

223-
var inspect = typeof util.inspect.custom === 'symbol' ?
224-
util.inspect.custom :
225-
/* istanbul ignore next */ 'inspect';
226-
227217
// Left :: a -> Either a b
228218
var Left = Either.Left;
229219

@@ -2780,7 +2770,14 @@
27802770
} :
27812771
wrapNext ({}, [], 0);
27822772

2783-
wrapped[inspect] = wrapped.toString = always0 (typeSignature (typeInfo));
2773+
wrapped.toString = always0 (typeSignature (typeInfo));
2774+
/* istanbul ignore else */
2775+
if (
2776+
typeof process !== 'undefined' &&
2777+
process != null &&
2778+
process.versions != null &&
2779+
process.versions.node != null
2780+
) wrapped[Symbol.for ('nodejs.util.inspect.custom')] = wrapped.toString;
27842781
/* istanbul ignore if */
27852782
if (typeof Deno !== 'undefined') {
27862783
if (Deno != null && typeof Deno.customInspect === 'symbol') {

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
"release": "sanctuary-release",
1414
"test": "npm run lint && sanctuary-test && npm run doctest"
1515
},
16+
"engines": {
17+
"node": ">=10.12.0"
18+
},
1619
"dependencies": {
1720
"sanctuary-either": "2.1.0",
1821
"sanctuary-show": "2.0.0",

0 commit comments

Comments
 (0)