Skip to content

Commit 55f998a

Browse files
committed
Add support for resolving a pkg from an alias in browser REPL
1 parent dd82092 commit 55f998a

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

lib/node_modules/@stdlib/repl/scripts/browser.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var docs = require( '@stdlib/repl/help' );
1414
// VARIABLES //
1515

1616
var NO_HELP_TEXT = 'No help information available.';
17+
var NO_PKG_TEXT = 'Unrecognized alias.';
1718
var NAMESPACE = namespace();
1819
var DOCS = docs();
1920

@@ -63,6 +64,32 @@ function ns() {
6364
}
6465
} // end FUNCTION ns()
6566

67+
/**
68+
* Prints the package name corresponding to a provided alias.
69+
*
70+
* @private
71+
* @param {*} alias - variable alias or value
72+
*/
73+
function alias2pkg( alias ) {
74+
var txt;
75+
var i;
76+
77+
// Check if provided an alias or a known value reference...
78+
for ( i = 0; i < NAMESPACE.length; i++ ) {
79+
if (
80+
alias === NAMESPACE[ i ].alias ||
81+
alias === NAMESPACE[ i ].value
82+
) {
83+
txt = NAMESPACE[ i ].path;
84+
break;
85+
}
86+
}
87+
if ( txt === void 0 ) {
88+
txt = NO_PKG_TEXT;
89+
}
90+
console.log( txt ); // eslint-disable-line no-console
91+
} // end FUNCTION alias2pkg()
92+
6693

6794
// MAIN //
6895

@@ -87,7 +114,8 @@ function main() {
87114
'help': help,
88115
'_help': help, // Firefox devtools already aliases `help` (and `?`) to a read-only value :(
89116
'require': require,
90-
'namespace': ns
117+
'namespace': ns,
118+
'alias2pkg': alias2pkg
91119
};
92120
paths = [];
93121
for ( i = 0; i < NAMESPACE.length; i++ ) {

0 commit comments

Comments
 (0)