From b5cc87581862eb4a85a339ed77365990a0efd53d Mon Sep 17 00:00:00 2001 From: Abdul Kaium Date: Sun, 25 Oct 2026 22:00:00 +0600 Subject: [PATCH 1/3] feat: add pretty print support for Int64, Uint64, and Complex instances --- lib/node_modules/@stdlib/repl/lib/drain.js | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/node_modules/@stdlib/repl/lib/drain.js b/lib/node_modules/@stdlib/repl/lib/drain.js index 48553b1ac0d3..336e38dd022a 100644 --- a/lib/node_modules/@stdlib/repl/lib/drain.js +++ b/lib/node_modules/@stdlib/repl/lib/drain.js @@ -30,6 +30,9 @@ var isUint64Array = require( '@stdlib/assert/is-uint64array' ); var isBooleanArray = require( '@stdlib/assert/is-booleanarray' ); var isComplex128Array = require( '@stdlib/assert/is-complex128array' ); var isComplex64Array = require( '@stdlib/assert/is-complex64array' ); +var isInt64 = require( '@stdlib/assert/is-int64' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isComplex = require( '@stdlib/assert/is-complex' ); var resolveGetter = require( '@stdlib/array/base/resolve-getter' ); var join = require( '@stdlib/array/base/join' ); var constructorName = require( '@stdlib/utils/constructor-name' ); @@ -118,6 +121,39 @@ function array2string( ctor, values ) { return format( '%s(%d) [%s]', ctor, values.length, str ); } +/** +* Converts a 64-bit integer or complex number instance to an annotated string. +* +* @private +* @param {(Uint64|Int64|Complex64|Complex128)} value - input value +* @returns {string} output string +* +* @example +* var Uint64 = require( '@stdlib/number/uint64/ctor' ); +* +* var x = new Uint64( 1 ); +* // returns +* +* var str = instance2string( x ); +* // returns '[Uint64: 1n]' +* +* @example +* var Complex128 = require( '@stdlib/complex/float64/ctor' ); +* +* var z = new Complex128( 1.0, 2.0 ); +* // returns +* +* var str = instance2string( z ); +* // returns '[Complex128: 1 + 2i]' +*/ +function instance2string( value ) { + var ctor = constructorName( value ); + if ( ctor === 'Int64' || ctor === 'Uint64' ) { + return format( '[%s: %sn]', ctor, value.toString() ); + } + return format( '[%s: %s]', ctor, value.toString() ); +} + // MAIN // @@ -221,6 +257,13 @@ function drain( repl ) { ) { // FIXME: this is a hack in order to avoid things like `BooleanArray {}` which doesn't allow easy inspection of array contents. Ideally, we'd roll our own inspector to accommodate stdlib's specialized array classes. tmp = array2string( constructorName( res ), copy2primitives( res ) ); // eslint-disable-line max-len + } else if ( + isInt64( res ) || + isUint64( res ) || + isComplex( res ) + ) { + // FIXME: this is a hack in order to avoid things like `Uint64 {}` which doesn't allow easy inspection of contents. Ideally, we'd roll our own inspector to accommodate stdlib's specialized scalar classes. + tmp = instance2string( res ); } else { tmp = inspect( repl._ans ); } From 77a1fa89588c4b61cf6e24ed88597fc6c6076ec4 Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 27 Oct 2026 01:55:40 +0100 Subject: [PATCH 2/3] refactor: move serialization logic to separate functions Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/drain.js | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/drain.js b/lib/node_modules/@stdlib/repl/lib/drain.js index 336e38dd022a..655fc0279376 100644 --- a/lib/node_modules/@stdlib/repl/lib/drain.js +++ b/lib/node_modules/@stdlib/repl/lib/drain.js @@ -122,10 +122,10 @@ function array2string( ctor, values ) { } /** -* Converts a 64-bit integer or complex number instance to an annotated string. +* Converts an integer instance to an annotated string. * * @private -* @param {(Uint64|Int64|Complex64|Complex128)} value - input value +* @param {(Uint64|Int64)} value - input value * @returns {string} output string * * @example @@ -134,8 +134,19 @@ function array2string( ctor, values ) { * var x = new Uint64( 1 ); * // returns * -* var str = instance2string( x ); +* var str = integer2string( x ); * // returns '[Uint64: 1n]' +*/ +function integer2string( value ) { + return format( '[%s: %sn]', ctor, value.toString() ); +} + +/** +* Converts a complex number instance to an annotated string. +* +* @private +* @param {(Complex64|Complex128)} value - input value +* @returns {string} output string * * @example * var Complex128 = require( '@stdlib/complex/float64/ctor' ); @@ -143,14 +154,10 @@ function array2string( ctor, values ) { * var z = new Complex128( 1.0, 2.0 ); * // returns * -* var str = instance2string( z ); +* var str = complex2string( z ); * // returns '[Complex128: 1 + 2i]' */ -function instance2string( value ) { - var ctor = constructorName( value ); - if ( ctor === 'Int64' || ctor === 'Uint64' ) { - return format( '[%s: %sn]', ctor, value.toString() ); - } +function complex2string( value ) { return format( '[%s: %s]', ctor, value.toString() ); } @@ -257,13 +264,12 @@ function drain( repl ) { ) { // FIXME: this is a hack in order to avoid things like `BooleanArray {}` which doesn't allow easy inspection of array contents. Ideally, we'd roll our own inspector to accommodate stdlib's specialized array classes. tmp = array2string( constructorName( res ), copy2primitives( res ) ); // eslint-disable-line max-len - } else if ( - isInt64( res ) || - isUint64( res ) || - isComplex( res ) - ) { + } else if ( isInt64( res ) || isUint64( res ) ) { // FIXME: this is a hack in order to avoid things like `Uint64 {}` which doesn't allow easy inspection of contents. Ideally, we'd roll our own inspector to accommodate stdlib's specialized scalar classes. - tmp = instance2string( res ); + tmp = integer2string( res ); + } else if ( isComplex( res ) ) { + // FIXME: this is a hack in order to avoid things like `Complex128 {}` which doesn't allow easy inspection of contents. Ideally, we'd roll our own inspector to accommodate stdlib's specialized scalar classes. + tmp = complex2string( res ); } else { tmp = inspect( repl._ans ); } From b1da458c87cb0dafaa46afe06b61764c45db8e5c Mon Sep 17 00:00:00 2001 From: Athan Date: Tue, 27 Oct 2026 01:58:51 +0100 Subject: [PATCH 3/3] Apply batched suggestions from code review Co-authored-by: Athan Signed-off-by: Athan --- lib/node_modules/@stdlib/repl/lib/drain.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/repl/lib/drain.js b/lib/node_modules/@stdlib/repl/lib/drain.js index 655fc0279376..0336f883d10f 100644 --- a/lib/node_modules/@stdlib/repl/lib/drain.js +++ b/lib/node_modules/@stdlib/repl/lib/drain.js @@ -138,7 +138,7 @@ function array2string( ctor, values ) { * // returns '[Uint64: 1n]' */ function integer2string( value ) { - return format( '[%s: %sn]', ctor, value.toString() ); + return format( '[%s: %sn]', constructorName( value ), value.toString() ); } /** @@ -158,7 +158,7 @@ function integer2string( value ) { * // returns '[Complex128: 1 + 2i]' */ function complex2string( value ) { - return format( '[%s: %s]', ctor, value.toString() ); + return format( '[%s: %s]', constructorName( value ), value.toString() ); }