From 39651ea5cd0040522985ecce19a81a9ec24cc6fb Mon Sep 17 00:00:00 2001 From: kgryte <2643044+kgryte@users.noreply.github.com> Date: Mon, 12 May 2025 01:48:37 +0000 Subject: [PATCH] chore: cleanup coverage directories Signed-off-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com> --- ml/incr/sgd-regression/loss/coverage.ndjson | 1 - .../loss/epsilon_insensitive.js.html | 262 ------ ml/incr/sgd-regression/loss/huber.js.html | 274 ------ ml/incr/sgd-regression/loss/index.html | 146 --- .../sgd-regression/loss/squared_error.js.html | 247 ----- repl/commands/__done__.js.html | 256 ------ repl/commands/add_theme.js.html | 274 ------ repl/commands/alias2pkg.js.html | 343 ------- repl/commands/alias2related.js.html | 379 -------- repl/commands/ans.js.html | 232 ----- repl/commands/assignfrom.js.html | 394 -------- repl/commands/assignin.js.html | 424 --------- repl/commands/citation.js.html | 328 ------- repl/commands/clear.js.html | 223 ----- repl/commands/clear_history.js.html | 223 ----- repl/commands/clear_user_docs.js.html | 715 --------------- repl/commands/clear_vars.js.html | 256 ------ repl/commands/clear_workspace.js.html | 844 ----------------- repl/commands/contributor.js.html | 313 ------- repl/commands/copyright.js.html | 253 ------ repl/commands/coverage.ndjson | 1 - repl/commands/credits.js.html | 262 ------ repl/commands/current_workspace.js.html | 232 ----- repl/commands/deeprerequire.js.html | 400 -------- repl/commands/delete_theme.js.html | 271 ------ repl/commands/delete_workspace.js.html | 367 -------- repl/commands/donate.js.html | 301 ------- repl/commands/evalin.js.html | 514 ----------- repl/commands/example.js.html | 646 ------------- repl/commands/get_theme.js.html | 295 ------ repl/commands/help.js.html | 559 ------------ repl/commands/index.html | 851 ------------------ repl/commands/info.js.html | 514 ----------- repl/commands/is_keyword.js.html | 394 -------- repl/commands/is_workspace.js.html | 343 ------- repl/commands/keybindings.js.html | 328 ------- repl/commands/license_text.js.html | 238 ----- repl/commands/load.js.html | 436 --------- repl/commands/load_workspace.js.html | 592 ------------ repl/commands/pager.js.html | 277 ------ repl/commands/presentation_start.js.html | 781 ---------------- repl/commands/presentation_stop.js.html | 451 ---------- repl/commands/quit.js.html | 256 ------ repl/commands/rename_theme.js.html | 274 ------ repl/commands/rename_workspace.js.html | 439 --------- repl/commands/rerequire.js.html | 319 ------- repl/commands/rerun.js.html | 571 ------------ repl/commands/reset.js.html | 223 ----- repl/commands/set_keybinding.js.html | 367 -------- repl/commands/settings.js.html | 442 --------- repl/commands/themes.js.html | 226 ----- repl/commands/tutorial.js.html | 604 ------------- repl/commands/user_doc.js.html | 409 --------- repl/commands/vars.js.html | 265 ------ repl/commands/vars_workspace.js.html | 727 --------------- repl/commands/workspace.js.html | 493 ---------- repl/commands/workspaces.js.html | 451 ---------- 57 files changed, 21506 deletions(-) delete mode 100644 ml/incr/sgd-regression/loss/coverage.ndjson delete mode 100644 ml/incr/sgd-regression/loss/epsilon_insensitive.js.html delete mode 100644 ml/incr/sgd-regression/loss/huber.js.html delete mode 100644 ml/incr/sgd-regression/loss/index.html delete mode 100644 ml/incr/sgd-regression/loss/squared_error.js.html delete mode 100644 repl/commands/__done__.js.html delete mode 100644 repl/commands/add_theme.js.html delete mode 100644 repl/commands/alias2pkg.js.html delete mode 100644 repl/commands/alias2related.js.html delete mode 100644 repl/commands/ans.js.html delete mode 100644 repl/commands/assignfrom.js.html delete mode 100644 repl/commands/assignin.js.html delete mode 100644 repl/commands/citation.js.html delete mode 100644 repl/commands/clear.js.html delete mode 100644 repl/commands/clear_history.js.html delete mode 100644 repl/commands/clear_user_docs.js.html delete mode 100644 repl/commands/clear_vars.js.html delete mode 100644 repl/commands/clear_workspace.js.html delete mode 100644 repl/commands/contributor.js.html delete mode 100644 repl/commands/copyright.js.html delete mode 100644 repl/commands/coverage.ndjson delete mode 100644 repl/commands/credits.js.html delete mode 100644 repl/commands/current_workspace.js.html delete mode 100644 repl/commands/deeprerequire.js.html delete mode 100644 repl/commands/delete_theme.js.html delete mode 100644 repl/commands/delete_workspace.js.html delete mode 100644 repl/commands/donate.js.html delete mode 100644 repl/commands/evalin.js.html delete mode 100644 repl/commands/example.js.html delete mode 100644 repl/commands/get_theme.js.html delete mode 100644 repl/commands/help.js.html delete mode 100644 repl/commands/index.html delete mode 100644 repl/commands/info.js.html delete mode 100644 repl/commands/is_keyword.js.html delete mode 100644 repl/commands/is_workspace.js.html delete mode 100644 repl/commands/keybindings.js.html delete mode 100644 repl/commands/license_text.js.html delete mode 100644 repl/commands/load.js.html delete mode 100644 repl/commands/load_workspace.js.html delete mode 100644 repl/commands/pager.js.html delete mode 100644 repl/commands/presentation_start.js.html delete mode 100644 repl/commands/presentation_stop.js.html delete mode 100644 repl/commands/quit.js.html delete mode 100644 repl/commands/rename_theme.js.html delete mode 100644 repl/commands/rename_workspace.js.html delete mode 100644 repl/commands/rerequire.js.html delete mode 100644 repl/commands/rerun.js.html delete mode 100644 repl/commands/reset.js.html delete mode 100644 repl/commands/set_keybinding.js.html delete mode 100644 repl/commands/settings.js.html delete mode 100644 repl/commands/themes.js.html delete mode 100644 repl/commands/tutorial.js.html delete mode 100644 repl/commands/user_doc.js.html delete mode 100644 repl/commands/vars.js.html delete mode 100644 repl/commands/vars_workspace.js.html delete mode 100644 repl/commands/workspace.js.html delete mode 100644 repl/commands/workspaces.js.html diff --git a/ml/incr/sgd-regression/loss/coverage.ndjson b/ml/incr/sgd-regression/loss/coverage.ndjson deleted file mode 100644 index 5bcba47d47..0000000000 --- a/ml/incr/sgd-regression/loss/coverage.ndjson +++ /dev/null @@ -1 +0,0 @@ -[176,176,100,12,12,100,3,3,100,176,176,100,"3dd8cb379ea22c4a92d610d146cdd662d3187e27","2025-05-06 22:36:48 -0400"] diff --git a/ml/incr/sgd-regression/loss/epsilon_insensitive.js.html b/ml/incr/sgd-regression/loss/epsilon_insensitive.js.html deleted file mode 100644 index 7c4e4dc143..0000000000 --- a/ml/incr/sgd-regression/loss/epsilon_insensitive.js.html +++ /dev/null @@ -1,262 +0,0 @@ - - - - -
-- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 | 3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -1x -3x -1x -1x -3x -3x -3x -3x -3x -3x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var regularize = require( './../regularize.js' ); - - -// MAIN // - -/** -* Given a new observation `(x,y)`, updates the weights using the epsilon-insensitive loss. -* -* ## Notes -* -* The penalty of the epsilon-insensitive loss is the absolute value of the dot product of the weights and `x` minus `y` whenever the absolute error exceeds epsilon, and zero otherwise. -* -* @private -* @param {WeightVector} weights - current model coefficients -* @param {NumericArray} x - feature vector -* @param {number} y - response value -* @param {PositiveNumber} eta - current learning rate -* @param {NonNegativeNumber} lambda - regularization parameter -* @param {PositiveNumber} epsilon - insensitivity parameter -*/ -function epsilonInsensitiveLoss( weights, x, y, eta, lambda, epsilon ) { - var p = weights.innerProduct( x ) - y; - - // Perform L2 regularization... - regularize( weights, lambda, eta ); - - if ( p > epsilon ) { - weights.add( x, -eta ); - } else if ( p < -epsilon ) { - weights.add( x, +eta ); - } -} - - -// EXPORTS // - -module.exports = epsilonInsensitiveLoss; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 | 3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -1x -3x -1x -1x -1x -1x -3x -3x -3x -3x -3x -3x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var regularize = require( './../regularize.js' ); - - -// MAIN // - -/** -* Given a new observation `(x,y)`, updates the weights using the [Huber loss][1] function. -* -* ## Notes -* -* The Huber loss uses squared-error loss for observations with error smaller than epsilon in magnitude and linear loss above that in order to decrease the influence of outliers on the model fit. -* -* [1]: https://en.wikipedia.org/wiki/Huber_loss -* -* @private -* @param {WeightVector} weights - current model coefficients -* @param {NumericArray} x - feature vector -* @param {number} y - response value -* @param {PositiveNumber} eta - current learning rate -* @param {NonNegativeNumber} lambda - regularization parameter -* @param {PositiveNumber} epsilon - insensitivity parameter -*/ -function huberLoss( weights, x, y, eta, lambda, epsilon ) { - var p = weights.innerProduct( x ) - y; - - // Perform L2 regularization... - regularize( weights, lambda, eta ); - - if ( p > epsilon ) { - weights.add( x, -eta ); - } else if ( p < -epsilon ) { - weights.add( x, +eta ); - } else { - weights.add( x, -eta * p ); - } -} - - -// EXPORTS // - -module.exports = huberLoss; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
---|---|---|---|---|---|---|---|---|---|
epsilon_insensitive.js | -
-
- |
- 100% | -59/59 | -100% | -5/5 | -100% | -1/1 | -100% | -59/59 | -
huber.js | -
-
- |
- 100% | -63/63 | -100% | -5/5 | -100% | -1/1 | -100% | -63/63 | -
squared_error.js | -
-
- |
- 100% | -54/54 | -100% | -2/2 | -100% | -1/1 | -100% | -54/54 | -
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 | 3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -3x -6x -6x -6x -6x -6x -6x -6x -6x -3x -3x -3x -3x -3x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var regularize = require( './../regularize.js' ); - - -// MAIN // - -/** -* Given a new observation `(x,y)`, updates the weights using the squared error loss. -* -* ## Notes -* -* The squared error loss is defined as the squared difference of the observed and fitted value. -* -* @private -* @param {WeightVector} weights - current model coefficients -* @param {NumericArray} x - feature vector -* @param {number} y - response value -* @param {PositiveNumber} eta - current learning rate -* @param {NonNegativeNumber} lambda - regularization parameter -*/ -function squaredErrorLoss( weights, x, y, eta, lambda ) { - var loss = y - weights.innerProduct( x ); - - // Perform L2 regularization... - regularize( weights, lambda, eta ); - - weights.add( x, ( eta * loss ) ); -} - - -// EXPORTS // - -module.exports = squaredErrorLoss; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `__done__` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Callback invoked to confirm that a command has finished executing. - * - * @private - * @param {(Error|null)} [error] - execution error - * @param {*} [results] - command results - * @returns {void} - */ - function onCommand( error, results ) { - if ( arguments.length === 0 ) { - return repl._done(); - } - if ( arguments.length === 1 ) { - return repl._done( error ); - } - repl._done( error, results ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `addTheme` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Adds a syntax highlighting color theme. - * - * @private - * @param {string} name - theme name - * @param {Object} theme - theme object - * @returns {void} - */ - function onCommand( name, theme ) { - try { - repl.addTheme( name, theme ); - } catch ( err ) { - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - return; - } - log( repl, format( '\nSuccessfully added theme `%s`.', name ) ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var alias2pkg = require( '@stdlib/namespace/alias2pkg' ); -var indexOf = require( './../index_of.js' ); -var alias2string = require( './../alias_to_string.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `alias2pkg` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns the package name corresponding to a provided alias. - * - * @private - * @param {*} alias - alias - * @returns {(string|void)} package name - */ - function onCommand( alias ) { - var aliases; - var out; - var N; - var i; - - aliases = repl._aliases; - N = aliases.length; - - if ( isString( alias ) ) { - out = alias2pkg( alias ); - } - // If provided an `alias` which is not a string or we failed to resolve a package name based on the provided string value, we try to resolve a string alias (and subsequently a corresponding package name) by searching the list of cached references of global variables/properties... - if ( !out ) { - i = indexOf( N/2, aliases, 2, 1, alias ); - if ( i >= 0 ) { - out = alias2pkg( aliases[ i-1 ] ); - } - } - // If we failed to resolve a package name and the provided value is an object, try finding a provided value's constructor (e.g., if provided a `Uint32Array`, try finding the package name for `Uint32Array`)... - if ( !out && typeof alias === 'object' && alias !== null && alias.constructor ) { - i = indexOf( N/2, aliases, 2, 1, alias.constructor ); - if ( i >= 0 ) { - out = alias2pkg( aliases[ i-1 ] ); - } - } - if ( out ) { - return out; - } - repl._ostream.write( 'Error: unrecognized alias or alias is not associated with a package (such as a\nREPL-specific command). Alias: `'+alias2string( alias )+'`.\n' ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var alias2related = require( '@stdlib/namespace/alias2related' ); -var indexOf = require( './../index_of.js' ); -var alias2string = require( './../alias_to_string.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `alias2related` command. -* -* @private -* @param {REPL} repl - REPL instance -* @param {ArrayArray} cmds - REPL command list -* @returns {Function} callback -*/ -function command( repl, cmds ) { - return onCommand; - - /** - * Returns aliases related to a provided alias. - * - * @private - * @param {*} alias - alias - * @returns {(StringArray|void)} related packages as a newline-delimited list - */ - function onCommand( alias ) { - var aliases; - var out; - var N; - var i; - - aliases = repl._aliases; - N = aliases.length; - - if ( isString( alias ) ) { - out = alias2related( alias ); - } - // If unable to resolve related aliases, check if we were provided a reference to a REPL-specific command... - if ( !out ) { - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 1 ] === alias ) { - out = alias2related( cmds[ i ][ 0 ] ); - } - } - } - // If provided an `alias` which is not a string or we failed to resolve related aliases based on the provided string value, we try to resolve a string alias (and subsequently related aliases) by searching the list of cached references of global variables/properties... - if ( !out ) { - i = indexOf( N/2, aliases, 2, 1, alias ); - if ( i >= 0 ) { - out = alias2related( aliases[ i-1 ] ); - } - } - // If we failed to resolve related aliases and the provided value is an object, try finding a provided value's constructor (e.g., if provided a `Uint32Array`, try finding related aliases for `Uint32Array`)... - if ( !out && typeof alias === 'object' && alias !== null && alias.constructor ) { - i = indexOf( N/2, aliases, 2, 1, alias.constructor ); - if ( i >= 0 ) { - out = alias2related( aliases[ i-1 ] ); - } - } - if ( out === void 0 || out === null ) { - repl._ostream.write( 'Error: unrecognized alias. Alias: `'+alias2string( alias )+'`.\n' ); - return; - } - if ( out.length ) { - return out; - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `ans` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns the result of the last successfully executed command. - * - * @private - * @returns {*} result - */ - function onCommand() { - return repl._ans; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:assignfrom' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `assignfrom` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Reads a value from a specified workspace. - * - * @private - * @param {string} workspace - workspace name - * @param {(string|symbol)} variable - variable name - * @returns {*} assigned value - */ - function onCommand( workspace, variable ) { - var list; - var desc; - var err; - var i; - if ( !isString( workspace ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( workspace === repl._currentWorkspace ) { - return repl._context[ variable ]; - } - if ( !hasOwnProp( repl._workspaces, workspace ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - list = repl._workspaces[ workspace ]; - for ( i = 0; i < list.length; i += 2 ) { - if ( list[ i ] === variable ) { - desc = list[ i+1 ]; - - // Check if descriptor is an accessor descriptor: - if ( hasOwnProp( desc, 'get' ) ) { - // WARNING: the `this` context is not defined, as the variable is not actually bound to a global instance! - return desc.get.call( null ); - } - // Check if the descriptor is a data descriptor: - if ( hasOwnProp( desc, 'value' ) ) { - return desc.value; - } - // Variable must be write-only: - err = new Error( format( 'invalid operation. Cannot read from write-only variable `%s`.', variable ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:assignin' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `assignin` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Assigns a value to a variable in a specified workspace. - * - * @private - * @param {string} workspace - workspace name - * @param {(string|symbol)} variable - variable name - * @param {*} value - value to assign - * @returns {void} - */ - function onCommand( workspace, variable, value ) { - var list; - var desc; - var err; - var i; - if ( !isString( workspace ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( workspace === repl._currentWorkspace ) { - repl._context[ variable ] = value; - return; - } - if ( !hasOwnProp( repl._workspaces, workspace ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - list = repl._workspaces[ workspace ]; - for ( i = 0; i < list.length; i += 2 ) { - if ( list[ i ] === variable ) { - desc = list[ i+1 ]; - - // Check if descriptor has a setter: - if ( typeof desc.set === 'function' ) { - // WARNING: the `this` context is not defined, as the variable is not actually bound to a global instance! - desc.set.call( null, value ); - return; - } - // Check if the variable is read-only: - if ( typeof desc.get === 'function' || desc.writable === false ) { - err = new Error( format( 'Cannot assign to read only property %s of object #<Object>', variable ) ); // Note: this mirrors the built-in environment error message - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - desc.value = value; - return; - } - } - // Create a workspace variable by defining a property descriptor equivalent to when a user defines a variable within a global context (e.g., `var x = 3.14`): - list.push( variable, { - 'configurable': true, - 'enumerable': true, - 'writable': true, - 'value': value - }); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var currentYear = require( '@stdlib/time/current-year' ); - - -// VARIABLES // - -var YEAR = currentYear(); - -// FIXME: include software DOI! -var INFO = [ - '', - ' To cite stdlib in publications, use:', - '', - ' The Stdlib Authors ('+YEAR+'). stdlib: a standard library for JavaScript and', - ' Node.js with an emphasis on numerical and scientific computing.', - ' <https://github.com/stdlib-js/stdlib>.', - '', - ' For LaTeX users, the following is a suitable BibTeX entry:', - '', - ' @manual{<id>,', - ' author = {The Stdlib Authors},', - ' title = {{stdlib: a standard library for JavaScript and Node.js', - ' with an emphasis on numerical and scientific computing}},', - ' year = {'+YEAR+'},', - ' url = {https://github.com/stdlib-js/stdlib},', - ' }', - '', - ' We have invested considerable time and effort in creating stdlib, please cite', - ' stdlib when using it for data analysis and development.', - '', - '' -].join( '\n' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `citation` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Prints citation information. - * - * @private - */ - function onCommand() { - repl._ostream.write( INFO ); // eslint-disable-line no-underscore-dangle - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `clear` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Clears the entire REPL screen and scrollback history. - * - * @private - */ - function onCommand() { - repl.clear(); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `clearHistory` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Clears a REPL's history. - * - * @private - */ - function onCommand() { - repl.clearHistory(); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var isArrayLike = require( '@stdlib/assert/is-array-like-object' ); -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); -var contains = require( './../contains.js' ); -var log = require( './../log.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:clear_userdocs' ); -var FILTERS = [ - 'alias', - 'value', - '*' -]; - - -// FUNCTIONS // - -/** -* Filters user-defined documentation based on include and exclude filters. -* -* @private -* @param {Array} list - documentation to filter -* @param {string} type - filter type -* @param {(RegExp|ArrayLikeObject|void)} include - name inclusion filter -* @param {boolean} isArrInc - boolean indicating whether the inclusion filter is an array -* @param {(RegExp|ArrayLikeObject|void)} exclude - name exclusion filter -* @param {boolean} isArrExc - boolean indicating whether the exclusion filter is an array -* @returns {Array} reference to input array -*/ -function filter( list, type, include, isArrInc, exclude, isArrExc ) { - var ALIAS_FLG; - var VALUE_FLG; - var FLG; - var v; - var i; - var j; - - if ( type === '*' ) { - ALIAS_FLG = true; - VALUE_FLG = true; - } else if ( type === 'alias' ) { - ALIAS_FLG = true; - } else { - VALUE_FLG = true; - } - // Perform list "compression" without using temporary data structures... - j = 0; - for ( i = 0; i < list.length; i += 3 ) { - v = list[ i ]; - FLG = false; - - // Note: exclude/include order matters!!! - if ( exclude ) { - if ( isArrExc ) { - if ( ALIAS_FLG && contains( exclude, v ) ) { - // The alias is in the explicit exclude list: - FLG = true; - } else if ( VALUE_FLG && contains( exclude, list[ i+1 ] ) ) { - // The value is in the explicit exclude list: - FLG = true; - } - } else if ( exclude.test( v ) ) { - // The alias passes the exclusion test: - FLG = true; - } - } - // Only apply inclusion filters if the alias has not been already excluded from deletion... - if ( FLG === false && include ) { - if ( isArrInc ) { - if ( ALIAS_FLG && !contains( include, v ) ) { - // The alias is *not* in the include list: - FLG = true; - } else if ( VALUE_FLG && !contains( include, list[ i+1 ] ) ) { - // The value is *not* in the include list: - FLG = true; - } - } else if ( !include.test( v ) ) { - // The alias does *not* pass the include test: - FLG = true; - } - } - if ( FLG ) { - list[ j ] = list[ i ]; - list[ j+1 ] = list[ i+1 ]; - list[ j+2 ] = list[ i+2 ]; - j += 3; - } - } - list.length = j; - return list; -} - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `clearUserDocs` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Deletes user-defined documentation. - * - * @private - * @param {Options} [options] - function options - * @param {(RegExp|ArrayLikeObject)} [options.include] - name inclusion filter - * @param {(RegExp|ArrayLikeObject)} [options.exclude] - name exclusion filter - * @param {boolean} [options.filter='*'] - filter type (only applicable for array-like inclusion/exclusion filters) - * @returns {void} - */ - function onCommand( options ) { - var isArrInc; - var isArrExc; - var opts; - var err; - var len; - - if ( arguments.length ) { - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts = options; - } else { - opts = {}; - } - if ( hasOwnProp( opts, 'include' ) ) { - isArrInc = isArrayLike( opts.include ); - if ( isArrInc === false && !isRegExp( opts.include ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression or an array-like object. Option: `%s`.', 'include', opts.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } - if ( hasOwnProp( opts, 'exclude' ) ) { - isArrExc = isArrayLike( opts.exclude ); - if ( isArrExc === false && !isRegExp( opts.exclude ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression or an array-like object. Option: `%s`.', 'exclude', opts.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } - if ( hasOwnProp( opts, 'filter' ) ) { - if ( !contains( FILTERS, opts.filter ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Option: `%s`.', 'filter', FILTERS.join( '", "' ), opts.filter ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } else { - opts.filter = '*'; - } - // Case: clear all user-defined documentation... - if ( opts.include === void 0 && opts.exclude === void 0 ) { - repl._userdocs.length = 0; - log( repl, 'Cleared all user-defined documentation.' ); - debug( 'Cleared all user-defined documentation.' ); - return; - } - // Case: include/exclude filters: - len = repl._userdocs.length / 3; - filter( repl._userdocs, opts.filter, opts.include, isArrInc, opts.exclude, isArrExc ); // eslint-disable-line max-len - len -= repl._userdocs.length / 3; - log( repl, 'Cleared documentation for '+len+' alias(es).' ); - debug( 'Cleared documentation for %d alias(es).', len ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `clearVars` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Deletes user-defined variables in the current workspace. - * - * @private - * @param {Options} [options] - function options - * @param {(RegExp|ArrayLikeObject)} [options.include] - name inclusion filter - * @param {(RegExp|ArrayLikeObject)} [options.exclude] - name exclusion filter - */ - function onCommand( options ) { - var opts; - if ( arguments.length ) { - opts = options; - } else { - opts = {}; - } - repl._context.clearWorkspace( repl._currentWorkspace, opts ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 -234 -235 -236 -237 -238 -239 -240 -241 -242 -243 -244 -245 -246 -247 -248 -249 -250 -251 -252 -253 -254 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var isArrayLike = require( '@stdlib/assert/is-array-like-object' ); -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var format = require( '@stdlib/string/format' ); -var contains = require( './../contains.js' ); -var log = require( './../log.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:clear_workspace' ); - - -// FUNCTIONS // - -/** -* Filters a variable list based on include and exclude filters. -* -* @private -* @param {Array} list - variable list to filter -* @param {(RegExp|ArrayLikeObject|void)} include - name inclusion filter -* @param {boolean} isArrInc - boolean indicating whether the inclusion filter is an array -* @param {(RegExp|ArrayLikeObject|void)} exclude - name exclusion filter -* @param {boolean} isArrExc - boolean indicating whether the exclusion filter is an array -* @returns {Array} input list -*/ -function filter( list, include, isArrInc, exclude, isArrExc ) { - var FLG; - var v; - var i; - var j; - - // Perform list "compression" without using temporary data structures... - j = 0; - for ( i = 0; i < list.length; i += 2 ) { - // Note: we can only delete "configurable" variables... - if ( list[ i+1 ].configurable === false ) { - // Variable is non-configurable and, hence, cannot be deleted... - continue; - } - v = list[ i ]; - FLG = false; - - // Note: exclude/include order matters!!! - if ( exclude ) { - if ( isArrExc ) { - if ( contains( exclude, v ) ) { - // The variable is in the explicit exclude list: - FLG = true; - } - } else if ( exclude.test( v ) ) { - // The variable passes the exclusion test: - FLG = true; - } - } - // Only apply inclusion filters if the variable has not been already excluded from deletion... - if ( FLG === false && include ) { - if ( isArrInc ) { - if ( !contains( include, v ) ) { - // The variable is *not* in the include list: - FLG = true; - } - } else if ( !include.test( v ) ) { - // The variable does *not* pass the include test: - FLG = true; - } - } - if ( FLG ) { - list[ j ] = list[ i ]; - list[ j+1 ] = list[ i+1 ]; - j += 2; - } - } - list.length = j; - return list; -} - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `clearWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Deletes user-defined variables in a specified workspace. - * - * @private - * @param {string} [name] - workspace name - * @param {Options} [options] - function options - * @param {(RegExp|ArrayLikeObject)} [options.include] - name inclusion filter - * @param {(RegExp|ArrayLikeObject)} [options.exclude] - name exclusion filter - * @returns {void} - */ - function onCommand( name, options ) { - var isArrInc; - var isArrExc; - var opts; - var list; - var desc; - var err; - var tmp; - var n; - var d; - var i; - - if ( arguments.length === 0 ) { - n = repl._currentWorkspace; - opts = {}; - } else if ( arguments.length === 1 ) { - if ( isString( name ) ) { - n = name; - opts = {}; - } else if ( isPlainObject( name ) ) { - n = repl._currentWorkspace; - opts = name; - } else { - err = new TypeError( format( 'invalid argument. Must provide either an options object or a workspace name. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } else { - if ( !isString( name ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - n = name; - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts = options; - } - if ( hasOwnProp( opts, 'include' ) ) { - isArrInc = isArrayLike( opts.include ); - if ( isArrInc === false && !isRegExp( opts.include ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression or an array-like object. Option: `%s`.', 'include', opts.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } - if ( hasOwnProp( opts, 'exclude' ) ) { - isArrExc = isArrayLike( opts.exclude ); - if ( isArrExc === false && !isRegExp( opts.exclude ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression or an array-like object. Option: `%s`.', 'exclude', opts.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } - if ( n === repl._currentWorkspace ) { - // Get the current variable list: - tmp = repl._context.varsWorkspace( n, {} ); - if ( tmp.length === 0 ) { - // No user-defined variables to delete... - log( repl, 'No user-defined variables to delete.' ); - debug( 'No user-defined variables to delete.' ); - return; - } - // Cache the variable names and their respective property descriptors: - list = []; - for ( i = 0; i < tmp.length; i++ ) { - list.push( tmp[ i ], propertyDescriptor( repl._context, tmp[i] ) ); // eslint-disable-line max-len - } - d = list.length / 2; - - // Filter the list of variables: - list = filter( list, opts.include, isArrInc, opts.exclude, isArrExc ); // eslint-disable-line max-len - - // Reset the REPL evaluation context (Why? Because we cannot simply delete variables as seen within the REPL environment. E.g., variables declared with `var` in the global scope are non-configurable, and, thus, cannot be deleted (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete). While we can delete a property/variable from the REPL context object here, this deletion does not get propagated to within the REPL environment; i.e., a user can still access the deleted property as a variable within the REPL environment. Hence, we need to adopt a cache, reset, and reassign approach, as done here.): - repl.resetContext(); // Note: in sandboxed environments, we assume a fresh context object is created! - - // Reassign the variables which were not deleted: - for ( i = 0; i < list.length; i += 2 ) { - desc = list[ i+1 ]; - if ( desc.configurable || repl._sandbox ) { - // If configurable, in non-sandboxed environments, we simply overwrite the existing descriptor; in sandboxed environments, we always need to redefine the variable with the appropriate property descriptor; if non-configurable, in non-sandboxed environments, we do not need to reassign/redefine, as the variable could not be deleted from the context object and thus already exists and cannot be reconfigured: - defineProperty( repl._context, list[ i ], desc ); - } - } - d -= list.length / 2; - log( repl, 'Deleted '+d+' variable(s).' ); - debug( 'Deleted %d variable(s).', d ); - return; - } - if ( !hasOwnProp( repl._workspaces, n ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', n ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - list = repl._workspaces[ n ]; - - // Case: clear all user-defined variables... - if ( opts.include === void 0 && opts.exclude === void 0 ) { - list.length = 0; - log( repl, 'Deleted '+d+' variable(s).' ); - debug( 'Deleted %d variable(s).', d ); - return; - } - // Case: include/exclude filters: - list = filter( list, opts.include, isArrInc, opts.exclude, isArrExc ); - d -= list.length / 2; - log( repl, 'Deleted '+d+' variable(s).' ); - debug( 'Deleted %d variable(s).', d ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var DATA = require( './../../data/contributor.json' ); - - -// VARIABLES // - -var INFO = [ - '', - ' stdlib began as a project of Athan Reines and Philipp Burckhardt to bring', - ' libraries for numerical and scientific computing to JavaScript and, more', - ' generally, web environments.', - '', - ' The project has since expanded to include an extensive standard library for', - ' modern web and application development and provides best-in-class algorithms', - ' and implementations for mathematics, linear algebra, statistics, random number', - ' generation, string processing, benchmarking, testing, and so much more.', - '', - ' stdlib is the result of a collaborative effort with contributions from all', - ' over the world.', - '', - ' stdlib would not have been able to achieve its success without the invaluable', - ' help of those who have contributed by donating code, bug fixes, and', - ' documentation:', - '', - ' ' + DATA.join( '\n ' ), - '' -].join( '\n' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `contributors` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Prints a list of contributors. - * - * @private - */ - function onCommand() { - repl._ostream.write( INFO ); // eslint-disable-line no-underscore-dangle - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var currentYear = require( '@stdlib/time/current-year' ); - - -// VARIABLES // - -var INFO = '\nCopyright (c) 2016-'+currentYear()+' The Stdlib Authors.\n'; - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `copyright` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Prints copyright information. - * - * @private - */ - function onCommand() { - repl._ostream.write( INFO ); // eslint-disable-line no-underscore-dangle - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var INFO = [ - '', - ' Thank you to Stencila for initial financial support, to CircleCI, Travis CI,', - ' and Microsoft for providing continuous integration services for open-source', - ' projects, and to the many others who have supported stdlib development by', - ' contributing code, guidance, and support.', - '', - '' -].join( '\n' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `credits` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Prints credits. - * - * @private - */ - function onCommand() { - repl._ostream.write( INFO ); // eslint-disable-line no-underscore-dangle - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `currentWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns the name of the current workspace. - * - * @private - * @returns {string} result - */ - function onCommand() { - return repl._currentWorkspace; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var Stack = require( '@stdlib/dstructs/stack' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:deeprerequire' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `deeprerequire` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Reloads a previously loaded module and all its associated module dependencies. - * - * @private - * @param {string} id - module id or path - * @returns {*} resolved module - */ - function onCommand( id ) { - var nodes; - var stack; - var err; - var m; - var i; - if ( !isString( id ) ) { - err = new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', id ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - // Resolve the module id to a path: - id = repl._context.require.resolve( id ); - - // Attempt to load the module (if already loaded, this is effectively a no-op; if not already loaded, loading a module does *not* guarantee that all associated module dependencies will be freshly loaded; hence, cannot just simply `require` the module id): - repl._context.require( id ); - - // Get the module object: - m = repl._context.require.cache[ id ]; - - // Perform a depth-first search to get a list of all module ids which need to be re-imported... - stack = new Stack(); - nodes = {}; - - stack.push( m ); // push the root node onto the stack - while ( stack.length ) { - m = stack.pop(); - if ( m && !hasOwnProp( nodes, m.id ) ) { - nodes[ m.id ] = true; - for ( i = 0; i < m.children.length; i++ ) { - stack.push( m.children[ i ] ); - } - } - } - // Remove each module from the `require` cache... - nodes = objectKeys( nodes ); - for ( i = 0; i < nodes.length; i++ ) { - delete repl._context.require.cache[ nodes[ i ] ]; - } - // Re-require the module (and all its associated dependencies): - return repl._context.require( id ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `deleteTheme` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Deletes a syntax highlighting color theme. - * - * @private - * @param {string} name - theme name - * @returns {void} - */ - function onCommand( name ) { - try { - repl.deleteTheme( name ); - } catch ( err ) { - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - return; - } - log( repl, format( '\nSuccessfully deleted theme `%s`.', name ) ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:delete_workspace' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `deleteWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Deletes a workspace. - * - * @private - * @param {string} [name] - workspace name - * @returns {void} - */ - function onCommand( name ) { - var err; - var ws; - if ( arguments.length ) { - if ( !isString( name ) ) { - err = new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( !hasOwnProp( repl._workspaces, name ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - ws = name; - } else { - ws = repl._currentWorkspace; - } - if ( ws === 'base' ) { - err = new Error( 'invalid operation. Cannot delete the `base` workspace.' ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( ws === repl._currentWorkspace ) { - repl._context.workspace( 'base' ); - } - delete repl._workspaces[ ws ]; - log( repl, 'Deleted \''+ws+'\' workspace.' ); - debug( 'Deleted \'%s\' workspace.', ws ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// VARIABLES // - -var INFO = [ - '', - ' Help support stdlib!', - '', - ' stdlib is an open-source project which is maintained by members of the', - ' community. Our ability to build new features, submit bug fixes, and improve', - ' the project depends on your support.', - '', - ' You can help in the following ways:', - '', - ' - Give developer time to the project. Message us on Gitter for guidance.', - ' - Financially sponsor the project.', - '', - ' If you want to be a sponsor 🤗, you can donate to one or more of the following:', - '', - ' - Open Collective (https://opencollective.com/stdlib)', - ' - GitHub Sponsors (https://github.com/sponsors/stdlib-js)', - '', - ' Thank you for your support!', - '', - '' -].join( '\n' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `donate` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Prints donation information. - * - * @private - */ - function onCommand() { - repl._ostream.write( INFO ); // eslint-disable-line no-underscore-dangle - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var vm = require( 'vm' ); -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); -var updateRegExpCache = require( './../update_regexp_cache.js' ); -var restoreRegExpMatches = require( './../restore_regexp_matches.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:evalin' ); -var RE_WHITESPACE = /^\s*$/; - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `evalin` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Evaluates an expression in a specified workspace. - * - * @private - * @param {string} workspace - workspace name - * @param {string} expression - expression to evaluate - * @returns {void} - */ - function onCommand( workspace, expression ) { - var script; - var opts; - var err; - var FLG; - var ws; - if ( !isString( workspace ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( !isString( expression ) ) { - err = new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( !hasOwnProp( repl._workspaces, workspace ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', workspace ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( RE_WHITESPACE.test( expression ) ) { - debug( 'Expression only consists of whitespace. Nothing to evaluate.' ); - return; - } - // Cache the name of the current workspace: - ws = repl._currentWorkspace; - - // Temporarily silence logging: - FLG = repl._quiet; - repl._quiet = true; - - // Switch to the target workspace: - repl._context.workspace( workspace ); - - // Try evaluating the expression... - opts = { - 'filename': '<repl>', - 'lineOffset': 0 - }; - try { - // FIXME: this needs to follow the same logic as `process_line`, such as code wrapping, asynchronous execution, and handling top-level `await`!!! - script = new vm.Script( expression, opts ); - } catch ( error ) { - debug( 'Error: %s', error.message ); - repl._ostream.write( 'Error: '+error.message+'\n' ); - repl._context.workspace( ws ); - repl._quiet = FLG; - return; - } - // Set the (non-standard) properties on the `RegExp` expression object to the cached matches: - restoreRegExpMatches( repl._regexp ); - - opts = { - 'timeout': repl._timeout, - 'displayErrors': false, - 'breakOnSigint': true // Note: only applies for Node.js versions >=6.3.0 - }; - - // FIXME: we need to follow similar logic as `drain.js`, such as SIGINT handling!!! - try { - script.runInContext( repl._context, opts ); - repl._ostream.write( 'Successfully evaluated expression.\n' ); - } catch ( error ) { - debug( 'Error: %s', error.message ); - repl._ostream.write( 'Error: '+error.message+'\n' ); - } - updateRegExpCache( repl._regexp ); - - // Return to the previous workspace: - repl._context.workspace( ws ); - - // Re-enable logging (if enabled): - repl._quiet = FLG; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isFunction = require( '@stdlib/assert/is-function' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var alias2example = require( '@stdlib/repl/code-blocks' ); -var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP; -var nextTick = require( '@stdlib/utils/next-tick' ); -var indexOf = require( './../index_of.js' ); -var findUniqueEntry = require( './../find_unique_entry.js' ); -var alias2string = require( './../alias_to_string.js' ); -var DOCS = require( './../repl_docs.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `example` command. -* -* @private -* @param {REPL} repl - REPL instance -* @param {ArrayArray} cmds - REPL command list -* @returns {Function} callback -*/ -function command( repl, cmds ) { - return onCommand; - - /** - * Runs an example. - * - * @private - * @param {*} alias - variable alias or value - * @returns {void} - */ - function onCommand( alias ) { - var aliases; - var entry; - var lines; - var out; - var len; - var N; - var i; - - aliases = repl._aliases; - N = aliases.length; - - if ( isString( alias ) ) { - // Command docs supersede project namespace docs... - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 0 ] === alias ) { - out = DOCS.example[ cmds[ i ][ 0 ] ]; - } - } - if ( !out ) { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 0, alias ); // eslint-disable-line max-len - if ( i >= 0 ) { - out = DOCS.example[ alias ]; - } - } - if ( !out ) { - out = alias2example( alias ); - } - // TODO: add support for user docs - } - // If unable to resolve an associated example, check if we were provided a reference to a REPL-specific command... - if ( !out ) { - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 1 ] === alias ) { - out = DOCS.example[ cmds[ i ][ 0 ] ]; - } - } - } - // Check if we were provided a reference to a global context variable... - if ( !out ) { - // Address the fact that the `global` object is proxied (see https://github.com/nodejs/node/issues/855) - if ( - alias !== null && - typeof alias === 'object' && - hasOwnProp( alias, 'global' ) && - alias.global === alias - ) { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 1, repl._context.global ); // eslint-disable-line max-len - } else { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 1, alias ); // eslint-disable-line max-len - } - if ( i >= 0 ) { - out = DOCS.example[ repl._contextVars[ i-1 ] ]; - } - } - // If provided an `alias` which is not a string or we failed to resolve an associated example based on the provided value, we try to resolve a string alias (and subsequently a corresponding example) by searching the list of cached references of global variables/properties... - if ( !out ) { - i = indexOf( N/2, aliases, 2, 1, alias ); - if ( i >= 0 ) { - out = alias2example( aliases[ i-1 ] ); - } - } - // TODO: add support for searching user documentation - - // If we failed to resolve an associated example and the provided value is an object, try finding a provided value's constructor (e.g., if provided a `Uint32Array`, try finding examples for `Uint32Array`)... - if ( !out && typeof alias === 'object' && alias !== null && alias.constructor ) { - i = indexOf( N/2, aliases, 2, 1, alias.constructor ); - if ( i >= 0 ) { - out = alias2example( aliases[ i-1 ] ); - } - } - // If we failed to resolve an associated example and the provided value is a function, try finding method examples... - if ( !out && isFunction( alias ) ) { - // Note: the following is an **expensive** look-up!! - entry = findUniqueEntry( N/2, aliases, 2, 1, alias ); - if ( entry ) { - out = alias2example( aliases[ entry[2]-1 ]+'.'+entry[ 1 ] ); - } - } - if ( out ) { - lines = []; - out = out.split( RE_EOL ); - len = out.length; - i = -1; - - // Why defer? In order to allow the `example()` command to finish before actually evaluating the commands to run, thus ensuring that commands are run as if a user manually enters them... - repl.once( 'drain', next ); - return; - } - repl._ostream.write( 'Error: no example available. Alias: `'+alias2string( alias )+'`.\n' ); - - /** - * Callback invoked after draining the command queue. - * - * @private - * @param {string} cmd - command - * @param {boolean} success - boolean indicating whether the command successfully executed - * @returns {void} - */ - function next() { - var j; - i += 1; - if ( i < len ) { - // Forward the next line to the REPL readline interface in order to mimic user input... - if ( out[ i ] ) { - lines.push( out[ i ] ); - - // If line is part of a multi-line input, wait for the next line... - if ( repl._multilineHandler.isMultilineInput( lines.join( '\n' ) ) ) { - return next(); - } - for ( j = 0; j < lines.length; j++ ) { - repl._rli.write( lines[ j ] ); - repl._rli.write( '\n', { - 'name': 'return' - }); - } - lines = []; - repl.once( 'drain', next ); - } else { - nextTick( next ); - } - } - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `getTheme` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a syntax highlighting color theme. - * - * @private - * @param {string} [name] - theme name - * @returns {(Object|void)} theme object - */ - function onCommand() { - var theme; - var name; - - // If no theme name given, get the current theme... - if ( arguments.length === 0 ) { - name = repl.settings( 'theme' ); - } else { - name = arguments[ 0 ]; - } - try { - theme = repl.getTheme( name ); - } catch ( err ) { - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - return; - } - return theme; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -2x -2x -2x -2x -2x -2x - - - -2x -2x -2x -2x -2x -2x -100x - - -100x -2x -2x -2x - - -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x -2x - - - - - - -2x -2x - - - - - - - - - - - - - - - -2x -2x - - - - - -2x -2x - - - - - -2x -2x - - - - - -2x -2x - - - - - - -2x -2x -2x -2x - -2x -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isFunction = require( '@stdlib/assert/is-function' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var alias2help = require( '@stdlib/repl/help' ); -var indexOf = require( './../index_of.js' ); -var findUniqueEntry = require( './../find_unique_entry.js' ); -var alias2string = require( './../alias_to_string.js' ); -var HELP_TEXT = require( './../help_text.js' ); -var DOCS = require( './../repl_docs.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `help` command. -* -* @private -* @param {REPL} repl - REPL instance -* @param {ArrayArray} cmds - REPL command list -* @returns {Function} callback -*/ -function command( repl, cmds ) { - return onCommand; - - /** - * Prints help text. - * - * @private - * @param {*} [alias] - variable alias or value - * @returns {void} - */ - function onCommand( alias ) { - var aliases; - var entry; - var out; - var N; - var i; - if ( arguments.length === 0 ) { - repl._ostream.write( HELP_TEXT ); - return; - } - aliases = repl._aliases; - N = aliases.length; - - if ( isString( alias ) ) { - // Command docs supersede project namespace docs... - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 0 ] === alias ) { - out = DOCS.help[ cmds[ i ][ 0 ] ]; - } - } - if ( !out ) { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 0, alias ); // eslint-disable-line max-len - if ( i >= 0 ) { - out = DOCS.help[ alias ]; - } - } - // Built-in docs supersede user-defined documentation... - if ( !out ) { - out = alias2help( alias ); - } - if ( !out ) { - i = indexOf( repl._userdocs.length/3, repl._userdocs, 3, 0, alias ); // eslint-disable-line max-len - if ( i >= 0 ) { - out = repl._userdocs[ i+2 ].text; - } - } - } - // If unable to resolve help text, check if we were provided a reference to a REPL-specific command... - if ( !out ) { - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 1 ] === alias ) { - out = DOCS.help[ cmds[ i ][ 0 ] ]; - } - } - } - // Check if we were provided a reference to a global context variable... - if ( !out ) { - // Address the fact that the `global` object is proxied (see https://github.com/nodejs/node/issues/855) - if ( - alias !== null && - typeof alias === 'object' && - hasOwnProp( alias, 'global' ) && - alias.global === alias - ) { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 1, repl._context.global ); // eslint-disable-line max-len - } else { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 1, alias ); // eslint-disable-line max-len - } - if ( i >= 0 ) { - out = DOCS.help[ repl._contextVars[ i-1 ] ]; - } - } - // If provided an `alias` which is not a string or we failed to resolve a help text based on the provided string value, we try to resolve a string alias (and subsequently a corresponding help text) by searching the list of cached references of global variables/properties... - if ( !out ) { - i = indexOf( N/2, aliases, 2, 1, alias ); - if ( i >= 0 ) { - out = alias2help( aliases[ i-1 ] ); - } - } - // Try searching user-defined documentation for a matching object reference... - if ( !out ) { - i = indexOf( repl._userdocs.length/3, repl._userdocs, 3, 1, alias ); - if ( i >= 0 ) { - out = repl._userdocs[ i+1 ].text; - } - } - // If we failed to resolve help text and the provided value is an object, try finding a provided value's constructor (e.g., if provided a `Uint32Array`, try finding the documentation for `Uint32Array`)... - if ( !out && typeof alias === 'object' && alias !== null && alias.constructor ) { - i = indexOf( N/2, aliases, 2, 1, alias.constructor ); - if ( i >= 0 ) { - out = alias2help( aliases[ i-1 ] ); - } - } - // If we failed to resolve help text and the provided value is a function, try finding method documentation (note: we cannot perform a full inherited property search as prototype methods can be shared among multiple constructors, and, based on a reference alone, we cannot determine the appropriate document context; e.g., typed array methods all belong to an ancestor constructor `TypedArray` and we cannot tell, for example, whether a reference to `forEach` should return the documentation for `Uint32Array.prototype.forEach` or `Int32Array.prototype.forEach` or any of the other typed array constructors)... - if ( !out && isFunction( alias ) ) { - // Note: the following is an **expensive** look-up!! Why unique? In order to avoid document conflicts/"race conditions" between two or more context variables having own properties pointing to the same function reference (e.g., PRNGs having a `PRNG` property whose value is shared among multiple PRNGs; which `PRNG` property documentation do we return?). - entry = findUniqueEntry( N/2, aliases, 2, 1, alias ); - if ( entry ) { - out = alias2help( aliases[ entry[2]-1 ]+'.'+entry[ 1 ] ); - } - } - if ( out ) { - repl._ostream.write( out+'\n' ); - return; - } - repl._ostream.write( 'Error: no help information available. Alias: `'+alias2string( alias )+'`.\n' ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
---|---|---|---|---|---|---|---|---|---|
__done__.js | -
-
- |
- 85.96% | -49/57 | -100% | -2/2 | -50% | -1/2 | -85.96% | -49/57 | -
add_theme.js | -
-
- |
- 87.3% | -55/63 | -100% | -2/2 | -50% | -1/2 | -87.3% | -55/63 | -
alias2pkg.js | -
-
- |
- 65.11% | -56/86 | -100% | -2/2 | -50% | -1/2 | -65.11% | -56/86 | -
alias2related.js | -
-
- |
- 58.16% | -57/98 | -100% | -2/2 | -50% | -1/2 | -58.16% | -57/98 | -
ans.js | -
-
- |
- 95.91% | -47/49 | -100% | -2/2 | -50% | -1/2 | -95.91% | -47/49 | -
assignfrom.js | -
-
- |
- 60.19% | -62/103 | -100% | -2/2 | -50% | -1/2 | -60.19% | -62/103 | -
assignin.js | -
-
- |
- 55.75% | -63/113 | -100% | -2/2 | -50% | -1/2 | -55.75% | -63/113 | -
citation.js | -
-
- |
- 97.53% | -79/81 | -100% | -2/2 | -50% | -1/2 | -97.53% | -79/81 | -
clear.js | -
-
- |
- 95.65% | -44/46 | -100% | -2/2 | -50% | -1/2 | -95.65% | -44/46 | -
clear_history.js | -
-
- |
- 95.65% | -44/46 | -100% | -2/2 | -50% | -1/2 | -95.65% | -44/46 | -
clear_user_docs.js | -
-
- |
- 42.38% | -89/210 | -100% | -2/2 | -33.33% | -1/3 | -42.38% | -89/210 | -
clear_vars.js | -
-
- |
- 85.96% | -49/57 | -100% | -2/2 | -50% | -1/2 | -85.96% | -49/57 | -
clear_workspace.js | -
-
- |
- 33.99% | -86/253 | -100% | -2/2 | -33.33% | -1/3 | -33.99% | -86/253 | -
contributor.js | -
-
- |
- 97.36% | -74/76 | -100% | -2/2 | -50% | -1/2 | -97.36% | -74/76 | -
copyright.js | -
-
- |
- 96.42% | -54/56 | -100% | -2/2 | -50% | -1/2 | -96.42% | -54/56 | -
credits.js | -
-
- |
- 96.61% | -57/59 | -100% | -2/2 | -50% | -1/2 | -96.61% | -57/59 | -
current_workspace.js | -
-
- |
- 95.91% | -47/49 | -100% | -2/2 | -50% | -1/2 | -95.91% | -47/49 | -
deeprerequire.js | -
-
- |
- 60% | -63/105 | -100% | -2/2 | -50% | -1/2 | -60% | -63/105 | -
delete_theme.js | -
-
- |
- 87.09% | -54/62 | -100% | -2/2 | -50% | -1/2 | -87.09% | -54/62 | -
delete_workspace.js | -
-
- |
- 65.95% | -62/94 | -100% | -2/2 | -50% | -1/2 | -65.95% | -62/94 | -
donate.js | -
-
- |
- 97.22% | -70/72 | -100% | -2/2 | -50% | -1/2 | -97.22% | -70/72 | -
evalin.js | -
-
- |
- 46.15% | -66/143 | -100% | -2/2 | -50% | -1/2 | -46.15% | -66/143 | -
example.js | -
-
- |
- 33.68% | -63/187 | -100% | -2/2 | -50% | -1/2 | -33.68% | -63/187 | -
get_theme.js | -
-
- |
- 75.71% | -53/70 | -100% | -2/2 | -50% | -1/2 | -75.71% | -53/70 | -
help.js | -
-
- |
- 68.35% | -108/158 | -22.22% | -4/18 | -100% | -2/2 | -68.35% | -108/158 | -
info.js | -
-
- |
- 42.65% | -61/143 | -100% | -2/2 | -50% | -1/2 | -42.65% | -61/143 | -
is_keyword.js | -
-
- |
- 64.07% | -66/103 | -100% | -2/2 | -50% | -1/2 | -64.07% | -66/103 | -
is_workspace.js | -
-
- |
- 73.25% | -63/86 | -100% | -2/2 | -50% | -1/2 | -73.25% | -63/86 | -
keybindings.js | -
-
- |
- 75.3% | -61/81 | -100% | -2/2 | -50% | -1/2 | -75.3% | -61/81 | -
license_text.js | -
-
- |
- 96.07% | -49/51 | -100% | -2/2 | -50% | -1/2 | -96.07% | -49/51 | -
load.js | -
-
- |
- 51.28% | -60/117 | -100% | -2/2 | -50% | -1/2 | -51.28% | -60/117 | -
load_workspace.js | -
-
- |
- 42.6% | -72/169 | -100% | -2/2 | -50% | -1/2 | -42.6% | -72/169 | -
pager.js | -
-
- |
- 100% | -64/64 | -100% | -5/5 | -100% | -2/2 | -100% | -64/64 | -
presentation_start.js | -
-
- |
- 30.17% | -70/232 | -100% | -2/2 | -50% | -1/2 | -30.17% | -70/232 | -
presentation_stop.js | -
-
- |
- 51.63% | -63/122 | -100% | -2/2 | -50% | -1/2 | -51.63% | -63/122 | -
quit.js | -
-
- |
- 94.73% | -54/57 | -100% | -2/2 | -50% | -1/2 | -94.73% | -54/57 | -
rename_theme.js | -
-
- |
- 87.3% | -55/63 | -100% | -2/2 | -50% | -1/2 | -87.3% | -55/63 | -
rename_workspace.js | -
-
- |
- 53.38% | -63/118 | -100% | -2/2 | -50% | -1/2 | -53.38% | -63/118 | -
rerequire.js | -
-
- |
- 76.92% | -60/78 | -100% | -2/2 | -50% | -1/2 | -76.92% | -60/78 | -
rerun.js | -
-
- |
- 39.5% | -64/162 | -100% | -2/2 | -50% | -1/2 | -39.5% | -64/162 | -
reset.js | -
-
- |
- 95.65% | -44/46 | -100% | -2/2 | -50% | -1/2 | -95.65% | -44/46 | -
set_keybinding.js | -
-
- |
- 65.95% | -62/94 | -100% | -2/2 | -50% | -1/2 | -65.95% | -62/94 | -
settings.js | -
-
- |
- 62.18% | -74/119 | -100% | -2/2 | -33.33% | -1/3 | -62.18% | -74/119 | -
themes.js | -
-
- |
- 95.74% | -45/47 | -100% | -2/2 | -50% | -1/2 | -95.74% | -45/47 | -
tutorial.js | -
-
- |
- 47.97% | -83/173 | -100% | -2/2 | -33.33% | -1/3 | -47.97% | -83/173 | -
user_doc.js | -
-
- |
- 80.55% | -87/108 | -42.85% | -3/7 | -100% | -2/2 | -80.55% | -87/108 | -
vars.js | -
-
- |
- 86.66% | -52/60 | -100% | -2/2 | -50% | -1/2 | -86.66% | -52/60 | -
vars_workspace.js | -
-
- |
- 35.04% | -75/214 | -100% | -2/2 | -50% | -1/2 | -35.04% | -75/214 | -
workspace.js | -
-
- |
- 47.05% | -64/136 | -100% | -2/2 | -50% | -1/2 | -47.05% | -64/136 | -
workspaces.js | -
-
- |
- 54.91% | -67/122 | -100% | -2/2 | -50% | -1/2 | -54.91% | -67/122 | -
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isFunction = require( '@stdlib/assert/is-function' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var alias2info = require( '@stdlib/repl/info' ); -var indexOf = require( './../index_of.js' ); -var findUniqueEntry = require( './../find_unique_entry.js' ); -var alias2string = require( './../alias_to_string.js' ); -var DOCS = require( './../repl_docs.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `info` command. -* -* @private -* @param {REPL} repl - REPL instance -* @param {ArrayArray} cmds - REPL command list -* @returns {Function} callback -*/ -function command( repl, cmds ) { - return onCommand; - - /** - * Prints abbreviated help text. - * - * @private - * @param {*} alias - variable alias or value - * @returns {void} - */ - function onCommand( alias ) { - var aliases; - var entry; - var out; - var N; - var i; - - aliases = repl._aliases; - N = aliases.length; - - if ( isString( alias ) ) { - // Command docs supersede project namespace docs... - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 0 ] === alias ) { - out = DOCS.info[ cmds[ i ][ 0 ] ]; - } - } - if ( !out ) { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 0, alias ); // eslint-disable-line max-len - if ( i >= 0 ) { - out = DOCS.info[ alias ]; - } - } - if ( !out ) { - out = alias2info( alias ); - } - // TODO: add support for user-defined documentation - } - // If unable to resolve abbreviated help text, check if we were provided a reference to a REPL-specific command... - if ( !out ) { - for ( i = 0; i < cmds.length; i++ ) { - if ( cmds[ i ][ 1 ] === alias ) { - out = DOCS.info[ cmds[ i ][ 0 ] ]; - } - } - } - // Check if we were provided a reference to a global context variable... - if ( !out ) { - // Address the fact that the `global` object is proxied (see https://github.com/nodejs/node/issues/855) - if ( - alias !== null && - typeof alias === 'object' && - hasOwnProp( alias, 'global' ) && - alias.global === alias - ) { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 1, repl._context.global ); // eslint-disable-line max-len - } else { - i = indexOf( repl._contextVars.length, repl._contextVars, 2, 1, alias ); // eslint-disable-line max-len - } - if ( i >= 0 ) { - out = DOCS.info[ repl._contextVars[ i-1 ] ]; - } - } - // If provided an `alias` which is not a string or we failed to resolve an abbreviated help text based on the provided string value, we try to resolve a string alias (and subsequently a corresponding abbreviated help text) by searching the list of cached references of global variables/properties... - if ( !out ) { - i = indexOf( N/2, aliases, 2, 1, alias ); - if ( i >= 0 ) { - out = alias2info( aliases[ i-1 ] ); - } - } - // TODO: add support for user-defined documentation - - // If we failed to resolve abbreviated help text and the provided value is an object, try finding a provided value's constructor (e.g., if provided a `Uint32Array`, try finding the documentation for `Uint32Array`)... - if ( !out && typeof alias === 'object' && alias !== null && alias.constructor ) { - i = indexOf( N/2, aliases, 2, 1, alias.constructor ); - if ( i >= 0 ) { - out = alias2info( aliases[ i-1 ] ); - } - } - // If we failed to resolve abbreviated help text and the provided value is a function, try finding method abbreviated documentation... - if ( !out && isFunction( alias ) ) { - // Note: the following is an **expensive** look-up!! - entry = findUniqueEntry( N/2, aliases, 2, 1, alias ); - if ( entry ) { - out = alias2info( aliases[ entry[2]-1 ]+'.'+entry[ 1 ] ); - } - } - if ( out ) { - repl._ostream.write( out+'\n' ); - return; - } - repl._ostream.write( 'Error: no abbreviated help available. Alias: `'+alias2string( alias )+'`.\n' ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:is_keyword' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `isKeyword` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a boolean indicating whether a string is a reserved keyword in the REPL environment. - * - * ## Notes - * - * - This function supports nested keyword paths (e.g., `base.sin`). - * - * @private - * @param {string} keyword - string to test - * @returns {(boolean|void)} boolean indicating whether a string is a reserved keyword - */ - function onCommand( keyword ) { - var desc; - var err; - var o; - var i; - var k; - if ( !isString( keyword ) ) { - err = new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', keyword ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - // Our proxy for determining whether a value is a keyword is whether the value is read-only property on the `context` object, as any properties we have added to the `context` object are read-only (note, however, that, in a non-sandboxed environment, the `global` object may have read-only properties we have *not* introduced; meaning, some values which may be flagged as "keywords" were not introduced by us): - keyword = keyword.split( '.' ); - o = repl._context; - for ( i = 0; i < keyword.length-1; i++ ) { - k = keyword[ i ]; - if ( !hasOwnProp( o, k ) ) { - return false; - } - o = o[ k ]; - } - k = keyword[ i ]; - desc = propertyDescriptor( o, k ); - return ( - desc !== null && - ( - // Data descriptor: - desc.writable === false || - - // Accessor descriptor: - ( - typeof desc.get === 'function' && - desc.set === void 0 - ) - ) - ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:is_workspace' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `isWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a boolean indicating whether a specified workspace exists. - * - * @private - * @param {(string|RegExp)} name - workspace name or regular expression - * @returns {(boolean|void)} boolean indicating whether a workspace exists - */ - function onCommand( name ) { - var isStr; - var keys; - var err; - var i; - - isStr = isString( name ); - if ( isStr === false && !isRegExp( name ) ) { - err = new TypeError( format( 'invalid argument. Must provide either a string or regular expression. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( isStr ) { - return hasOwnProp( repl._workspaces, name ); - } - keys = objectKeys( repl._workspaces ); - for ( i = 0; i < keys.length; i++ ) { - if ( name.test( keys[ i ] ) ) { - return true; - } - } - return false; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); -var contains = require( '@stdlib/array/base/assert/contains' ).factory; -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var ACTIONS = require( './../actions.js' ); - - -// VARIABLES // - -var isAction = contains( ACTIONS ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `keybindings` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns all (or select) keybindings. - * - * @private - * @param {string} [action] - action name - * @returns {(Object|Array<Object>)} keybindings object or a list of keybindings - */ - function onCommand() { - var action; - var nargs; - - nargs = arguments.length; - if ( nargs === 0 ) { - return repl.keybindings(); - } - if ( nargs === 1 ) { - action = arguments[ 0 ]; - if ( !isString( action ) ) { - repl._ostream.write( format( 'Error: invalid argument. First argument must be a string. Value: `%s`.', action ) ); - return; - } - if ( !isAction( action ) ) { - repl._ostream.write( format( 'Error: invalid argument. First argument must be a valid action name. Value: `%s`.', action ) ); - return; - } - return repl.keybindings()[ action ]; - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var DATA = require( './../../data/license_text.json' ).text; - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `license` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Prints license information. - * - * @private - */ - function onCommand() { - repl._ostream.write( DATA ); // eslint-disable-line no-underscore-dangle - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:load' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `load` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Loads and evaluates a JavaScript file line-by-line. - * - * @private - * @param {string} fpath - file path - * @returns {void} - */ - function onCommand( fpath ) { - var err; - if ( !isString( fpath ) ) { - err = new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', fpath ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - repl.once( 'drain', onDrain ); - - /** - * Callback invoked upon a 'drain' event. - * - * @private - */ - function onDrain() { - debug( 'Loading a file...' ); - repl.load( fpath, clbk ); - } - - /** - * Callback invoked upon loading a file. - * - * @private - * @param {Error} [error] - error object - */ - function clbk( error ) { - var pos; - if ( error ) { - // NOTE: we can assume that the error pertains to actually reading the file (e.g., loading from disk) and NOT the line-by-line evaluation, where error handling should be handled separately... - debug( 'Error: %s', error.message ); - - // Infer the current cursor column position based on the length of the command prompt string: - pos = repl._prompt().length; // FIXME: how to address multi-column characters? - - // FIXME: handle non-TTY output streams! - - /* - * Print the error message on the previous line and generate the expected display prompt and cursor position. - * - * [ANSI escape sequences][1]: - * - * - `\u001b`: ESC, the escape character - * - `[1A`: move cursor up one line - * - `[nD`: move cursor back (to the left) `n` columns (cells) - * - `[0J`: clear the screen beginning from the current cursor position to the end of the screen - * - * [1]: https://en.wikipedia.org/wiki/ANSI_escape_code - */ - repl._ostream.write( '\u001b[1A\u001b['+pos+'DError: '+error.message+'\u001b[0J\n' ); - - // Show a new display prompt: - repl._displayPrompt(); - return; - } - debug( 'Successfully loaded file.' ); - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var isArrayLike = require( '@stdlib/assert/is-array-like-object' ); -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var format = require( '@stdlib/string/format' ); -var contains = require( './../contains.js' ); -var log = require( './../log.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:load_workspace' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `loadWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Loads variables from a specified workspace into the current workspace. - * - * @private - * @param {string} name - workspace name - * @param {Options} [options] - function options - * @param {(RegExp|ArrayLikeObject)} [options.include] - name inclusion filter - * @param {(RegExp|ArrayLikeObject)} [options.exclude] - name exclusion filter - * @param {boolean} [options.override=true] - boolean indicating whether to override existing workspace variables - * @returns {void} - */ - function onCommand( name, options ) { - var isArrInc; - var isArrExc; - var opts; - var err; - var cnt; - var ws; - var v; - var i; - if ( !isString( name ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts = { - 'override': true - }; - if ( arguments.length > 1 ) { - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( options, 'include' ) ) { - isArrInc = isArrayLike( options.include ); - if ( isArrInc === false && !isRegExp( options.include ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression or an array-like object. Option: `%s`.', 'include', options.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts.include = options.include; - } - if ( hasOwnProp( options, 'exclude' ) ) { - isArrExc = isArrayLike( options.exclude ); - if ( isArrExc === false && !isRegExp( options.exclude ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression or an array-like object. Option: `%s`.', 'exclude', options.exclude ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts.exclude = options.exclude; - } - if ( hasOwnProp( options, 'override' ) ) { - if ( !isBoolean( options.override ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'override', options.override ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts.override = options.override; - } - } - if ( name === repl._currentWorkspace ) { - log( repl, 'Already in \''+name+'\' workspace.' ); - debug( 'Already in \'%s\' workspace.', name ); - return; - } - if ( !hasOwnProp( repl._workspaces, name ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - ws = repl._workspaces[ name ]; - - // Note: the internal branches are not the most performant implementation, but the implementation is straightforward and presumably "good enough"... - cnt = 0; - for ( i = 0; i < ws.length; i += 2 ) { - v = ws[ i ]; - if ( opts.include ) { - if ( isArrInc && !contains( opts.include, v ) ) { - continue; - } - if ( !opts.include.test( v ) ) { - continue; - } - } - if ( opts.exclude ) { - if ( isArrExc && contains( opts.exclude, v ) ) { - continue; - } - if ( opts.exclude.test( v ) ) { - continue; - } - } - if ( hasOwnProp( repl._context, v ) && opts.override === false ) { - continue; - } - // If we've made it this far, the variable should have passed all filters... - cnt += 1; - defineProperty( repl._context, v, ws[ i+1] ); - } - log( repl, cnt.toString()+' variable(s) loaded from \''+name+'\' workspace.' ); - debug( '%d variable(s) loaded from \'%s\' workspace.', cnt, name ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -6x -6x -6x -6x -5x -5x -5x -5x -1x -1x -1x -1x -1x -1x -1x -1x -6x -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `pager` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Enables paging for a provided string. - * - * @private - * @param {string} value - input string - */ - function onCommand( value ) { - var ostream = repl._ostream; - - // Check whether auto-paging is already enabled... - if ( repl.settings( 'autoPage' ) ) { - // Nothing needed here, as we can defer to already enabled behavior: - ostream.write( value ); - return; - } - // Temporarily enable paging: - ostream.enablePaging(); - - // Write the input value: - ostream.write( value ); - - // Disable paging: - ostream.disablePaging(); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 -216 -217 -218 -219 -220 -221 -222 -223 -224 -225 -226 -227 -228 -229 -230 -231 -232 -233 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); -var properties = require( '@stdlib/utils/properties' ); -var Presentation = require( '@stdlib/repl/presentation' ); // eslint-disable-line stdlib/no-redeclare -var format = require( '@stdlib/string/format' ); -var setdiff = require( './../setdiff.js' ); -var propertyComparator = require( './../property_comparator.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:presentation_start' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `presentationStart` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Starts a REPL presentation. - * - * @private - * @param {string} [text] - presentation text - * @param {Options} [options] - options - * @param {boolean} [options.watch=false] - boolean indicating whether to watch a presentation source file for changes (note: only applicable if not provided presentation text and the options object specifies a presentation file to load) - * @returns {(NonNegativeInteger|void)} presentation identifier - */ - function onCommand( text, options ) { - var opts; - var FLG; - var err; - var ctx; - var ws; - var cs; - var id; - var t; - var p; - - if ( arguments.length === 0 ) { - err = new TypeError( 'invalid invocation. Must provide either a string containing presentation text or an options object specifying a presentation file to load.' ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( arguments.length === 1 ) { - if ( isString( text ) ) { - t = text; - opts = {}; - } else if ( isPlainObject( text ) ) { - opts = text; - } else { - err = new TypeError( format( 'invalid argument. First argument must be either a string containing presentation text or an options object specifying a presentation file to load. Value: `%s`.', text ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } else { - if ( !isString( text ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', text ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - t = text; - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Second argument must be an options object. Value: `%s`.', options ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts = options; - } - if ( hasOwnProp( opts, 'watch' ) && !isBoolean( opts.watch ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'watch', opts.watch ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( t === void 0 && !hasOwnProp( opts, 'load' ) ) { - err = new TypeError( 'invalid argument. When not provided presentation text, an options argument must specify a presentation file to load.' ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - // Generate a presentation identifier: - id = repl._internal.presentation.counter + 1; - debug( 'Presentation identifier: %d', id ); - - // Determine the destination workspace name: - if ( hasOwnProp( opts, 'workspace' ) ) { - ws = opts.workspace; - } else { - ws = 'presentation-' + id; - opts.workspace = ws; - } - debug( 'Presentation workspace: %s', ws ); - - // Cache a reference to the current evaluation context: - ctx = repl._context; - - // Cache the current workspace name: - cs = repl._currentWorkspace; - - // If the destination workspace already exists, we need to delete that workspace in order to allow presentation commands to be properly bound... - if ( ws !== 'base' && repl._context.isWorkspace( ws ) ) { - debug( 'Deleting workspace: %s', ws ); - FLG = repl._quiet; - repl._quiet = true; // temporarily silence logging - repl._context.deleteWorkspace( ws ); - repl._quiet = FLG; - } - // Create a new presentation... - debug( 'Creating presentation...' ); - if ( t === void 0 ) { - p = new Presentation( repl, opts ); - if ( opts.watch ) { - // Start watching before the invoking command finishes in order to catch any source file changes which happen between now and then... - p.watch(); - } - } else { - p = new Presentation( t, repl, opts ); - } - // Update the internal resource cache for tracking presentations: - repl._internal.presentation.counter += 1; - repl._internal.presentation.cache[ id ] = { - 'i': id, - 'w': ws, - 'p': p - }; - - // Allow the command to finish before showing the presentation: - repl.once( 'drain', onFinish ); - - // Return the presentation identifier: - return id; - - /** - * Callback invoked once the `presentationStart()` command finishes. - * - * @private - * @param {string} cmd - command - * @param {boolean} success - boolean indicating whether the command successfully executed - * @returns {void} - */ - function onFinish( cmd, success ) { - var desc; - var vars; - var FLG; - var ws; - var v; - var i; - var j; - - // NOTE: the following is a bit of a hack. Because creating a presentation instance automatically switches the workspace (and thus creates a **new** evaluation context), we need to manually assign the returned identifier (if assigned) and any other declared variables (!) in the invoking workspace to allow the presentation identifier and other variables to be correctly tracked... - - // Get the list of variables in the invoking evaluation context AFTER having run the command: - vars = properties( ctx ).sort( propertyComparator ); - - // Get the list of user-defined workspace variables in the invoking evaluation context: - vars = setdiff( repl._workspace, vars ); - - // Manually append the variables to the workspace which were assigned but not captured upon creating a presentation instance... - ws = repl._workspaces[ cs ]; - for ( i = 0; i < vars.length; i++ ) { - FLG = false; - v = vars[ i ]; - desc = propertyDescriptor( ctx, v ); - - // Search for an existing workspace variable to overwrite... - for ( j = 0; j < ws.length; j += 2 ) { - if ( ws[ j ] === v ) { - ws[ j+1 ] = desc; - FLG = true; - break; - } - } - // Create a new workspace variable: - if ( FLG === false ) { - ws.push( v, desc ); - } - } - - // Only show the presentation if the command successfully executed... - if ( success === false ) { - return; - } - debug( 'Showing presentation...' ); - p.show(); - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var format = require( '@stdlib/string/format' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:presentation_stop' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `presentationStop` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Stops a REPL presentation. - * - * @private - * @param {(NonNegativeInteger|string)} [id] - presentation identifier - * @returns {boolean} boolean indicating whether a REPL presentation is successfully stopped - */ - function onCommand( id ) { - var cache; - var keys; - var FLG; - var err; - var key; - var ws; - var i; - var o; - - cache = repl._internal.presentation.cache; - if ( arguments.length ) { - if ( !isString( id ) && !isNonNegativeInteger( id ) ) { - err = new TypeError( format( 'invalid argument. Invalid presentation identifier. Must be either a string or nonnegative integer. Value: `%s`.', id ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return false; - } - key = id; - } else { - ws = repl._currentWorkspace; - keys = objectKeys( cache ); - for ( i = 0; i < keys.length; i++ ) { - if ( cache[ keys[ i ] ].w === ws ) { - key = cache[ keys[ i ] ].i; - break; - } - } - if ( key === void 0 ) { - err = new Error( 'invalid invocation. Not currently in a presentation workspace. Must provide either a string or nonnegative integer which corresponds to the identifier of the presentation to be stopped.' ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return false; - } - } - if ( !hasOwnProp( cache, key ) ) { - debug( 'Unrecognized presentation identifier: %d', key ); - return false; - } - debug( 'Stopping presentation: %d', key ); - - // Retrieve the presentation data: - o = cache[ key ]; - - // Delete the presentation workspace... - if ( o.w !== 'base' ) { - debug( 'Deleting workspace: %s', o.w ); - FLG = repl._quiet; - repl._quiet = true; // temporarily silence logging - repl._context.deleteWorkspace( o.w ); - repl._quiet = FLG; - } - // Ensure that we no longer watch presentation files (if enabled): - o.p.unwatch(); - - // Update the internal resource cache for tracking presentations: - delete cache[ key ]; - - return true; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:quit' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `quit` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Quits a REPL. - * - * @private - */ - function onCommand() { - debug( 'Quitting the REPL...' ); - repl.close(); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `renameTheme` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Renames a syntax highlighting color theme. - * - * @private - * @param {string} oldName - old theme name - * @param {string} newName - new theme name - * @returns {void} - */ - function onCommand( oldName, newName ) { - try { - repl.renameTheme( oldName, newName ); - } catch ( err ) { - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - return; - } - log( repl, format( '\nSuccessfully renamed theme from `%s` to `%s`.', oldName, newName ) ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:delete_workspace' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `renameWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Renames a workspace. - * - * @private - * @param {string} oldName - name of workspace to rename - * @param {string} newName - new workspace name - * @returns {void} - */ - function onCommand( oldName, newName ) { - var err; - if ( !isString( oldName ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', oldName ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( !isString( newName ) ) { - err = new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', newName ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( !hasOwnProp( repl._workspaces, oldName ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', oldName ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( oldName === newName ) { - log( repl, 'Workspace is already named \''+newName+'\'.' ); - return; - } - if ( hasOwnProp( repl._workspaces, newName ) ) { - err = new Error( format( 'invalid argument. Workspace name already exists. Value: `%s`.', newName ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( oldName === repl._currentWorkspace ) { - if ( oldName === 'base' ) { - repl._workspaces[ 'base' ].length = 0; - log( repl, 'Created \''+newName+'\' workspace and cleared \'base\' workspace. Current workspace: \''+newName+'\'.' ); - debug( 'Created \'%s\' workspace and cleared \'base\' workspace. Current workspace: \'%s\'.', newName, newName ); - } else { - delete repl._workspaces[ oldName ]; - log( repl, 'Renamed \''+oldName+'\' workspace to \''+newName+'\'. Current workspace: \''+newName+'\'.' ); - debug( 'Renamed \'%s\' workspace to \'%s\'. Current workspace: \'%s\'.', oldName, newName, newName ); - } - repl._workspaces[ newName ] = []; // "registers" the workspace - repl._currentWorkspace = newName; // bookkeeping - return; - } - if ( oldName === 'base' ) { - repl._workspaces[ newName ] = repl._workspaces[ 'base' ].slice(); - repl._workspaces[ 'base' ].length = 0; - log( repl, 'Created \''+newName+'\' workspace and cleared \'base\' workspace.' ); - debug( 'Created \'%s\' workspace and cleared \'base\' workspace.', newName ); - return; - } - repl._workspaces[ newName ] = repl._workspaces[ oldName ]; - delete repl._workspaces[ oldName ]; - log( repl, 'Renamed \''+oldName+'\' workspace to \''+newName+'\'.' ); - debug( 'Renamed \'%s\' workspace to \'%s\'.', oldName, newName ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:rerequire' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `rerequire` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Reloads a previously loaded module. - * - * @private - * @param {string} id - module id or path - * @returns {*} resolved module - */ - function onCommand( id ) { - var err; - if ( !isString( id ) ) { - err = new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', id ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - // Resolve the module id to a path: - id = repl._context.require.resolve( id ); - - // Remove the module from the `require` cache: - debug( 'Removing module from require cache: %s', id ); - delete repl._context.require.cache[ id ]; - - // Re-require the module: - debug( 'Re-requiring module: %s', id ); - return repl._context.require( id ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/* eslint-disable no-underscore-dangle */ - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var isNonNegativeIntegerArray = require( '@stdlib/assert/is-nonnegative-integer-array' ).primitives; -var format = require( '@stdlib/string/format' ); -var displayPrompt = require( './../display_prompt.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:rerun' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `rerun` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Reruns previous commands. - * - * @private - * @param {(string|RegExp|NonNegativeInteger|NonNegativeIntegerArray)} [arg=1] - filter - * @returns {void} - */ - function onCommand( arg ) { - var nargs; - var len; - var FLG; - var err; - - len = repl._history.length; - if ( len === 0 ) { - repl._ostream.write( 'History is empty. No commands to run.\n' ); - return; - } - nargs = arguments.length; - if ( nargs > 0 ) { - if ( isString( arg ) ) { - FLG = 1; - } else if ( isNonNegativeInteger( arg ) ) { - FLG = 2; - } else if ( isRegExp( arg ) ) { - FLG = 3; - } else if ( isNonNegativeIntegerArray( arg ) ) { - FLG = 4; - } else { - err = new TypeError( format( 'invalid argument. Must provide a string, regular expression, nonnegative integer, or an array of nonnegative integers. Value: `%s`.', arg ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } - // Why defer? In order to allow the `rerun()` command to finish before actually evaluating the commands to rerun, thus ensuring that commands are run as if a user manually enters them... - repl.once( 'drain', onFinish ); - - /** - * Callback invoked once the `rerun()` command finishes. - * - * @private - * @param {string} cmd - command - * @param {boolean} success - boolean indicating whether the command successfully executed - * @returns {void} - */ - function onFinish() { - var n; - var i; - var j; - - if ( nargs === 0 ) { - // Evaluate the last command... - repl._rli.write( repl._history[ len-2 ]+'\n' ); - return; - } - if ( FLG === 1 ) { - // TODO: subsequence string parsing (use an iterator!!!) - return; - } - if ( FLG === 2 ) { - i = len - (3*arg); - if ( i < 0 ) { - n = len / 3; - i = 0; - } else { - n = arg; - } - // Evaluate the most recent `n` commands... - i += 1; - j = 0; - for ( ; i < len; i += 3 ) { - repl._rli.write( repl._history[ i ]+'\n' ); - if ( j < n-1 ) { - displayPrompt( repl, false ); - } - j += 1; - } - return; - } - if ( FLG === 3 ) { - // Scan the history for the most recent command matching the regular expression... - for ( i = len-2; i >= 0; i -= 3 ) { - if ( arg.test( repl._history[ i ] ) ) { - repl._rli.write( repl._history[ i ]+'\n' ); - return; - } - } - return; - } - // Case: FLG === 4 - n = arg.length; - for ( i = 0; i < n; i++ ) { - // Scan the history for the command identifier... - for ( j = 0; j < len; j += 3 ) { - if ( arg[ i ] === repl._history[ j ] ) { - repl._rli.write( repl._history[ j+1 ]+'\n' ); - if ( i < n-1 ) { - displayPrompt( repl, false ); - } - break; - } - } - } - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `reset` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Resets a REPL's local context. - * - * @private - */ - function onCommand() { - repl.reset(); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2025 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var format = require( '@stdlib/string/format' ); -var contains = require( '@stdlib/array/base/assert/contains' ).factory; -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var ACTIONS = require( './../actions.js' ); - - -// VARIABLES // - -var isAction = contains( ACTIONS ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `setKeybinding` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Sets a keybinding. - * - * @private - * @param {string} action - action name - * @param {Array<Object>} [keys] - list of keys - * @returns {void} - */ - function onCommand() { - var action; - var nargs; - var keys; - - nargs = arguments.length; - if ( nargs === 0 ) { - repl._ostream.write( 'Error: invalid argument. First argument must be an action name.\n' ); - return; - } - action = arguments[ 0 ]; - if ( nargs === 1 ) { - if ( !isString( action ) ) { - repl._ostream.write( format( 'Error: invalid argument. First argument must be a string. Value: `%s`.\n', action ) ); - return; - } - if ( !isAction( action ) ) { - repl._ostream.write( format( 'Error: invalid argument. First argument must be a valid action name. Value: `%s`.\n', action ) ); - return; - } - repl._ostream.write( 'Listening for keypresses...' ); - repl._isCapturingKeybinding = true; - repl._targetAction = action; - return; - } - keys = arguments[ 1 ]; - try { - repl.setKeybinding( action, keys ); - repl._ostream.write( format( '\nSuccessfully set keybindings for action `%s`.\n', action ) ); - } catch ( err ) { - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - } - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x - - - - - - - - - - - - - - - - - - -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); -var SETTINGS = require( './../settings.js' ); -var SETTINGS_NAMES = require( './../settings_names.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:settings' ); - - -// FUNCTIONS // - -/** -* Returns settings help text. -* -* @private -* @param {Object} settings - REPL settings -* @returns {string} settings help text -*/ -function help( settings ) { - var HELP_TEXT; - var name; - var o; - var i; - - HELP_TEXT = '\n'; - for ( i = 0; i < SETTINGS_NAMES.length; i++ ) { - name = SETTINGS_NAMES[ i ]; - o = SETTINGS[ name ]; - HELP_TEXT += name + '\n'; - HELP_TEXT += ' '; - HELP_TEXT += o.desc; // TODO: auto-wrap description - HELP_TEXT += format( ' Value: %s.', settings[ name ] ); - HELP_TEXT += '\n\n'; - } - return HELP_TEXT; -} - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `settings` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Gets (and sets) REPL settings. - * - * @private - * @param {string} [name] - setting name - * @param {*} [value] - new setting value - * @returns {(void|*)} setting value or undefined - */ - function onCommand() { - var nargs; - var v; - - nargs = arguments.length; - if ( nargs === 0 ) { - repl._ostream.write( help( repl._settings ) ); - return; - } - if ( nargs === 1 ) { - try { - v = repl.settings( arguments[ 0 ] ); - } catch ( err ) { - debug( 'Error: %s', err.message ); - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - return; - } - return v; - } - try { - repl.settings( arguments[ 0 ], arguments[ 1 ] ); - } catch ( err ) { - debug( 'Error: %s', err.message ); - repl._ostream.write( format( 'Error: %s\n', err.message ) ); - return; - } - log( repl, '\nSuccessfully updated setting.' ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2024 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `themes` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a list of available syntax highlighting color themes. - * - * @private - * @returns {Array<string>} list of available themes - */ - function onCommand() { - return repl.themes(); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x - - - - - - - - - - - - - - - - - - - - - - - -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var format = require( '@stdlib/string/format' ); -var TUTORIALS = require( './../repl_docs.js' ).tutorial; - - -// VARIABLES // - -var debug = logger( 'repl:command:tutorial' ); -var HELP_TEXT; - - -// FUNCTIONS // - -/** -* Returns tutorial help text. -* -* @private -* @returns {string} tutorial help text -*/ -function help() { - var names; - var o; - var i; - - if ( HELP_TEXT ) { - return HELP_TEXT; - } - names = objectKeys( TUTORIALS ); - HELP_TEXT = '\n'; - for ( i = 0; i < names.length; i++ ) { - o = TUTORIALS[ names[ i ] ]; - HELP_TEXT += names[ i ] + '\n'; - HELP_TEXT += ' '; - if ( o.desc ) { - HELP_TEXT += TUTORIALS[ names[ i ] ].desc; - } else { - HELP_TEXT += '(no description available)'; - } - HELP_TEXT += '\n\n'; - } - return HELP_TEXT; -} - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `tutorial` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Starts a tutorial if provided a recognized tutorial name; otherwise, returns the list of available tutorials. - * - * @private - * @param {string} [name] - tutorial name - * @param {Options} [options] - tutorial options - * @param {string} [options.borderTop='*'] - top border character sequence - * @param {string} [options.borderBottom='*'] - bottom border character sequence - * @param {string} [options.borderLeft='* '] - left border character sequence - * @param {string} [options.borderRight=' *'] - right border character sequence - * @param {(boolean|string)} [options.counter='progress'] - slide counter - * @param {string} [options.workspace] - REPL workspace name - * @param {boolean} [options.autoClear=true] - boolean indicating whether to automatically clear the screen before writing a rendered slide to the REPL - * @returns {(NonNegativeInteger|void)} tutorial presentation identifier - */ - function onCommand( name, options ) { - var opts; - var err; - if ( arguments.length === 0 ) { - repl._ostream.write( help() ); - return; - } - if ( !isString( name ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( !hasOwnProp( TUTORIALS, name ) ) { - err = new Error( format( 'invalid argument. Unrecognized tutorial name. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - debug( 'Tutorial: %s', name ); - - // Define default options: - opts = { - 'borderTop': '*', - 'borderBottom': '*', - 'borderLeft': '* ', - 'borderRight': ' *', - 'autoClear': true, - 'counter': 'progress', - 'workspace': 'tutorial-'+name+'-'+(repl._internal.presentation.counter+1 ) - }; - - // Handle user-provided options... - if ( arguments.length > 1 ) { - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - // Punt option validation to the presentation API... - if ( hasOwnProp( options, 'borderTop' ) ) { - opts.borderTop = options.borderTop; - } - if ( hasOwnProp( options, 'borderBottom' ) ) { - opts.borderBottom = options.borderBottom; - } - if ( hasOwnProp( options, 'borderLeft' ) ) { - opts.borderLeft = options.borderLeft; - } - if ( hasOwnProp( options, 'borderRight' ) ) { - opts.borderRight = options.borderRight; - } - if ( hasOwnProp( options, 'counter' ) ) { - opts.counter = options.counter; - } - if ( hasOwnProp( options, 'autoClear' ) ) { - opts.autoClear = options.autoClear; - } - if ( hasOwnProp( options, 'workspace' ) ) { - opts.workspace = options.workspace; - } - } - debug( 'Options: %s', JSON.stringify( opts ) ); - - debug( 'Starting tutorial...' ); - return repl._context.presentationStart( TUTORIALS[ name ].text, opts ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -2x -2x -2x -2x -2x -2x - - - - - -2x -2x -2x - - - -2x - - - - - -2x -2x -2x -2x -2x -2x - - - - - - - - -2x -2x -2x -2x -2x -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:userdoc' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `userDoc` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Adds user-defined documentation. - * - * ## Notes - * - * - If user-defined documentation already exists for a provided alias, the current documentation is overwritten. - * - * @private - * @param {string} alias - alias - * @param {*} [ref] - object reference - * @param {string} doc - documentation - * @returns {void} - */ - function onCommand( alias, ref, doc ) { - var buf; - var err; - var d; - var r; - var i; - if ( !isString( alias ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', alias ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( arguments.length < 3 ) { - d = ref; - } else { - r = ref; - d = doc; - } - if ( !isString( d ) ) { - err = new TypeError( format( 'invalid argument. Documentation argument must be a string. Value: `%s`.', d ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - buf = repl._userdocs; - - // TODO: extract `info`, examples, etc - - // Search for existing documentation to overwrite... - for ( i = 0; i < buf.length; i += 3 ) { - if ( buf[ i ] === alias ) { - buf[ i+1 ] = r; - buf[ i+2 ] = { - 'text': d - }; - return; - } - } - // Append new documentation: - buf.push( alias, r, { - 'text': d - }); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `vars` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a list of variable names in the current workspace. - * - * @private - * @param {Options} [options] - function options - * @param {RegExp} [options.include] - name inclusion filter - * @param {RegExp} [options.exclude] - name exclusion filter - * @param {ArrayLikeObject} [options.types] - type inclusion filter(s) - * @param {boolean} [options.details] - boolean indicating whether to include additional variable details, such as variable type, contents, etc - * @returns {(Array|void)} workspace variable names - */ - function onCommand( options ) { - var opts; - if ( arguments.length ) { - opts = options; - } else { - opts = {}; - } - return repl._context.varsWorkspace( repl._currentWorkspace, opts ); - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 -138 -139 -140 -141 -142 -143 -144 -145 -146 -147 -148 -149 -150 -151 -152 -153 -154 -155 -156 -157 -158 -159 -160 -161 -162 -163 -164 -165 -166 -167 -168 -169 -170 -171 -172 -173 -174 -175 -176 -177 -178 -179 -180 -181 -182 -183 -184 -185 -186 -187 -188 -189 -190 -191 -192 -193 -194 -195 -196 -197 -198 -199 -200 -201 -202 -203 -204 -205 -206 -207 -208 -209 -210 -211 -212 -213 -214 -215 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var isArrayLike = require( '@stdlib/assert/is-array-like-object' ); -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var isReadableProperty = require( '@stdlib/assert/is-readable-property' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var properties = require( '@stdlib/utils/properties' ); -var typeOf = require( '@stdlib/utils/type-of' ); -var format = require( '@stdlib/string/format' ); -var setdiff = require( './../setdiff.js' ); -var propertyComparator = require( './../property_comparator.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:vars_workspace' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `varsWorkspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a list of variable names in a specified workspace. - * - * @private - * @param {string} [name] - workspace name - * @param {Options} [options] - function options - * @param {RegExp} [options.include] - name inclusion filter - * @param {RegExp} [options.exclude] - name exclusion filter - * @param {ArrayLikeObject} [options.types] - type inclusion filter(s) - * @param {boolean} [options.details] - boolean indicating whether to include additional variable details, such as variable type, contents, etc - * @returns {(Array|void)} workspace variable names - */ - function onCommand( name, options ) { - var opts; - var list; - var type; - var err; - var tmp; - var out; - var FLG; - var v; - var n; - var i; - var j; - - if ( arguments.length === 0 ) { - return setdiff( repl._workspace, properties( repl._context ).sort( propertyComparator ) ); // eslint-disable-line max-len - } - if ( arguments.length === 1 ) { - if ( isString( name ) ) { - n = name; - opts = {}; - } else if ( isPlainObject( name ) ) { - opts = name; - } else { - err = new TypeError( format( 'invalid argument. Must provide either an options object or a workspace name. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - } else { - if ( !isString( name ) ) { - err = new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - n = name; - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - opts = options; - } - if ( hasOwnProp( opts, 'include' ) && !isRegExp( opts.include ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression. Option: `%s`.', 'include', opts.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( opts, 'exclude' ) && !isRegExp( opts.exclude ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression. Option: `%s`.', 'exclude', opts.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( opts, 'types' ) && !isArrayLike( opts.types ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be an array-like object. Option: `%s`.', 'types', opts.types ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( opts, 'details' ) && !isBoolean( opts.details ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'details', opts.details ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( n === void 0 || n === repl._currentWorkspace ) { - tmp = properties( repl._context ).sort( propertyComparator ); - tmp = setdiff( repl._workspace, tmp ); - list = []; - for ( i = 0; i < tmp.length; i++ ) { - if ( isReadableProperty( repl._context, tmp[ i ] ) ) { - list.push( tmp[ i ], repl._context[ tmp[ i ] ] ); - } else { - // The variable can be set, but not retrieved (i.e., is write-only), so value inspection is not possible without triggering an error... - list.push( tmp[ i ], void 0 ); - } - } - } else { - if ( !hasOwnProp( repl._workspaces, n ) ) { - err = new Error( format( 'invalid argument. Unrecognized workspace name. Value: `%s`.', n ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - list = repl._workspaces[ n ].slice(); - for ( i = 1; i < list.length; i += 2 ) { - if ( typeof list[ i ].get === 'function' ) { - // WARNING: the `this` context is not defined, as the variable is not actually bound to a global instance! - list[ i ] = list[ i ].get.call( null ); - } else if ( typeof list[ i ].set === 'function' ) { - // The variable can be set, but not retrieved (i.e., is write-only), so value inspection is not possible without triggering an error... - list[ i ] = void 0; - } else { - list[ i ] = list[ i ].value; - } - } - } - out = []; - for ( i = 0; i < list.length; i += 2 ) { - v = list[ i ]; - FLG = false; - type = ''; - if ( opts.include && !opts.include.test( v ) ) { - continue; - } - if ( opts.exclude && opts.exclude.test( v ) ) { - continue; - } - if ( opts.types ) { - type = typeOf( list[ i+1 ] ); - for ( j = 0; j < opts.types.length; j++ ) { - if ( type === opts.types[ j ] ) { - FLG = true; - break; - } - } - if ( FLG === false ) { - continue; - } - } - // If we've made it this far, the variable should have passed all filters... - out.push( v ); - if ( opts.details ) { - j = out.length - 1; - out[ j ] = { - 'name': out[ j ], - 'type': type || typeOf( list[ i+1 ] ), - 'data': String( list[ i+1 ] ) // WARNING: for large datasets, this could be expensive!!! TODO: may want to consider alternative strategies for serialization based on a value's type. - }; - v = out[ j ].data; - if ( v.length > 20 ) { - out[ j ].data = v.slice( 0, 9 ) + '...' + v.slice( v.length-8 ); - } - } - } - return out; - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 -124 -125 -126 -127 -128 -129 -130 -131 -132 -133 -134 -135 -136 -137 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var propertyDescriptor = require( '@stdlib/utils/property-descriptor' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var format = require( '@stdlib/string/format' ); -var log = require( './../log.js' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:workspace' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `workspace` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Switches to a specified workspace. - * - * @private - * @param {string} name - workspace name - * @returns {void} - */ - function onCommand( name ) { - var vars; - var curr; - var desc; - var err; - var ws; - var i; - if ( !isString( name ) ) { - err = new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - curr = repl._currentWorkspace; - if ( name === curr ) { - log( repl, 'Already in \''+name+'\' workspace.' ); - debug( 'Already in \'%s\' workspace.', name ); - return; - } - // Cache and delete the current workspace variables... - vars = repl._context.varsWorkspace( curr ); - ws = repl._workspaces[ curr ]; - ws.length = 0; // reset - for ( i = 0; i < vars.length; i++ ) { - desc = propertyDescriptor( repl._context, vars[ i ] ); - ws.push( vars[ i ], desc ); - - // WARNING: in non-sandboxed environments, we run the risk of deleting global variables which were not introduced by the REPL environment... - if ( desc.configurable ) { - delete repl._context[ vars[ i ] ]; - } - } - // Reset the REPL evaluation context (Why? Because we cannot simply delete variables as seen within the REPL environment. E.g., variables declared with `var` in the global scope are non-configurable, and, thus, cannot be deleted (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete). Hence, while we can delete a property/variable here, this deletion does not get propagated to within the REPL environment; i.e., a user can still access the deleted property as a variable within the REPL environment.): - repl.resetContext(); - - // If the destination workspace already exists, load the workspace's variables... - if ( hasOwnProp( repl._workspaces, name ) ) { - ws = repl._workspaces[ name ]; - for ( i = 0; i < ws.length; i += 2 ) { - desc = propertyDescriptor( repl._context, ws[ i ] ); - - // If the variable does not already exist in the current evaluation context, define a new variable... - if ( desc === null ) { - defineProperty( repl._context, ws[ i ], ws[ i+1 ] ); - } - // If configurable, we can simply overwrite the existing property descriptor... - else if ( desc.configurable ) { - defineProperty( repl._context, ws[ i ], ws[ i+1 ] ); - } - // Otherwise, use direct assignment if the variable is writable... - else if ( hasOwnProp( desc, 'value' ) || hasOwnProp( desc, 'set' ) ) { - repl._context[ ws[ i ] ] = ws[ i+1 ]; - } - // Cannot assign to the variable as the variable is read-only... - else { - log( repl, 'Cannot load \''+ws[ i ]+'\' from \''+name+'\' workspace due to the presence of a non-configurable read-only variable of the same name.' ); - debug( 'Cannot load \'%s\' from \'%s\' workspace due to the presence of a non-configurable read-only variable of the same name.', ws[ i ], name ); - } - } - ws.length = 0; // free up memory and prevent holding on to old references - log( repl, 'Switched to \''+name+'\' workspace.' ); - debug( 'Switched to %s workspace.', name ); - } - // Otherwise, create a new workspace... - else { - repl._workspaces[ name ] = []; - log( repl, 'Created and switched to \''+name+'\' workspace.' ); - debug( 'Created and switched to %s workspace.', name ); - } - - // Update the current workspace variable: - repl._currentWorkspace = name; // bookkeeping - } -} - - -// EXPORTS // - -module.exports = command; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 -110 -111 -112 -113 -114 -115 -116 -117 -118 -119 -120 -121 -122 -123 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x -127x - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -127x -11x -11x -11x -11x -11x - | /** -* @license Apache-2.0 -* -* Copyright (c) 2019 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var logger = require( 'debug' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isPlainObject = require( '@stdlib/assert/is-plain-object' ); -var isRegExp = require( '@stdlib/assert/is-regexp' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var objectKeys = require( '@stdlib/utils/keys' ); -var format = require( '@stdlib/string/format' ); - - -// VARIABLES // - -var debug = logger( 'repl:command:workspaces' ); - - -// MAIN // - -/** -* Returns a callback to be invoked upon calling the `workspaces` command. -* -* @private -* @param {REPL} repl - REPL instance -* @returns {Function} callback -*/ -function command( repl ) { - return onCommand; - - /** - * Returns a list of workspaces. - * - * @private - * @param {Options} [options] - function options - * @param {RegExp} [options.include] - name inclusion filter - * @param {RegExp} [options.exclude] - name exclusion filter - * @param {boolean} [options.details] - boolean indicating whether to include additional workspace details, such as variable names, types, contents, etc - * @returns {Array} workspace names - */ - function onCommand( options ) { - var err; - var tmp; - var out; - var w; - var i; - if ( arguments.length === 0 ) { - return objectKeys( repl._workspaces ); - } - if ( !isPlainObject( options ) ) { - err = new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', name ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( options, 'include' ) && !isRegExp( options.include ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression. Option: `%s`.', 'include', options.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( options, 'exclude' ) && !isRegExp( options.exclude ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a regular expression. Option: `%s`.', 'exclude', options.include ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - if ( hasOwnProp( options, 'details' ) && !isBoolean( options.details ) ) { - err = new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'details', options.details ) ); - debug( 'Error: %s', err.message ); - repl._ostream.write( 'Error: '+err.message+'\n' ); - return; - } - tmp = objectKeys( repl._workspaces ); - out = []; - for ( i = 0; i < tmp.length; i++ ) { - w = tmp[ i ]; - if ( options.include && !options.include.test( w ) ) { - continue; - } - if ( options.exclude && options.exclude.test( w ) ) { - continue; - } - // If we've made it this far, the variable should have passed all filters... - out.push( w ); - if ( options.details ) { - out[ out.length-1 ] = { - 'name': w, - 'variables': repl._context.varsWorkspace( w, { - 'details': true - }) - }; - } - } - return out; - } -} - - -// EXPORTS // - -module.exports = command; - |