Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use global symbol to customize string representations in Node.js REPL #39

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
{
"files": ["index.js"],
"globals": {"Deno": false},
"globals": {"Deno": false, "process": false},
"rules": {
"multiline-comment-style": ["off"]
}
Expand Down
45 changes: 23 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@

'use strict';

const util = {inspect: {}};

/* istanbul ignore else */
if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = f (require ('util'),
require ('sanctuary-show'),
module.exports = f (require ('sanctuary-show'),
require ('sanctuary-type-classes'));
} else if (typeof define === 'function' && define.amd != null) {
define (['sanctuary-show', 'sanctuary-type-classes'],
(show, Z) => f (util, show, Z));
define (['sanctuary-show', 'sanctuary-type-classes'], f);
} else {
self.sanctuaryEither = f (util,
self.sanctuaryShow,
self.sanctuaryEither = f (self.sanctuaryShow,
self.sanctuaryTypeClasses);
}

}) ((util, show, Z) => {
}) ((show, Z) => {

'use strict';

Expand Down Expand Up @@ -88,19 +83,25 @@
/* eslint-enable key-spacing */
};

{
const {custom} = util.inspect; // added in Node.js v6.6.0
/* istanbul ignore else */
if (typeof custom === 'symbol') {
Left$prototype[custom] = Left$prototype$show;
Right$prototype[custom] = Right$prototype$show;
}
/* istanbul ignore if */
if (typeof Deno !== 'undefined') {
if (Deno != null && typeof Deno.customInspect === 'symbol') {
Left$prototype[Deno.customInspect] = Left$prototype$show;
Right$prototype[Deno.customInspect] = Right$prototype$show;
}
/* istanbul ignore else */
if (
typeof process !== 'undefined' &&
process != null &&
process.versions != null &&
process.versions.node != null
) {
Left$prototype[
Symbol.for ('nodejs.util.inspect.custom') // added in Node.js v10.12.0
] = Left$prototype$show;
Right$prototype[
Symbol.for ('nodejs.util.inspect.custom') // added in Node.js v10.12.0
] = Right$prototype$show;
}
/* istanbul ignore if */
if (typeof Deno !== 'undefined') {
if (Deno != null && typeof Deno.customInspect === 'symbol') {
Left$prototype[Deno.customInspect] = Left$prototype$show;
Right$prototype[Deno.customInspect] = Right$prototype$show;
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"/package.json"
],
"engines": {
"node": ">=6.6.0"
"node": ">=10.12.0"
},
"dependencies": {
"sanctuary-show": "2.0.0",
Expand Down