Skip to content

Commit 73b052e

Browse files
committed
Add package to map internal package names to standalone package names
1 parent 502c421 commit 73b052e

File tree

19 files changed

+3978
-0
lines changed

19 files changed

+3978
-0
lines changed

lib/node_modules/@stdlib/namespace/pkg2standalone/LICENSE

+356
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2021 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# pkg2standalone
22+
23+
> Return the standalone package name associated with a provided internal package name.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var pkg2standalone = require( '@stdlib/namespace/pkg2standalone' );
41+
```
42+
43+
#### pkg2standalone( pkg )
44+
45+
Returns the standalone package name associated with a provided internal package name.
46+
47+
```javascript
48+
var v = pkg2standalone( '@stdlib/math/base/special/sin' );
49+
// returns '@stdlib/math-base-special-sin'
50+
```
51+
52+
If provided an unrecognized `pkg`, the function returns `null`.
53+
54+
```javascript
55+
var v = pkg2standalone( 'unrecognized_pkg_beep_boop_bop_bip' );
56+
// returns null
57+
```
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
64+
65+
<section class="notes">
66+
67+
</section>
68+
69+
<!-- /.notes -->
70+
71+
<!-- Package usage examples. -->
72+
73+
<section class="examples">
74+
75+
## Examples
76+
77+
<!-- TODO: better example -->
78+
79+
<!-- eslint no-undef: "error" -->
80+
81+
```javascript
82+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
83+
var aliases = require( '@stdlib/namespace/aliases' );
84+
var alias2pkg = require( '@stdlib/namespace/alias2pkg' );
85+
var pkg2standalone = require( '@stdlib/namespace/pkg2standalone' );
86+
87+
var list;
88+
var len;
89+
var idx;
90+
var v1;
91+
var v2;
92+
var i;
93+
94+
list = aliases();
95+
len = list.length;
96+
97+
for ( i = 0; i < 100; i++ ) {
98+
idx = discreteUniform( 0, len-1 );
99+
v1 = alias2pkg( list[ idx ] );
100+
v2 = pkg2standalone( v1 );
101+
console.log( 'alias: %s. pkg: %s.', list[ idx ], v1 );
102+
console.log( 'pkg: %s. standalone: %s.', v1, v2 );
103+
}
104+
```
105+
106+
</section>
107+
108+
<!-- /.examples -->
109+
110+
<!-- Section for describing a command-line interface. -->
111+
112+
* * *
113+
114+
<section class="cli">
115+
116+
## CLI
117+
118+
<!-- CLI usage documentation. -->
119+
120+
<section class="usage">
121+
122+
### Usage
123+
124+
```text
125+
Usage: stdlib-pkg2standalone [options] <pkg>
126+
127+
Options:
128+
129+
-h, --help Print this message.
130+
-V, --version Print the package version.
131+
```
132+
133+
</section>
134+
135+
<!-- /.usage -->
136+
137+
<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
138+
139+
<section class="notes">
140+
141+
</section>
142+
143+
<!-- /.notes -->
144+
145+
<!-- CLI usage examples. -->
146+
147+
<section class="examples">
148+
149+
### Examples
150+
151+
```bash
152+
$ stdlib-pkg2standalone '@stdlib/math/base/special/sin'
153+
@stdlib/math-base-special-sin
154+
```
155+
156+
</section>
157+
158+
<!-- /.examples -->
159+
160+
</section>
161+
162+
<!-- /.cli -->
163+
164+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
165+
166+
<section class="references">
167+
168+
</section>
169+
170+
<!-- /.references -->
171+
172+
<!-- <license> -->
173+
174+
## License
175+
176+
The data files (databases) are licensed under an [Open Data Commons Public Domain Dedication & License 1.0][pddl-1.0] and their contents are licensed under [Creative Commons Zero v1.0 Universal][cc0]. The software is licensed under [Apache License, Version 2.0][apache-license].
177+
178+
<!-- </license> -->
179+
180+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
181+
182+
<section class="links">
183+
184+
[pddl-1.0]: http://opendatacommons.org/licenses/pddl/1.0/
185+
186+
[cc0]: https://creativecommons.org/publicdomain/zero/1.0
187+
188+
[apache-license]: https://www.apache.org/licenses/LICENSE-2.0
189+
190+
</section>
191+
192+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2021 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var pkg2standalone = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var values;
33+
var v;
34+
var i;
35+
36+
values = [
37+
'@stdlib/math/base/special/sin',
38+
'@stdlib/math/base/special/abs',
39+
'@stdlib/math/base/special/cos'
40+
];
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
v = pkg2standalone( values[ i%values.length ] );
45+
if ( typeof v !== 'string' ) {
46+
b.fail( 'should return a string' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isString( v ) ) {
51+
b.fail( 'should return a string' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @license Apache-2.0
5+
*
6+
* Copyright (c) 2021 The Stdlib Authors.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var resolve = require( 'path' ).resolve;
26+
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
27+
var CLI = require( '@stdlib/cli' );
28+
var pkg2standalone = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Main execution sequence.
35+
*
36+
* @private
37+
*/
38+
function main() {
39+
var flags;
40+
var args;
41+
var cli;
42+
var out;
43+
44+
// Create a command-line interface:
45+
cli = new CLI({
46+
'pkg': require( './../package.json' ),
47+
'options': require( './../etc/cli_opts.json' ),
48+
'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), {
49+
'encoding': 'utf8'
50+
})
51+
});
52+
53+
// Get any provided command-line options:
54+
flags = cli.flags();
55+
if ( flags.help || flags.version ) {
56+
return;
57+
}
58+
59+
// Get any provided command-line arguments:
60+
args = cli.args();
61+
62+
// Resolve a provided package name to an alias...
63+
out = pkg2standalone( args[ 0 ] );
64+
if ( out ) {
65+
console.log( out ); // eslint-disable-line no-console
66+
} else {
67+
cli.close( 1 );
68+
}
69+
}
70+
71+
main();

0 commit comments

Comments
 (0)