Skip to content

Commit c2c4e62

Browse files
committed
Refactor support for standalone package names and update namespace data
1 parent aee6b5b commit c2c4e62

File tree

11 files changed

+14
-57
lines changed

11 files changed

+14
-57
lines changed

lib/node_modules/@stdlib/namespace/pkg2alias/lib/main.js

+4-52
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,10 @@
2222

2323
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2424
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25-
var objectKeys = require( '@stdlib/utils/keys' );
26-
var replace = require( '@stdlib/string/replace' );
25+
var standalone2pkg = require( '@stdlib/namespace/standalone2pkg' );
2726
var PKG_TO_ALIAS = require( './../data/data.json' );
2827

2928

30-
// VARIABLES //
31-
32-
var DB;
33-
34-
35-
// FUNCTIONS //
36-
37-
/**
38-
* Converts an internal package name to a standalone package name.
39-
*
40-
* @private
41-
* @param {string} name - internal package name
42-
* @returns {string} standalone package name
43-
*/
44-
function pkg2standalone( name ) {
45-
// Note: every internal package name begins with `@stdlib/`, which is 8 characters long...
46-
return '@stdlib/' + replace( name.substring( 8 ), '/', '-' );
47-
}
48-
49-
/**
50-
* Returns an in-memory hash mapping standalone package names to internal package names.
51-
*
52-
* @private
53-
* @returns {Object} hash mapping standalone package names to internal package names
54-
*/
55-
function database() {
56-
var keys;
57-
var k;
58-
var i;
59-
60-
if ( DB ) {
61-
return DB;
62-
}
63-
DB = {};
64-
keys = objectKeys( PKG_TO_ALIAS );
65-
for ( i = 0; i < keys.length; i++ ) {
66-
k = keys[ i ];
67-
DB[ pkg2standalone( k ) ] = k;
68-
}
69-
return DB;
70-
}
71-
72-
7329
// MAIN //
7430

7531
/**
@@ -84,19 +40,15 @@ function database() {
8440
* // returns 'base.sin'
8541
*/
8642
function pkg2alias( pkg ) {
87-
var db;
8843
if ( !isString( pkg ) ) {
8944
throw new TypeError( 'invalid argument. Must provide a string. Value: `' + pkg + '`.' );
9045
}
9146
if ( hasOwnProp( PKG_TO_ALIAS, pkg ) ) {
9247
return PKG_TO_ALIAS[ pkg ];
9348
}
94-
db = database();
95-
if ( hasOwnProp( db, pkg ) ) {
96-
pkg = db[ pkg ];
97-
if ( hasOwnProp( PKG_TO_ALIAS, pkg ) ) {
98-
return PKG_TO_ALIAS[ pkg ];
99-
}
49+
pkg = standalone2pkg( pkg );
50+
if ( hasOwnProp( PKG_TO_ALIAS, pkg ) ) {
51+
return PKG_TO_ALIAS[ pkg ];
10052
}
10153
return null;
10254
}

lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.csv

+1
Original file line numberDiff line numberDiff line change
@@ -2388,6 +2388,7 @@
23882388
"@stdlib/datasets-ssa-us-births-2000-2014","@stdlib/datasets/ssa-us-births-2000-2014"
23892389
"@stdlib/blas-sswap","@stdlib/blas/sswap"
23902390
"@stdlib/utils-stack","@stdlib/utils/stack"
2391+
"@stdlib/namespace-standalone2pkg","@stdlib/namespace/standalone2pkg"
23912392
"@stdlib/datasets-standard-card-deck","@stdlib/datasets/standard-card-deck"
23922393
"@stdlib/string-startcase","@stdlib/string/startcase"
23932394
"@stdlib/string-starts-with","@stdlib/string/starts-with"

lib/node_modules/@stdlib/namespace/standalone2pkg/data/data.json

+1-1
Large diffs are not rendered by default.

lib/node_modules/@stdlib/repl/code-blocks/data/data.csv

+1
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,7 @@ SQRT_TWO_PI,"SQRT_TWO_PI\n"
38073807
SSA_US_BIRTHS_2000_2014,"var data = SSA_US_BIRTHS_2000_2014()\n"
38083808
sswap,"var x = array( new Float32Array( [ 4.0, 2.0, -3.0, 5.0, -1.0 ] ) );\nvar y = array( new Float32Array( [ 2.0, 6.0, -1.0, -4.0, 8.0 ] ) );\nsswap( x, y );\nx.data\ny.data\n"
38093809
Stack,"var s = Stack();\ns.push( 'foo' ).push( 'bar' );\ns.length\ns.pop()\ns.length\ns.pop()\ns.length\n"
3810+
standalone2pkg,"var v = standalone2pkg( '@stdlib/math-base-special-sin' )\n"
38103811
STANDARD_CARD_DECK,"var list = STANDARD_CARD_DECK()\n"
38113812
startcase,"var out = startcase( 'beep boop' )\n"
38123813
startsWith,"var bool = startsWith( 'Beep', 'Be' )\nbool = startsWith( 'Beep', 'ep' )\nbool = startsWith( 'Beep', 'ee', 1 )\nbool = startsWith( 'Beep', 'ee', -3 )\nbool = startsWith( 'Beep', '' )\n"

lib/node_modules/@stdlib/repl/code-blocks/data/data.json

+1-1
Large diffs are not rendered by default.

lib/node_modules/@stdlib/repl/info/data/data.csv

+1
Original file line numberDiff line numberDiff line change
@@ -3807,6 +3807,7 @@ SQRT_TWO_PI,"\nSQRT_TWO_PI\n Square root of the mathematical constant `π` ti
38073807
SSA_US_BIRTHS_2000_2014,"\nSSA_US_BIRTHS_2000_2014()\n Returns US birth data from 2000 to 2014, as provided by the Social Security\n Administration.\n"
38083808
sswap,"\nsswap( x:ndarray, y:ndarray )\n Interchanges two single-precision floating-point vectors.\n"
38093809
Stack,"\nStack()\n Stack constructor.\n"
3810+
standalone2pkg,"\nstandalone2pkg( pkg:string )\n Returns the internal package name associated with a provided standalone\n package name.\n"
38103811
STANDARD_CARD_DECK,"\nSTANDARD_CARD_DECK()\n Returns a string array containing two or three letter abbreviations for each\n card in a standard 52-card deck.\n"
38113812
startcase,"\nstartcase( str:string )\n Capitalizes the first letter of each word in an input `string`.\n"
38123813
startsWith,"\nstartsWith( str:string, search:string[, position:integer] )\n Tests if a `string` starts with the characters of another `string`.\n"

lib/node_modules/@stdlib/repl/info/data/data.json

+1-1
Large diffs are not rendered by default.

lib/node_modules/@stdlib/repl/signature/data/data.csv

+1
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,7 @@ SQRT_TWO_PI,"SQRT_TWO_PI"
38353835
SSA_US_BIRTHS_2000_2014,"SSA_US_BIRTHS_2000_2014()"
38363836
sswap,"sswap( x, y )"
38373837
Stack,"Stack()"
3838+
standalone2pkg,"standalone2pkg( pkg )"
38383839
STANDARD_CARD_DECK,"STANDARD_CARD_DECK()"
38393840
startcase,"startcase( str )"
38403841
startsWith,"startsWith( str, search[, position] )"

lib/node_modules/@stdlib/repl/signature/data/data.json

+1-1
Large diffs are not rendered by default.

lib/node_modules/@stdlib/repl/typed-signature/data/data.csv

+1
Original file line numberDiff line numberDiff line change
@@ -3835,6 +3835,7 @@ SQRT_TWO_PI,"SQRT_TWO_PI"
38353835
SSA_US_BIRTHS_2000_2014,"SSA_US_BIRTHS_2000_2014()"
38363836
sswap,"sswap( x:ndarray, y:ndarray )"
38373837
Stack,"Stack()"
3838+
standalone2pkg,"standalone2pkg( pkg:string )"
38383839
STANDARD_CARD_DECK,"STANDARD_CARD_DECK()"
38393840
startcase,"startcase( str:string )"
38403841
startsWith,"startsWith( str:string, search:string[, position:integer] )"

lib/node_modules/@stdlib/repl/typed-signature/data/data.json

+1-1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)