Skip to content
Merged
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
49 changes: 49 additions & 0 deletions lib/node_modules/@stdlib/repl/lib/drain.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
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' );
Expand Down Expand Up @@ -118,6 +121,46 @@
return format( '%s(%d) [%s]', ctor, values.length, str );
}

/**
* Converts an integer instance to an annotated string.
*
* @private
* @param {(Uint64|Int64)} value - input value
* @returns {string} output string
*
* @example
* var Uint64 = require( '@stdlib/number/uint64/ctor' );
*
* var x = new Uint64( 1 );
* // returns <Uint64>
*
* var str = integer2string( x );
* // returns '[Uint64: 1n]'
*/
function integer2string( value ) {
return format( '[%s: %sn]', constructorName( value ), 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' );
*
* var z = new Complex128( 1.0, 2.0 );
* // returns <Complex128>
*
* var str = complex2string( z );
* // returns '[Complex128: 1 + 2i]'
*/
function complex2string( value ) {
return format( '[%s: %s]', constructorName( value ), value.toString() );
}


// MAIN //

Expand Down Expand Up @@ -209,9 +252,9 @@
if ( code.silent === false && res !== void 0 ) {
pre = replace( repl._outputPrompt, '%d', (repl._count+1).toString() );

// TODO: pretty printing (can defer to `util.inspect` for now, but will invariably want more control over this later, possibly including default configuration, etc, either at startup, during runtime, or according to an external configuration file)

Check warning on line 255 in lib/node_modules/@stdlib/repl/lib/drain.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: pretty printing (can defer to...'
if ( isndarrayLike( res ) ) {
tmp = res.toString(); // FIXME: this is a hack in order to avoid printing private ndarray properties in the REPL, as done by the built-in `util.inspect`. Ideally, we'd roll our own inspector which specifically accommodates stdlib's ndarray and other specialized classes.

Check warning on line 257 in lib/node_modules/@stdlib/repl/lib/drain.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: this is a hack in order to avoid...'
} else if (
isBooleanArray( res ) ||
isComplex128Array( res ) ||
Expand All @@ -219,8 +262,14 @@
isInt64Array( res ) ||
isUint64Array( res )
) {
// 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.

Check warning on line 265 in lib/node_modules/@stdlib/repl/lib/drain.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: this is a hack in order to avoid...'
tmp = array2string( constructorName( res ), copy2primitives( res ) ); // eslint-disable-line max-len
} 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.

Check warning on line 268 in lib/node_modules/@stdlib/repl/lib/drain.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: this is a hack in order to avoid...'
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.

Check warning on line 271 in lib/node_modules/@stdlib/repl/lib/drain.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'fixme' comment: 'FIXME: this is a hack in order to avoid...'
tmp = complex2string( res );
} else {
tmp = inspect( repl._ans );
}
Expand Down Expand Up @@ -286,7 +335,7 @@
if ( code.silent === false && ( res !== void 0 || results !== void 0 ) ) { // eslint-disable-line max-len
pre = replace( repl._outputPrompt, '%d', (repl._count+1).toString() );

// TODO: pretty printing (can defer to `util.inspect` for now, but will invariably want more control over this later, possibly including default configuration, etc, either at startup, during runtime, or according to an external configuration file)

Check warning on line 338 in lib/node_modules/@stdlib/repl/lib/drain.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected 'todo' comment: 'TODO: pretty printing (can defer to...'
repl._ostream.write( pre+inspect( repl._ans )+'\n' );
}
// Finish processing:
Expand Down
Loading