diff --git a/bench/harness/benchmark-class/assert.js.html b/bench/harness/benchmark-class/assert.js.html deleted file mode 100644 index 7396195b42..0000000000 --- a/bench/harness/benchmark-class/assert.js.html +++ /dev/null @@ -1,289 +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 -61 -62 -63 -64 -65 -66 -67 -68 -69 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10775x -10589x -10589x -10775x -10589x -10589x -10775x -127x -127x -127x -127x -127x -10775x -10775x -10775x -12x -12x -12x -12x -12x - | /** -* @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. -*/ - -/* eslint-disable no-invalid-this */ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); - - -// MAIN // - -/** -* Generates an assertion. -* -* @private -* @param {boolean} ok - assertion outcome -* @param {Options} opts - options -*/ -function assert( ok, opts ) { - var result; - var err; - - result = { - 'id': this._count, - 'ok': ok, - 'skip': opts.skip, - 'todo': opts.todo, - 'name': opts.message || '(unnamed assert)', - 'operator': opts.operator - }; - if ( hasOwnProp( opts, 'actual' ) ) { - result.actual = opts.actual; - } - if ( hasOwnProp( opts, 'expected' ) ) { - result.expected = opts.expected; - } - if ( !ok ) { - result.error = opts.error || new Error( this.name ); - err = new Error( 'not implemented' ); // eslint-disable-line no-unused-vars - - // TODO: generate an exception in order to locate the calling function (https://github.com/substack/tape/blob/master/lib/test.js#L215) - } - this._count += 1; - this.emit( 'result', result ); -} - - -// EXPORTS // - -module.exports = assert; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x - | /** -* @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'; - -// EXPORTS // - -module.exports = clearTimeout; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -42x -42x -42x -42x -42x -42x -42x -48x -48x -48x -48x -42x -12x -12x -12x -12x -12x - | /** -* @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 trim = require( '@stdlib/string/base/trim' ); -var replace = require( '@stdlib/string/base/replace' ); -var EOL = require( '@stdlib/regexp/eol' ).REGEXP; - - -// VARIABLES // - -var RE_COMMENT = /^#\s*/; - - -// MAIN // - -/** -* Writes a comment. -* -* @private -* @param {string} msg - comment message -*/ -function comment( msg ) { - /* eslint-disable no-invalid-this */ - var lines; - var i; - msg = trim( msg ); - lines = msg.split( EOL ); - for ( i = 0; i < lines.length; i++ ) { - msg = trim( lines[ i ] ); - msg = replace( msg, RE_COMMENT, '' ); - this.emit( 'result', msg ); - } -} - - -// EXPORTS // - -module.exports = comment; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x - - - - - - -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Asserts that `actual` is deeply equal to `expected`. -* -* @private -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] message -*/ -function deepEqual( actual, expected, msg ) { - /* eslint-disable no-invalid-this */ - this.comment( 'actual: '+actual+'. expected: '+expected+'. msg: '+msg+'.' ); - - // TODO: implement -} - - -// EXPORTS // - -module.exports = deepEqual; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -302x -302x -302x -302x -1x -302x -301x -301x -301x -302x -302x -302x -302x -302x -302x -302x -302x -302x -301x -301x -302x -12x -12x -12x -12x -12x - | /** -* @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 nextTick = require( './../utils/next_tick.js' ); - - -// MAIN // - -/** -* Ends a benchmark. -* -* @private -*/ -function end() { - /* eslint-disable no-invalid-this */ - var self = this; - if ( this._ended ) { - this.fail( '.end() called more than once' ); - } else { - // Prevents releasing the zalgo when running synchronous benchmarks. - nextTick( onTick ); - } - this._ended = true; - this._running = false; - - /** - * Callback invoked upon a subsequent tick of the event loop. - * - * @private - */ - function onTick() { - self.emit( 'end' ); - } -} - - -// EXPORTS // - -module.exports = end; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -140x -140x -140x -140x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Returns a `boolean` indicating if a benchmark has ended. -* -* @private -* @returns {boolean} boolean indicating if a benchmark has ended -*/ -function ended() { - /* eslint-disable no-invalid-this */ - return this._ended; -} - - -// EXPORTS // - -module.exports = ended; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -1773x -1773x -1773x -1773x -1773x -1773x -1773x -1773x -1773x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Asserts that `actual` is strictly equal to `expected`. -* -* @private -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] - message -*/ -function equal( actual, expected, msg ) { - /* eslint-disable no-invalid-this */ - this._assert( actual === expected, { - 'message': msg || 'should be equal', - 'operator': 'equal', - 'expected': expected, - 'actual': actual - }); -} - - -// EXPORTS // - -module.exports = equal; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -24x -24x -24x -14x -14x -14x -10x -24x -9x -9x -9x -9x -9x -6x -6x -9x -24x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Forcefully ends a benchmark. -* -* @private -* @returns {void} -*/ -function exit() { - /* eslint-disable no-invalid-this */ - if ( this._exited ) { - // If we have already "exited", do not create more failing assertions when one should suffice... - return; - } - // Only "exit" when a benchmark has either not yet been run or is currently running. If a benchmark has already ended, no need to generate a failing assertion. - if ( !this._ended ) { - this._exited = true; - this.fail( 'benchmark exited without ending' ); - - // Allow running benchmarks to call `end` on their own... - if ( !this._running ) { - this.end(); - } - } -} - - -// EXPORTS // - -module.exports = exit; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -45x -45x -45x -45x -45x -45x -45x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Generates a failing assertion. -* -* @private -* @param {string} msg - message -*/ -function fail( msg ) { - /* eslint-disable no-invalid-this */ - this._assert( false, { - 'message': msg, - 'operator': 'fail' - }); -} - - -// EXPORTS // - -module.exports = fail; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
---|---|---|---|---|---|---|---|---|---|
assert.js | -
-
- |
- 100% | -68/68 | -100% | -6/6 | -100% | -1/1 | -100% | -68/68 | -
clear_timeout.js | -
-
- |
- 100% | -23/23 | -100% | -1/1 | -100% | -0/0 | -100% | -23/23 | -
comment.js | -
-
- |
- 100% | -57/57 | -100% | -3/3 | -100% | -1/1 | -100% | -57/57 | -
deep_equal.js | -
-
- |
- 85.36% | -35/41 | -100% | -1/1 | -0% | -0/1 | -85.36% | -35/41 | -
end.js | -
-
- |
- 100% | -58/58 | -100% | -5/5 | -100% | -2/2 | -100% | -58/58 | -
ended.js | -
-
- |
- 100% | -37/37 | -100% | -2/2 | -100% | -1/1 | -100% | -37/37 | -
equal.js | -
-
- |
- 100% | -44/44 | -100% | -3/3 | -100% | -1/1 | -100% | -44/44 | -
exit.js | -
-
- |
- 100% | -50/50 | -100% | -6/6 | -100% | -1/1 | -100% | -50/50 | -
fail.js | -
-
- |
- 100% | -40/40 | -100% | -2/2 | -100% | -1/1 | -100% | -40/40 | -
index.js | -
-
- |
- 100% | -375/375 | -100% | -12/12 | -100% | -3/3 | -100% | -375/375 | -
not_deep_equal.js | -
-
- |
- 85.36% | -35/41 | -100% | -1/1 | -0% | -0/1 | -85.36% | -35/41 | -
not_equal.js | -
-
- |
- 100% | -44/44 | -100% | -3/3 | -100% | -1/1 | -100% | -44/44 | -
not_ok.js | -
-
- |
- 100% | -43/43 | -100% | -3/3 | -100% | -1/1 | -100% | -43/43 | -
ok.js | -
-
- |
- 100% | -43/43 | -100% | -3/3 | -100% | -1/1 | -100% | -43/43 | -
pass.js | -
-
- |
- 100% | -40/40 | -100% | -2/2 | -100% | -1/1 | -100% | -40/40 | -
run.js | -
-
- |
- 100% | -79/79 | -100% | -8/8 | -100% | -3/3 | -100% | -79/79 | -
set_timeout.js | -
-
- |
- 100% | -23/23 | -100% | -1/1 | -100% | -0/0 | -100% | -23/23 | -
skip.js | -
-
- |
- 100% | -42/42 | -100% | -2/2 | -100% | -1/1 | -100% | -42/42 | -
todo.js | -
-
- |
- 100% | -42/42 | -100% | -2/2 | -100% | -1/1 | -100% | -42/42 | -
- 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 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 -305 -306 -307 -308 -309 -310 -311 -312 -313 -314 -315 -316 -317 -318 -319 -320 -321 -322 -323 -324 -325 -326 -327 -328 -329 -330 -331 -332 -333 -334 -335 -336 -337 -338 -339 -340 -341 -342 -343 -344 -345 -346 -347 -348 -349 -350 -351 -352 -353 -354 -355 -356 -357 -358 -359 -360 -361 -362 -363 -364 -365 -366 -367 -368 -369 -370 -371 -372 -373 -374 -375 -376 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -326x -326x -326x -326x -326x -326x -1x -1x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -325x -286x -1x -286x -285x -285x -285x -285x -286x -325x -325x -325x -325x -325x -325x -325x -325x -286x -286x -286x -286x -286x -286x -1x -1x -285x -286x -1x -1x -284x -284x -284x -284x -284x -284x -284x -284x -284x -284x -284x -284x -284x -284x -286x -326x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x - | /** -* @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 EventEmitter = require( 'events' ).EventEmitter; -var inherit = require( '@stdlib/utils/inherit' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var tic = require( '@stdlib/time/tic' ); -var toc = require( '@stdlib/time/toc' ); -var run = require( './run.js' ); -var exit = require( './exit.js' ); -var ended = require( './ended.js' ); -var assert = require( './assert.js' ); -var comment = require( './comment.js' ); -var skip = require( './skip.js' ); -var todo = require( './todo.js' ); -var fail = require( './fail.js' ); -var pass = require( './pass.js' ); -var ok = require( './ok.js' ); -var notOk = require( './not_ok.js' ); -var equal = require( './equal.js' ); -var notEqual = require( './not_equal.js' ); -var deepEqual = require( './deep_equal.js' ); -var notDeepEqual = require( './not_deep_equal.js' ); -var end = require( './end.js' ); - - -// MAIN // - -/** -* Benchmark constructor. -* -* @constructor -* @param {string} name - benchmark name -* @param {Options} opts - benchmark options -* @param {boolean} opts.skip - boolean indicating whether to skip a benchmark -* @param {PositiveInteger} opts.iterations - number of iterations -* @param {PositiveInteger} opts.timeout - number of milliseconds before a benchmark automatically fails -* @param {Function} [benchmark] - function containing benchmark code -* @returns {Benchmark} Benchmark instance -* -* @example -* var bench = new Benchmark( 'beep', function benchmark( b ) { -* var x; -* var i; -* b.comment( 'Running benchmarks...' ); -* b.tic(); -* for ( i = 0; i < b.iterations; i++ ) { -* x = Math.sin( Math.random() ); -* if ( x !== x ) { -* b.ok( false, 'should not return NaN' ); -* } -* } -* b.toc(); -* if ( x !== x ) { -* b.ok( false, 'should not return NaN' ); -* } -* b.comment( 'Finished running benchmarks.' ); -* b.end(); -* }); -*/ -function Benchmark( name, opts, benchmark ) { - var hasTicked; - var hasTocked; - var self; - var time; - if ( !( this instanceof Benchmark ) ) { - return new Benchmark( name, opts, benchmark ); - } - self = this; - hasTicked = false; - hasTocked = false; - - EventEmitter.call( this ); - - // Private properties: - setReadOnly( this, '_benchmark', benchmark ); - setReadOnly( this, '_skip', opts.skip ); - - defineProperty( this, '_ended', { - 'configurable': false, - 'enumerable': false, - 'writable': true, - 'value': false - }); - - defineProperty( this, '_running', { - 'configurable': false, - 'enumerable': false, - 'writable': true, - 'value': false - }); - - defineProperty( this, '_exited', { - 'configurable': false, - 'enumerable': false, - 'writable': true, - 'value': false - }); - - defineProperty( this, '_count', { - 'configurable': false, - 'enumerable': false, - 'writable': true, - 'value': 0 - }); - - // Read-only: - setReadOnly( this, 'name', name ); - setReadOnly( this, 'tic', start ); - setReadOnly( this, 'toc', stop ); - setReadOnly( this, 'iterations', opts.iterations ); - setReadOnly( this, 'timeout', opts.timeout ); - - return this; - - /** - * Starts a benchmark timer. - * - * ## Notes - * - * - Using a scoped variable prevents nefarious mutation by bad actors hoping to manipulate benchmark results. - * - The one attack vector which remains is manipulation of the `require` cache for `tic` and `toc`. - * - One way to combat cache manipulation is by comparing the checksum of `Function#toString()` against known values. - * - * @private - */ - function start() { - if ( hasTicked ) { - self.fail( '.tic() called more than once' ); - } else { - self.emit( 'tic' ); - hasTicked = true; - time = tic(); - } - } - - /** - * Stops a benchmark timer. - * - * @private - * @returns {void} - */ - function stop() { - var elapsed; - var secs; - var rate; - var out; - - if ( hasTicked === false ) { - return self.fail( '.toc() called before .tic()' ); - } - elapsed = toc( time ); - if ( hasTocked ) { - return self.fail( '.toc() called more than once' ); - } - hasTocked = true; - self.emit( 'toc' ); - - secs = elapsed[ 0 ] + ( elapsed[ 1 ]/1e9 ); - rate = self.iterations / secs; - - out = { - 'ok': true, - 'operator': 'result', - 'iterations': self.iterations, - 'elapsed': secs, - 'rate': rate - }; - self.emit( 'result', out ); - } -} - -/* -* Inherit from the `EventEmitter` prototype. -*/ -inherit( Benchmark, EventEmitter ); - -/** -* Runs a benchmark. -* -* @private -* @name run -* @memberof Benchmark.prototype -* @type {Function} -*/ -setReadOnly( Benchmark.prototype, 'run', run ); - -/** -* Forcefully ends a benchmark. -* -* @private -* @name exit -* @memberof Benchmark.prototype -* @type {Function} -*/ -setReadOnly( Benchmark.prototype, 'exit', exit ); - -/** -* Returns a `boolean` indicating if a benchmark has ended. -* -* @private -* @name ended -* @memberof Benchmark.prototype -* @type {Function} -* @returns {boolean} boolean indicating if a benchmark has ended -*/ -setReadOnly( Benchmark.prototype, 'ended', ended ); - -/** -* Generates an assertion. -* -* @private -* @name _assert -* @memberof Benchmark.prototype -* @type {Function} -* @param {boolean} ok - assertion outcome -* @param {Options} opts - options -*/ -setReadOnly( Benchmark.prototype, '_assert', assert ); - -/** -* Writes a comment. -* -* @name comment -* @memberof Benchmark.prototype -* @type {Function} -* @param {string} msg - comment message -*/ -setReadOnly( Benchmark.prototype, 'comment', comment ); - -/** -* Generates an assertion which will be skipped. -* -* @name skip -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} value - value -* @param {string} msg - message -*/ -setReadOnly( Benchmark.prototype, 'skip', skip ); - -/** -* Generates an assertion which should be implemented. -* -* @name todo -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} value - value -* @param {string} msg - message -*/ -setReadOnly( Benchmark.prototype, 'todo', todo ); - -/** -* Generates a failing assertion. -* -* @name fail -* @memberof Benchmark.prototype -* @type {Function} -* @param {string} msg - message -*/ -setReadOnly( Benchmark.prototype, 'fail', fail ); - -/** -* Generates a passing assertion. -* -* @name pass -* @memberof Benchmark.prototype -* @type {Function} -* @param {string} msg - message -*/ -setReadOnly( Benchmark.prototype, 'pass', pass ); - -/** -* Asserts that a `value` is truthy. -* -* @name ok -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} value - value -* @param {string} [msg] - message -*/ -setReadOnly( Benchmark.prototype, 'ok', ok ); - -/** -* Asserts that a `value` is falsy. -* -* @name notOk -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} value - value -* @param {string} [msg] - message -*/ -setReadOnly( Benchmark.prototype, 'notOk', notOk ); - -/** -* Asserts that `actual` is strictly equal to `expected`. -* -* @name equal -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] - message -*/ -setReadOnly( Benchmark.prototype, 'equal', equal ); - -/** -* Asserts that `actual` is not strictly equal to `expected`. -* -* @name notEqual -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] - message -*/ -setReadOnly( Benchmark.prototype, 'notEqual', notEqual ); - -/** -* Asserts that `actual` is deeply equal to `expected`. -* -* @name deepEqual -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] message -*/ -setReadOnly( Benchmark.prototype, 'deepEqual', deepEqual ); - -/** -* Asserts that `actual` is not deeply equal to `expected`. -* -* @name notDeepEqual -* @memberof Benchmark.prototype -* @type {Function} -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] message -*/ -setReadOnly( Benchmark.prototype, 'notDeepEqual', notDeepEqual ); - -/** -* Ends a benchmark. -* -* @name end -* @memberof Benchmark.prototype -* @type {Function} -*/ -setReadOnly( Benchmark.prototype, 'end', end ); - - -// EXPORTS // - -module.exports = Benchmark; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x - - - - - - -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Asserts that `actual` is not deeply equal to `expected`. -* -* @private -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] message -*/ -function notDeepEqual( actual, expected, msg ) { - /* eslint-disable no-invalid-this */ - this.comment( 'actual: '+actual+'. expected: '+expected+'. msg: '+msg+'.' ); - - // TODO: implement -} - - -// EXPORTS // - -module.exports = notDeepEqual; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -16x -16x -16x -16x -16x -16x -16x -16x -16x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Asserts that `actual` is not strictly equal to `expected`. -* -* @private -* @param {*} actual - actual value -* @param {*} expected - expected value -* @param {string} [msg] - message -*/ -function notEqual( actual, expected, msg ) { - /* eslint-disable no-invalid-this */ - this._assert( actual !== expected, { - 'message': msg || 'should not be equal', - 'operator': 'notEqual', - 'expected': expected, - 'actual': actual - }); -} - - -// EXPORTS // - -module.exports = notEqual; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -15x -15x -15x -15x -15x -15x -15x -15x -15x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Asserts that a `value` is falsy. -* -* @private -* @param {*} value - value -* @param {string} [msg] - message -*/ -function notOk( value, msg ) { - /* eslint-disable no-invalid-this */ - this._assert( !value, { - 'message': msg || 'should be falsy', - 'operator': 'notOk', - 'expected': false, - 'actual': value - }); -} - - -// EXPORTS // - -module.exports = notOk; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -8785x -8785x -8785x -8785x -8785x -8785x -8785x -8785x -8785x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Asserts that a `value` is truthy. -* -* @private -* @param {*} value - value -* @param {string} [msg] - message -*/ -function ok( value, msg ) { - /* eslint-disable no-invalid-this */ - this._assert( !!value, { - 'message': msg || 'should be truthy', - 'operator': 'ok', - 'expected': true, - 'actual': value - }); -} - - -// EXPORTS // - -module.exports = ok; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -56x -56x -56x -56x -56x -56x -56x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Generates a passing assertion. -* -* @private -* @param {string} msg - message -*/ -function pass( msg ) { - /* eslint-disable no-invalid-this */ - this._assert( true, { - 'message': msg, - 'operator': 'pass' - }); -} - - -// EXPORTS // - -module.exports = pass; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -295x -295x -295x -295x -295x -3x -3x -3x -295x -5x -5x -5x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -287x -1x -1x -287x -287x -287x -287x -287x -287x -287x -287x -287x -295x -12x -12x -12x -12x -12x - | /** -* @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 timeout = require( './set_timeout.js' ); -var clear = require( './clear_timeout.js' ); - - -// MAIN // - -/** -* Runs a benchmark. -* -* @private -* @returns {void} -*/ -function run() { - /* eslint-disable no-invalid-this */ - var self; - var id; - if ( this._skip ) { - this.comment( 'SKIP '+this.name ); - return this.end(); - } - if ( !this._benchmark ) { - this.comment( 'TODO '+this.name ); - return this.end(); - } - self = this; - this._running = true; - - id = timeout( onTimeout, this.timeout ); - this.once( 'end', endTimeout ); - - this.emit( 'prerun' ); - this._benchmark( this ); - this.emit( 'run' ); - - /** - * Callback invoked once a timeout ends. - * - * @private - */ - function onTimeout() { - self.fail( 'benchmark timed out after '+self.timeout+'ms' ); - } - - /** - * Clears a timeout. - * - * @private - */ - function endTimeout() { - clear( id ); - } -} - - -// EXPORTS // - -module.exports = run; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x - | /** -* @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'; - -// EXPORTS // - -module.exports = setTimeout; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -41x -41x -41x -41x -41x -41x -41x -41x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Generates an assertion which will be skipped. -* -* @private -* @param {*} value - value -* @param {string} msg - message -*/ -function skip( value, msg ) { - /* eslint-disable no-invalid-this */ - this._assert( true, { - 'message': msg, - 'operator': 'skip', - 'skip': true - }); -} - - -// EXPORTS // - -module.exports = skip; - |
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -44x -44x -44x -44x -44x -44x -44x -44x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Generates an assertion which should be implemented. -* -* @private -* @param {*} value - value -* @param {string} msg - message -*/ -function todo( value, msg ) { - /* eslint-disable no-invalid-this */ - this._assert( !!value, { - 'message': msg, - 'operator': 'todo', - 'todo': true - }); -} - - -// EXPORTS // - -module.exports = todo; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
---|---|---|---|---|---|---|---|---|---|
index.js | -
-
- |
- 100% | -303/303 | -100% | -52/52 | -100% | -10/10 | -100% | -303/303 | -
init.js | -
-
- |
- 100% | -98/98 | -100% | -15/15 | -100% | -3/3 | -100% | -98/98 | -
iterations.js | -
-
- |
- 100% | -106/106 | -100% | -10/10 | -100% | -4/4 | -100% | -106/106 | -
pretest.js | -
-
- |
- 100% | -121/121 | -100% | -16/16 | -100% | -5/5 | -100% | -121/121 | -
validate.js | -
-
- |
- 100% | -96/96 | -100% | -17/17 | -100% | -1/1 | -100% | -96/96 | -
- 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 -255 -256 -257 -258 -259 -260 -261 -262 -263 -264 -265 -266 -267 -268 -269 -270 -271 -272 -273 -274 -275 -276 -277 -278 -279 -280 -281 -282 -283 -284 -285 -286 -287 -288 -289 -290 -291 -292 -293 -294 -295 -296 -297 -298 -299 -300 -301 -302 -303 -304 | 7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -88x -88x -88x -88x -88x -88x -88x -88x -88x -10x -1x -10x -1x -9x -8x -8x -88x -68x -9x -9x -68x -37x -37x -8x -8x -37x -51x -68x -9x -9x -68x -54x -88x -22x -22x -88x -43x -43x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -54x -160x -160x -160x -160x -36x -36x -124x -160x -38x -4x -38x -34x -34x -32x -32x -34x -160x -84x -84x -25x -25x -59x -84x -17x -17x -84x -50x -50x -50x -50x -160x -30x -30x -50x -160x -54x -54x -54x -54x -54x -54x -54x -54x -30x -30x -30x -30x -30x -30x -30x -30x -30x -30x -80x -80x -80x -80x -80x -80x -30x -30x -30x -50x -50x -50x -80x -30x -30x -30x -30x -30x -30x -30x -30x -30x -30x -30x -50x -50x -50x -50x -50x -110x -110x -110x -110x -50x -50x -30x -54x -54x -54x -54x -54x -54x -54x -54x -10265x -10265x -10265x -5x -10265x -5x -5x -10265x -54x -54x -54x -54x -54x -54x -54x -54x -54x -60x -46x -46x -14x -60x -54x -54x -54x -54x -54x -54x -54x -31x -31x -54x -54x -54x -54x -54x -54x -54x -3x -3x -54x -54x -54x -54x -54x -54x -54x -54x -12x -12x -54x -54x -54x -54x -54x -54x -54x -88x -7x -7x -7x -7x -7x - | /** -* @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 setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); -var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' ); -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isFunction = require( '@stdlib/assert/is-function' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var format = require( '@stdlib/string/format' ); -var copy = require( '@stdlib/utils/copy' ); -var Benchmark = require( './../benchmark-class' ); -var Runner = require( './../runner' ); -var nextTick = require( './../utils/next_tick.js' ); -var DEFAULTS = require( './../defaults.json' ); -var validate = require( './validate.js' ); -var init = require( './init.js' ); - - -// MAIN // - -/** -* Creates a benchmark harness. -* -* @param {Options} [options] - function options -* @param {boolean} [options.autoclose] - boolean indicating whether to automatically close a harness after a harness finishes running all benchmarks -* @param {Callback} [clbk] - callback to invoke when a harness finishes running all benchmarks -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {TypeError} callback argument must be a function -* @returns {Function} benchmark harness -* -* @example -* var bench = createHarness( onFinish ); -* -* function onFinish() { -* bench.close(); -* console.log( 'Exit code: %d', bench.exitCode ); -* } -* -* bench( 'beep', function benchmark( b ) { -* var x; -* var i; -* b.tic(); -* for ( i = 0; i < b.iterations; i++ ) { -* x = Math.sin( Math.random() ); -* if ( x !== x ) { -* b.ok( false, 'should not return NaN' ); -* } -* } -* b.toc(); -* if ( x !== x ) { -* b.ok( false, 'should not return NaN' ); -* } -* b.end(); -* }); -* -* @example -* var stdout = require( '@stdlib/streams/node/stdout' ); -* -* var stream = createHarness().createStream(); -* stream.pipe( stdout ); -*/ -function createHarness( options, clbk ) { - var exitCode; - var runner; - var queue; - var opts; - var cb; - - opts = {}; - if ( arguments.length === 1 ) { - if ( isFunction( options ) ) { - cb = options; - } else if ( isObject( options ) ) { - opts = options; - } else { - throw new TypeError( format( 'invalid argument. Must provide either an options object or a function. Value: `%s`.', options ) ); - } - } else if ( arguments.length > 1 ) { - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. First argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'autoclose' ) ) { - opts.autoclose = options.autoclose; - if ( !isBoolean( opts.autoclose ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'autoclose', opts.autoclose ) ); - } - } - cb = clbk; - if ( !isFunction( cb ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) ); - } - } - runner = new Runner(); - if ( opts.autoclose ) { - runner.once( 'done', close ); - } - if ( cb ) { - runner.once( 'done', cb ); - } - exitCode = 0; - queue = []; - - /** - * Benchmark harness. - * - * @private - * @param {string} name - benchmark name - * @param {Options} [options] - benchmark options - * @param {boolean} [options.skip=false] - boolean indicating whether to skip a benchmark - * @param {(PositiveInteger|null)} [options.iterations=null] - number of iterations - * @param {PositiveInteger} [options.repeats=3] - number of repeats - * @param {PositiveInteger} [options.timeout=300000] - number of milliseconds before a benchmark automatically fails - * @param {Function} [benchmark] - function containing benchmark code - * @throws {TypeError} first argument must be a string - * @throws {TypeError} options argument must be an object - * @throws {TypeError} must provide valid options - * @throws {TypeError} benchmark argument must a function - * @throws {Error} benchmark error - * @returns {Function} benchmark harness - */ - function harness( name, options, benchmark ) { - var opts; - var err; - var b; - if ( !isString( name ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', name ) ); - } - opts = copy( DEFAULTS ); - if ( arguments.length === 2 ) { - if ( isFunction( options ) ) { - b = options; - } else { - err = validate( opts, options ); - if ( err ) { - throw err; - } - } - } else if ( arguments.length > 2 ) { - err = validate( opts, options ); - if ( err ) { - throw err; - } - b = benchmark; - if ( !isFunction( b ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', b ) ); - } - } - // Add the benchmark to the initialization queue: - queue.push( [ name, opts, b ] ); - - // Perform initialization on the next turn of the event loop (note: this allows all benchmarks to be "registered" within the same turn of the loop; otherwise, we run the risk of registration-execution race conditions (i.e., a benchmark registers and executes before other benchmarks can register, depleting the benchmark queue and leading the harness to close)): - if ( queue.length === 1 ) { - nextTick( initialize ); - } - return harness; - } - - /** - * Initializes each benchmark. - * - * @private - * @returns {void} - */ - function initialize() { - var idx = -1; - return next(); - - /** - * Initialize the next benchmark. - * - * @private - * @returns {void} - */ - function next() { - var args; - - idx += 1; - - // If all benchmarks have been initialized, begin running the benchmarks: - if ( idx === queue.length ) { - queue.length = 0; - return runner.run(); - } - // Initialize the next benchmark: - args = queue[ idx ]; - init( args[ 0 ], args[ 1 ], args[ 2 ], onInit ); - } - - /** - * Callback invoked after performing initialization tasks. - * - * @private - * @param {string} name - benchmark name - * @param {Options} opts - benchmark options - * @param {(Function|undefined)} benchmark - function containing benchmark code - * @returns {void} - */ - function onInit( name, opts, benchmark ) { - var b; - var i; - - // Create a `Benchmark` instance for each repeat to ensure each benchmark has its own state... - for ( i = 0; i < opts.repeats; i++ ) { - b = new Benchmark( name, opts, benchmark ); - b.on( 'result', onResult ); - runner.push( b ); - } - return next(); - } - } - - /** - * Callback invoked upon a `result` event. - * - * @private - * @param {(string|Object)} result - result - */ - function onResult( result ) { - if ( - !isString( result ) && - !result.ok && - !result.todo - ) { - exitCode = 1; - } - } - - /** - * Returns a results stream. - * - * @private - * @param {Object} [options] - options - * @returns {TransformStream} transform stream - */ - function createStream( options ) { - if ( arguments.length ) { - return runner.createStream( options ); - } - return runner.createStream(); - } - - /** - * Closes a benchmark harness. - * - * @private - */ - function close() { - runner.close(); - } - - /** - * Forcefully exits a benchmark harness. - * - * @private - */ - function exit() { - runner.exit(); - } - - /** - * Returns the harness exit code. - * - * @private - * @returns {NonNegativeInteger} exit code - */ - function getExitCode() { - return exitCode; - } - - setReadOnly( harness, 'createStream', createStream ); - setReadOnly( harness, 'close', close ); - setReadOnly( harness, 'exit', exit ); - setReadOnlyAccessor( harness, 'exitCode', getExitCode ); - - return harness; -} - - -// EXPORTS // - -module.exports = createHarness; - |
- 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 | 9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -58x -58x -58x -5x -5x -5x -53x -58x -3x -3x -3x -50x -50x -50x -50x -50x -50x -50x -50x -50x -50x -50x -50x -50x -3x -3x -3x -3x -47x -49x -33x -33x -14x -14x -50x -50x -50x -50x -50x -50x -50x -50x -50x -50x -50x -14x -14x -1x -1x -1x -1x -13x -13x -14x -58x -9x -9x -9x -9x -9x - | /** -* @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 pretest = require( './pretest.js' ); -var iterations = require( './iterations.js' ); - - -// MAIN // - -/** -* Performs benchmark initialization tasks. -* -* @private -* @param {string} name - benchmark name -* @param {Options} opts - benchmark options -* @param {(Function|undefined)} benchmark - function containing benchmark code -* @param {Callback} clbk - callback to invoke after completing initialization tasks -* @returns {void} -*/ -function init( name, opts, benchmark, clbk ) { - // If no benchmark function, then the benchmark is considered a "todo", so no need to repeat multiple times... - if ( !benchmark ) { - opts.repeats = 1; - return clbk( name, opts, benchmark ); - } - // If the `skip` option to `true`, no need to initialize or repeat multiple times as will not be running the benchmark: - if ( opts.skip ) { - opts.repeats = 1; - return clbk( name, opts, benchmark ); - } - // Perform pretests: - pretest( name, opts, benchmark, onPreTest ); - - /** - * Callback invoked upon completing pretests. - * - * @private - * @param {Error} [error] - error object - * @returns {void} - */ - function onPreTest( error ) { - // If the pretests failed, don't run the benchmark multiple times... - if ( error ) { - opts.repeats = 1; - opts.iterations = 1; - return clbk( name, opts, benchmark ); - } - // If a user specified an iteration number, we can begin running benchmarks... - if ( opts.iterations ) { - return clbk( name, opts, benchmark ); - } - // Determine iteration number: - iterations( name, opts, benchmark, onIterations ); - } - - /** - * Callback invoked upon determining an iteration number. - * - * @private - * @param {(Error|null)} error - error object - * @param {PositiveInteger} iter - number of iterations - * @returns {void} - */ - function onIterations( error, iter ) { - // If provided an error, then a benchmark failed, and, similar to pretests, don't run the benchmark multiple times... - if ( error ) { - opts.repeats = 1; - opts.iterations = 1; - return clbk( name, opts, benchmark ); - } - opts.iterations = iter; - return clbk( name, opts, benchmark ); - } -} - - -// EXPORTS // - -module.exports = init; - |
- 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 | 9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -9x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -63x -63x -63x -63x -63x -15x -15x -15x -15x -15x -15x -15x -15x -352x -63x -63x -352x -15x -15x -15x -15x -15x -15x -15x -15x -63x -63x -48x -63x -48x -48x -48x -15x -63x -15x -9x -9x -9x -9x -9x - | /** -* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var copy = require( '@stdlib/utils/copy' ); -var Benchmark = require( './../benchmark-class' ); - - -// VARIABLES // - -var MIN_TIME = 0.1; // seconds -var ITERATIONS = 10; // 10^1 -var MAX_ITERATIONS = 10000000000; // 10^10 - - -// MAIN // - -/** -* Determines the number of iterations. -* -* @private -* @param {string} name - benchmark name -* @param {Options} options - benchmark options -* @param {(Function|undefined)} benchmark - function containing benchmark code -* @param {Callback} clbk - callback to invoke after determining number of iterations -* @returns {void} -*/ -function iterations( name, options, benchmark, clbk ) { - var opts; - var time; - - // Elapsed time (in seconds): - time = 0; - - // Create a local copy: - opts = copy( options ); - opts.iterations = ITERATIONS; - - // Begin running benchmarks: - return next(); - - /** - * Run a new benchmark. - * - * @private - */ - function next() { - var b = new Benchmark( name, opts, benchmark ); - b.on( 'result', onResult ); - b.once( 'end', onEnd ); - b.run(); - } - - /** - * Callback invoked upon a `result` event. - * - * @private - * @param {(string|Object)} result - result - */ - function onResult( result ) { - if ( !isString( result ) && result.operator === 'result' ) { - time = result.elapsed; - } - } - - /** - * Callback invoked upon an `end` event. - * - * @private - * @returns {void} - */ - function onEnd() { - if ( - time < MIN_TIME && - opts.iterations < MAX_ITERATIONS - ) { - opts.iterations *= 10; - return next(); - } - clbk( null, opts.iterations ); - } -} - - -// EXPORTS // - -module.exports = iterations; - |
- 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 | 10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -113x -113x -113x -8x -113x -6x -6x -113x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -56x -56x -57x -57x -57x -57x -57x -57x -57x -57x -57x -57x -4x -4x -57x -3x -3x -3x -57x -7x -7x -50x -57x -57x -10x -10x -10x -10x -10x - | /** -* @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 isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var copy = require( '@stdlib/utils/copy' ); -var Benchmark = require( './../benchmark-class' ); - - -// MAIN // - -/** -* Runs pretests to sanity check and/or catch failures. -* -* @private -* @param {string} name - benchmark name -* @param {Options} options - benchmark options -* @param {(Function|undefined)} benchmark - function containing benchmark code -* @param {Callback} clbk - callback to invoke after completing pretests -*/ -function pretest( name, options, benchmark, clbk ) { - var fail; - var opts; - var tic; - var toc; - var b; - - // Counters to determine the number of `tic` and `toc` events: - tic = 0; - toc = 0; - - // Local copy: - opts = copy( options ); - opts.iterations = 1; - - // Pretest to check for minimum requirements and/or errors... - b = new Benchmark( name, opts, benchmark ); - b.on( 'result', onResult ); - b.on( 'tic', onTic ); - b.on( 'toc', onToc ); - b.once( 'end', onEnd ); - b.run(); - - /** - * Callback invoked upon a `result` event. - * - * @private - * @param {(string|Object)} result - result - */ - function onResult( result ) { - if ( - !isString( result ) && - !result.ok && - !result.todo - ) { - fail = true; - } - } - - /** - * Callback invoked upon a `tic` event. - * - * @private - */ - function onTic() { - tic += 1; - } - - /** - * Callback invoked upon a `toc` event. - * - * @private - */ - function onToc() { - toc += 1; - } - - /** - * Callback invoked upon an `end` event. - * - * @private - * @returns {void} - */ - function onEnd() { - var err; - if ( fail ) { - // Possibility that failure is intermittent, but we will assume that the usual case is that the failure would persist across all repeats and no sense failing multiple times when once suffices. - err = new Error( 'unexpected error. Benchmark failed.' ); - } else if ( tic !== 1 || toc !== 1 ) { - // Unable to do anything definitive with timing information (e.g., a tic with no toc or vice versa, or benchmark function calls neither tic nor toc). - err = new Error( 'unexpected error. Invalid benchmark.' ); - } - if ( err ) { - return clbk( err ); - } - return clbk(); - } -} - - -// EXPORTS // - -module.exports = pretest; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -172x -172x -58x -58x -172x -31x -31x -16x -16x -31x -172x -55x -55x -55x -22x -55x -11x -11x -55x -172x -56x -56x -12x -12x -56x -172x -13x -13x -12x -12x -13x -63x -172x -8x -8x -8x -8x -8x - | /** -* @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 isObject = require( '@stdlib/assert/is-plain-object' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var isNull = require( '@stdlib/assert/is-null' ); -var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; -var format = require( '@stdlib/string/format' ); - - -// MAIN // - -/** -* Validates function options. -* -* @private -* @param {Object} opts - destination object -* @param {Options} options - function options -* @param {boolean} [options.skip] - boolean indicating whether to skip a benchmark -* @param {(PositiveInteger|null)} [options.iterations] - number of iterations -* @param {PositiveInteger} [options.repeats] - number of repeats -* @param {PositiveInteger} [options.timeout] - number of milliseconds before a benchmark automatically fails -* @returns {(Error|null)} error object or null -* -* @example -* var opts = {}; -* var options = { -* 'skip': false, -* 'iterations': 1e6, -* 'repeats': 3, -* 'timeout': 10000 -* }; -* -* var err = validate( opts, options ); -* if ( err ) { -* throw err; -* } -*/ -function validate( opts, options ) { - if ( !isObject( options ) ) { - return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'skip' ) ) { - opts.skip = options.skip; - if ( !isBoolean( opts.skip ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'skip', opts.skip ) ); - } - } - if ( hasOwnProp( options, 'iterations' ) ) { - opts.iterations = options.iterations; - if ( - !isPositiveInteger( opts.iterations ) && - !isNull( opts.iterations ) - ) { - return new TypeError( format( 'invalid option. `%s` option must be either a positive integer or null. Option: `%s`.', 'iterations', opts.iterations ) ); - } - } - if ( hasOwnProp( options, 'repeats' ) ) { - opts.repeats = options.repeats; - if ( !isPositiveInteger( opts.repeats ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'repeats', opts.repeats ) ); - } - } - if ( hasOwnProp( options, 'timeout' ) ) { - opts.timeout = options.timeout; - if ( !isPositiveInteger( opts.timeout ) ) { - return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'timeout', opts.timeout ) ); - } - } - return null; -} - - -// EXPORTS // - -module.exports = validate; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -- 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 | 10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -15x -52x -52x -52x -52x -1004x -1004x -80x -1004x -924x -924x -1004x -52x -52x -15x -15x -15x -15x -15x -15x -15x -15x -15x -82x -82x -82x -3x -3x -82x -82x -2x -2x -82x -15x -10x -10x -10x -10x -10x - | /** -* @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 TransformStream = require( '@stdlib/streams/node/transform' ); // eslint-disable-line stdlib/no-redeclare -var fromCodePoint = require( '@stdlib/string/from-code-point' ); -var log = require( './log.js' ); - - -// MAIN // - -/** -* Returns a Transform stream for logging to the console. -* -* @private -* @returns {TransformStream} transform stream -*/ -function createStream() { - var stream; - var line; - - stream = new TransformStream({ - 'transform': transform, - 'flush': flush - }); - line = ''; - - return stream; - - /** - * Callback invoked upon receiving a new chunk. - * - * @private - * @param {(Buffer|string)} chunk - chunk - * @param {string} enc - Buffer encoding - * @param {Callback} clbk - callback to invoke after transforming the streamed chunk - */ - function transform( chunk, enc, clbk ) { - var c; - var i; - - for ( i = 0; i < chunk.length; i++ ) { - c = fromCodePoint( chunk[ i ] ); - if ( c === '\n' ) { - flush(); - } else { - line += c; - } - } - clbk(); - } - - /** - * Callback to flush data to `stdout`. - * - * @private - * @param {Callback} [clbk] - callback to invoke after processing data - * @returns {void} - */ - function flush( clbk ) { - try { - log( line ); - } catch ( err ) { - stream.emit( 'error', err ); - } - line = ''; - if ( clbk ) { - return clbk(); - } - } -} - - -// EXPORTS // - -module.exports = createStream; - |
- 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 | 7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -7x -65x -65x -65x -7x -7x -7x -7x -7x - | /** -* @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'; - -// MAIN // - -/** -* Writes a string to the console. -* -* @private -* @param {string} str - string to write -*/ -function log( str ) { - console.log( str ); // eslint-disable-line no-console -} - - -// EXPORTS // - -module.exports = log; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -6x -6x -6x -6x -8x -8x -8x -8x -8x - | /** -* @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'; - -// MAIN // - -/** -* Removes any pending benchmarks. -* -* @private -*/ -function clear() { - /* eslint-disable no-invalid-this */ - this._benchmarks.length = 0; -} - - -// EXPORTS // - -module.exports = clear; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -45x -45x -45x -45x -8x -8x -37x -45x -2x -2x -45x -35x -35x -35x -35x -35x -5x -5x -35x -2x -2x -35x -2x -2x -35x -30x -30x -35x -37x -37x -37x -37x -37x -37x -37x -37x -37x -34x -34x -45x -8x -8x -8x -8x -8x - | /** -* @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'; - -// MAIN // - -/** -* Closes a benchmark runner. -* -* @private -* @returns {void} -*/ -function closeRunner() { - /* eslint-disable no-invalid-this */ - var self = this; - if ( this._closed ) { - return; - } - this._closed = true; - if ( this._benchmarks.length ) { - this.clear(); - this._stream.write( '# WARNING: harness closed before completion.\n' ); - } else { - this._stream.write( '#\n' ); - this._stream.write( '1..'+this.total+'\n' ); - this._stream.write( '# total '+this.total+'\n' ); - this._stream.write( '# pass '+this.pass+'\n' ); - if ( this.fail ) { - this._stream.write( '# fail '+this.fail+'\n' ); - } - if ( this.skip ) { - this._stream.write( '# skip '+this.skip+'\n' ); - } - if ( this.todo ) { - this._stream.write( '# todo '+this.todo+'\n' ); - } - if ( !this.fail ) { - this._stream.write( '#\n# ok\n' ); - } - } - this._stream.once( 'close', onClose ); - this._stream.destroy(); - - /** - * Callback invoked upon a `close` event. - * - * @private - */ - function onClose() { - self.emit( 'close' ); - } -} - - -// EXPORTS // - -module.exports = closeRunner; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -99x -99x -99x -99x -99x -99x -99x -99x -99x -84x -99x -15x -15x -99x -99x -6x -6x -6x -99x -57x -57x -57x -63x -63x -63x -63x -63x -63x -63x -63x -63x -189x -189x -63x -63x -63x -63x -63x -63x -63x -63x -189x -189x -140x -140x -60x -60x -80x -80x -49x -49x -189x -63x -63x -63x -63x -63x -63x -63x -63x -57x -49x -49x -49x -57x -63x -63x -63x -63x -63x -63x -63x -63x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -80x -2x -2x -2x -2x -2x -80x -12x -12x -72x -66x -66x -66x -80x -80x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -63x -63x -63x -63x -63x -63x -63x -6x -6x -99x -8x -8x -8x -8x -8x - | /** -* @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. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var TransformStream = require( '@stdlib/streams/node/transform' ); // eslint-disable-line stdlib/no-redeclare -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var nextTick = require( './../utils/next_tick.js' ); - - -// VARIABLES // - -var TAP_HEADER = 'TAP version 13'; - - -// MAIN // - -/** -* Creates a results stream. -* -* @private -* @param {Options} [options] - stream options -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @returns {TransformStream} transform stream -*/ -function createStream( options ) { - /* eslint-disable no-invalid-this */ - var stream; - var opts; - var self; - var id; - - self = this; - if ( arguments.length ) { - opts = options; - } else { - opts = {}; - } - stream = new TransformStream( opts ); - if ( opts.objectMode ) { - id = 0; - this.on( '_push', onPush ); - this.on( 'done', onDone ); - } else { - stream.write( TAP_HEADER+'\n' ); - this._stream.pipe( stream ); - } - this.on( '_run', onRun ); - return stream; - - /** - * Runs the next benchmark. - * - * @private - */ - function next() { - nextTick( onTick ); - } - - /** - * Callback invoked upon the next tick. - * - * @private - * @returns {void} - */ - function onTick() { - var b = self._benchmarks.shift(); - if ( b ) { - b.run(); - if ( !b.ended() ) { - return b.once( 'end', next ); - } - return next(); - } - self._running = false; - self.emit( 'done' ); - } - - /** - * Callback invoked upon a run event. - * - * @private - * @returns {void} - */ - function onRun() { - if ( !self._running ) { - self._running = true; - return next(); - } - } - - /** - * Callback invoked upon a push event. - * - * @private - * @param {Benchmark} b - benchmark - */ - function onPush( b ) { - var bid = id; - id += 1; - - b.once( 'prerun', onPreRun ); - b.on( 'result', onResult ); - b.on( 'end', onEnd ); - - /** - * Callback invoked upon a `prerun` event. - * - * @private - */ - function onPreRun() { - var row = { - 'type': 'benchmark', - 'name': b.name, - 'id': bid - }; - stream.write( row ); - } - - /** - * Callback invoked upon a `result` event. - * - * @private - * @param {(Object|string)} res - result - */ - function onResult( res ) { - if ( isString( res ) ) { - res = { - 'benchmark': bid, - 'type': 'comment', - 'name': res - }; - } else if ( res.operator === 'result' ) { - res.benchmark = bid; - res.type = 'result'; - } else { - res.benchmark = bid; - res.type = 'assert'; - } - stream.write( res ); - } - - /** - * Callback invoked upon an `end` event. - * - * @private - */ - function onEnd() { - stream.write({ - 'benchmark': bid, - 'type': 'end' - }); - } - } - - /** - * Callback invoked upon a `done` event. - * - * @private - */ - function onDone() { - stream.destroy(); - } -} - - -// EXPORTS // - -module.exports = createStream; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -69x -69x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -10325x -31x -10325x -32x -32x -10325x -10325x -10256x -10256x -69x -69x -69x -69x -69x -177x -52x -10325x -17x -17x -17x -17x - - -17x -5607x - - -5607x - - -69x -69x -69x -5607x - -5607x -69x -69x -69x -69x -69x -69x -438x -438x -69x -69x -69x -10325x -8x -8x -8x -8x -8x - | /* eslint-disable stdlib/jsdoc-require-throws-tags */ - -/** -* @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 replace = require( '@stdlib/string/base/replace' ); -var hasOwnProp = require( '@stdlib/assert/has-own-property' ); -var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP; - - -// VARIABLES // - -var RE_WHITESPACE = /\s+/g; - - -// MAIN // - -/** -* Encodes an assertion. -* -* @private -* @param {Object} result - result -* @param {PositiveInteger} count - result count -* @returns {string} encoded assertion -*/ -function encodeAssertion( result, count ) { - var actualStack; - var errorStack; - var expected; - var actual; - var indent; - var stack; - var lines; - var out; - var i; - - out = ''; - - if ( !result.ok ) { - out += 'not '; - } - // Add result count: - out += 'ok ' + count; - - // Add description: - if ( result.name ) { - out += ' ' + replace( result.name.toString(), RE_WHITESPACE, ' ' ); - } - // Append directives: - if ( result.skip ) { - out += ' # SKIP'; - } else if ( result.todo ) { - out += ' # TODO'; - } - out += '\n'; - if ( result.ok ) { - return out; - } - // Format diagnostics as YAML... - indent = ' '; - out += indent + '---\n'; - out += indent + 'operator: ' + result.operator + '\n'; - if ( - hasOwnProp( result, 'actual' ) || - hasOwnProp( result, 'expected' ) - ) { - // TODO: inspect object logic (https://github.com/substack/tape/blob/master/lib/results.js#L145) - expected = result.expected; - actual = result.actual; - if ( actual !== actual && expected !== expected ) { - throw new Error( 'unexpected error.' ); // TODO: remove me - } - } - if ( result.at ) { - out += indent + 'at: ' + result.at + '\n'; - } - if ( result.actual ) { - actualStack = result.actual.stack; - } - if ( result.error ) { - errorStack = result.error.stack; - } - if ( actualStack ) { - stack = actualStack; - } else { - stack = errorStack; - } - if ( stack ) { - lines = stack.toString().split( RE_EOL ); - out += indent + 'stack: |-\n'; - for ( i = 0; i < lines.length; i++ ) { - out += indent + ' ' + lines[ i ] + '\n'; - } - } - out += indent + '...\n'; - return out; -} - - -// EXPORTS // - -module.exports = encodeAssertion; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -134x -134x -134x -134x -134x -134x -134x -134x -8x -8x -8x -8x -8x - | /** -* @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'; - -// VARIABLES // - -var YAML_INDENT = ' '; -var YAML_BEGIN = YAML_INDENT + '---\n'; -var YAML_END = YAML_INDENT + '...\n'; - - -// MAIN // - -/** -* Encodes a result as a YAML block. -* -* @private -* @param {Object} result - result -* @returns {string} encoded result -*/ -function encodeResult( result ) { - var out = YAML_BEGIN; - out += YAML_INDENT + 'iterations: '+result.iterations+'\n'; - out += YAML_INDENT + 'elapsed: '+result.elapsed+'\n'; - out += YAML_INDENT + 'rate: '+result.rate+'\n'; - out += YAML_END; - return out; -} - - -// EXPORTS // - -module.exports = encodeResult; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -4x -8x -8x -8x -8x -8x - | /** -* @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'; - -// MAIN // - -/** -* Forcefully exits a benchmark runner. -* -* @private -*/ -function exit() { - /* eslint-disable no-invalid-this */ - var self; - var i; - for ( i = 0; i < this._benchmarks.length; i++ ) { - this._benchmarks[ i ].exit(); - } - self = this; - this.clear(); - this._stream.once( 'close', onClose ); - this._stream.destroy(); - - /** - * Callback invoked upon a `close` event. - * - * @private - */ - function onClose() { - self.emit( 'close' ); - } -} - - -// EXPORTS // - -module.exports = exit; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
---|---|---|---|---|---|---|---|---|---|
clear.js | -
-
- |
- 100% | -36/36 | -100% | -2/2 | -100% | -1/1 | -100% | -36/36 | -
close.js | -
-
- |
- 100% | -73/73 | -100% | -12/12 | -100% | -2/2 | -100% | -73/73 | -
create_stream.js | -
-
- |
- 100% | -189/189 | -100% | -25/25 | -100% | -9/9 | -100% | -189/189 | -
encode_assertion.js | -
-
- |
- 94.21% | -114/121 | -77.27% | -17/22 | -100% | -1/1 | -94.21% | -114/121 | -
encode_result.js | -
-
- |
- 100% | -49/49 | -100% | -2/2 | -100% | -1/1 | -100% | -49/49 | -
exit.js | -
-
- |
- 100% | -53/53 | -100% | -4/4 | -100% | -2/2 | -100% | -53/53 | -
index.js | -
-
- |
- 100% | -216/216 | -100% | -4/4 | -100% | -1/1 | -100% | -216/216 | -
push.js | -
-
- |
- 100% | -100/100 | -100% | -18/18 | -100% | -3/3 | -100% | -100/100 | -
run.js | -
-
- |
- 100% | -36/36 | -100% | -2/2 | -100% | -1/1 | -100% | -36/36 | -
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -91x -91x -1x -1x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -90x -91x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x - | /** -* @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 EventEmitter = require( 'events' ).EventEmitter; -var inherit = require( '@stdlib/utils/inherit' ); -var defineProperty = require( '@stdlib/utils/define-property' ); -var TransformStream = require( '@stdlib/streams/node/transform' ); -var push = require( './push.js' ); -var createStream = require( './create_stream.js' ); -var run = require( './run.js' ); -var clear = require( './clear.js' ); -var close = require( './close.js' ); // eslint-disable-line stdlib/no-redeclare -var exit = require( './exit.js' ); - - -// MAIN // - -/** -* Benchmark runner. -* -* @private -* @constructor -* @returns {Runner} Runner instance -* -* @example -* var runner = new Runner(); -*/ -function Runner() { - if ( !( this instanceof Runner ) ) { - return new Runner(); - } - EventEmitter.call( this ); - - // Private properties: - defineProperty( this, '_benchmarks', { - 'value': [], - 'configurable': false, - 'writable': false, - 'enumerable': false - }); - - defineProperty( this, '_stream', { - 'value': new TransformStream(), - 'configurable': false, - 'writable': false, - 'enumerable': false - }); - - defineProperty( this, '_closed', { - 'value': false, - 'configurable': false, - 'writable': true, - 'enumerable': false - }); - - defineProperty( this, '_running', { - 'value': false, - 'configurable': false, - 'writable': true, - 'enumerable': false - }); - - // Public properties: - defineProperty( this, 'total', { - 'value': 0, - 'configurable': false, - 'writable': true, - 'enumerable': true - }); - - defineProperty( this, 'fail', { - 'value': 0, - 'configurable': false, - 'writable': true, - 'enumerable': true - }); - - defineProperty( this, 'pass', { - 'value': 0, - 'configurable': false, - 'writable': true, - 'enumerable': true - }); - - defineProperty( this, 'skip', { - 'value': 0, - 'configurable': false, - 'writable': true, - 'enumerable': true - }); - - defineProperty( this, 'todo', { - 'value': 0, - 'configurable': false, - 'writable': true, - 'enumerable': true - }); - - return this; -} - -/* -* Inherit from the `EventEmitter` prototype. -*/ -inherit( Runner, EventEmitter ); - -/** -* Adds a new benchmark. -* -* @private -* @memberof Runner.prototype -* @function push -* @param {Benchmark} b - benchmark -*/ -defineProperty( Runner.prototype, 'push', { - 'value': push, - 'configurable': false, - 'writable': false, - 'enumerable': false -}); - -/** -* Creates a results stream. -* -* @private -* @memberof Runner.prototype -* @function createStream -* @param {Options} [options] - stream options -* @returns {TransformStream} transform stream -*/ -defineProperty( Runner.prototype, 'createStream', { - 'value': createStream, - 'configurable': false, - 'writable': false, - 'enumerable': false -}); - -/** -* Runs pending benchmarks. -* -* @private -* @memberof Runner.prototype -* @function run -*/ -defineProperty( Runner.prototype, 'run', { - 'value': run, - 'configurable': false, - 'writable': false, - 'enumerable': false -}); - -/** -* Removes any pending benchmarks. -* -* @private -* @memberof Runner.prototype -* @function clear -*/ -defineProperty( Runner.prototype, 'clear', { - 'value': clear, - 'configurable': false, - 'writable': false, - 'enumerable': false -}); - -/** -* Closes a benchmark runner. -* -* @private -* @memberof Runner.prototype -* @function close -*/ -defineProperty( Runner.prototype, 'close', { - 'value': close, - 'configurable': false, - 'writable': false, - 'enumerable': false -}); - -/** -* Forcefully exits a benchmark runner. -* -* @private -* @memberof Runner.prototype -* @function exit -*/ -defineProperty( Runner.prototype, 'exit', { - 'value': exit, - 'configurable': false, - 'writable': false, - 'enumerable': false -}); - - -// EXPORTS // - -module.exports = Runner; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -148x -134x -134x -148x -148x -148x -148x -148x -148x -148x -148x -148x -10468x -10468x -9x -9x -10468x -134x -134x -134x -10325x -10462x -10256x -31x -10256x -1x -1x -10256x -10256x -69x -69x -31x -31x -31x -38x -38x -38x -38x -10325x -10325x -10468x -148x -8x -8x -8x -8x -8x - | /** -* @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. -*/ - -/* eslint-disable no-underscore-dangle */ - -'use strict'; - -// MODULES // - -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var encodeAssertion = require( './encode_assertion.js' ); -var encodeResult = require( './encode_result.js' ); - - -// MAIN // - -/** -* Adds a new benchmark. -* -* @private -* @param {Benchmark} b - benchmark -*/ -function push( b ) { - /* eslint-disable no-invalid-this */ - var self = this; - - this._benchmarks.push( b ); - - b.once( 'prerun', onPreRun ); - b.on( 'result', onResult ); - - this.emit( '_push', b ); - - /** - * Callback invoked upon a `prerun` event. - * - * @private - */ - function onPreRun() { - self._stream.write( '# '+b.name+'\n' ); - } - - /** - * Callback invoked upon a `result` event. - * - * @private - * @param {(Object|string)} res - result - * @returns {void} - */ - function onResult( res ) { - // Check for a comment... - if ( isString( res ) ) { - return self._stream.write( '# '+res+'\n' ); - } - if ( res.operator === 'result' ) { - res = encodeResult( res ); - return self._stream.write( res ); - } - self.total += 1; - if ( res.ok ) { - if ( res.skip ) { - self.skip += 1; - } else if ( res.todo ) { - self.todo += 1; - } - self.pass += 1; - } - // According to the TAP spec, todos pass even if not "ok"... - else if ( res.todo ) { - self.pass += 1; - self.todo += 1; - } - // Everything else is a failure... - else { - self.fail += 1; - } - res = encodeAssertion( res, self.total ); - self._stream.write( res ); - } -} - - -// EXPORTS // - -module.exports = push; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -57x -57x -57x -57x -8x -8x -8x -8x -8x - | /** -* @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'; - -// MAIN // - -/** -* Runs pending benchmarks. -* -* @private -*/ -function run() { - /* eslint-disable no-invalid-this */ - this.emit( '_run' ); -} - - -// EXPORTS // - -module.exports = run; - |
- 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 | 10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x -10x - | /** -* @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 IS_BROWSER = require( '@stdlib/assert/is-browser' ); -var canExit = require( './can_exit.js' ); - - -// MAIN // - -var bool = ( !IS_BROWSER && canExit ); - - -// EXPORTS // - -module.exports = bool; - |
- 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 | 11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x -11x - | /** -* @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 proc = require( './process.js' ); - - -// MAIN // - -var bool = ( proc && typeof proc.exit === 'function' ); - - -// EXPORTS // - -module.exports = bool; - |
- Press n or j to go to the next uncovered block, b, p or k for the previous block. -
- -File | -- | Statements | -- | Branches | -- | Functions | -- | Lines | -- |
---|---|---|---|---|---|---|---|---|---|
can_emit_exit.js | -
-
- |
- 100% | -34/34 | -100% | -2/2 | -100% | -0/0 | -100% | -34/34 | -
can_exit.js | -
-
- |
- 100% | -33/33 | -100% | -2/2 | -100% | -0/0 | -100% | -33/33 | -
next_tick.js | -
-
- |
- 100% | -44/44 | -100% | -2/2 | -100% | -1/1 | -100% | -44/44 | -
process.js | -
-
- |
- 100% | -28/28 | -100% | -1/1 | -100% | -0/0 | -100% | -28/28 | -
- 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 | 12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -12x -520x -520x -520x -12x -12x -12x -12x -12x - | /** -* @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'; - -// MAIN // - -/** -* Runs a function on a subsequent turn of the event loop. -* -* ## Notes -* -* - `process.nextTick` is only Node.js. -* - `setImmediate` is non-standard. -* - Everything else is browser based (e.g., mutation observer, requestAnimationFrame, etc). -* - Only API which is universal is `setTimeout`. -* - Note that `0` is not actually `0ms`. Browser environments commonly have a minimum delay of `4ms`. This is acceptable. Here, the main intent of this function is to give the runtime a chance to run garbage collection, clear state, and tend to any other pending tasks before returning control to benchmark tasks. The larger aim (attainable or not) is to provide each benchmark run with as much of a fresh state as possible. -* -* @private -* @param {Function} fcn - function to run upon a subsequent turn of the event loop -*/ -function nextTick( fcn ) { - setTimeout( fcn, 0 ); -} - - -// EXPORTS // - -module.exports = nextTick; - |
- 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 | 8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x -8x - | /** -* @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 proc = require( 'process' ); - - -// EXPORTS // - -module.exports = proc; - |
- 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; - |