]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Make nodejs util inspect happy
authorbluelovers <codelovers@users.sourceforge.net>
Thu, 7 Mar 2019 14:48:38 +0000 (22:48 +0800)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 24 Apr 2020 15:20:50 +0000 (18:20 +0300)
Newer versions of nodejs use a special symbol for inspecting a value
instead of the old-school obj.inspect function.

src/lib/moment/prototype.js

index bd8fff79c201e4e588c824e97296cffa14d79981..1d0d08d14e937bd7dca4699f235881e592238503 100644 (file)
@@ -51,6 +51,11 @@ proto.toObject          = toObject;
 proto.toDate            = toDate;
 proto.toISOString       = toISOString;
 proto.inspect           = inspect;
+if (typeof Symbol !== undefined && Symbol.for != null) {
+    proto[Symbol.for('nodejs.util.inspect.custom')] = function () {
+        return 'Moment<' + this.format() + '>';
+    };
+}
 proto.toJSON            = toJSON;
 proto.toString          = toString;
 proto.unix              = unix;