Skip to content

Commit 3410341

Browse files
committed
docs: document setCommands
Signed-off-by: Snehil Shah <[email protected]> --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- Signed-off-by: Snehil Shah <[email protected]>
1 parent 99a38e7 commit 3410341

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/node_modules/@stdlib/repl/base/ctor/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,34 @@ repl.resetContext();
132132
repl.close();
133133
```
134134

135+
#### REPL.prototype.setCommands( context, commands )
136+
137+
Sets commands on a context object.
138+
139+
```javascript
140+
// Create a new REPL:
141+
var repl = new REPL();
142+
143+
// ...
144+
145+
// Initialize empty context:
146+
var ctx = {};
147+
148+
// Define custom commands:
149+
function helloWorld() {
150+
console.log( 'Hello World!' );
151+
}
152+
var cmds = [ [ 'helloWorld', helloWorld, false ] ];
153+
154+
// Set custom commands on context:
155+
repl.setCommands( ctx, cmds );
156+
157+
// ...
158+
159+
// Close the REPL:
160+
repl.close();
161+
```
162+
135163
#### REPL.prototype.createWorkspace( name )
136164

137165
Creates a new workspace.

lib/node_modules/@stdlib/repl/base/ctor/lib/main.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,29 @@ setNonEnumerableReadOnly( REPL.prototype, 'resetContext', function resetContext(
577577
* @param {Object} context - context object
578578
* @param {ArrayArray} commands - commands
579579
* @returns {Object} context object
580+
*
581+
* @example
582+
* // Create a new REPL:
583+
* var repl = new REPL();
584+
*
585+
* // ...
586+
*
587+
* // Initialize empty context:
588+
* var ctx = {};
589+
*
590+
* // Define custom commands:
591+
* function helloWorld() {
592+
* console.log( 'Hello World!' );
593+
* }
594+
* var cmds = [ [ 'helloWorld', helloWorld, false ] ];
595+
*
596+
* // Set custom commands on context:
597+
* repl.setCommands( ctx, cmds );
598+
*
599+
* // ...
600+
*
601+
* // Close the REPL:
602+
* repl.close();
580603
*/
581604
setNonEnumerableReadOnly( REPL.prototype, 'setCommands', function set( context, commands ) {
582605
if ( this._sandbox ) {

0 commit comments

Comments
 (0)