Skip to content

Commit 6b0f692

Browse files
committed
Add utility to return the internal package name associated with a standalone package name
1 parent 6ea7052 commit 6b0f692

19 files changed

Lines changed: 3978 additions & 0 deletions

File tree

lib/node_modules/@stdlib/namespace/standalone2pkg/LICENSE

Lines changed: 356 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
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+
# standalone2pkg
22+
23+
> Return the internal package name associated with a provided standalone 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 standalone2pkg = require( '@stdlib/namespace/standalone2pkg' );
41+
```
42+
43+
#### standalone2pkg( pkg )
44+
45+
Returns the internal package name associated with a provided standalone package name.
46+
47+
```javascript
48+
var v = standalone2pkg( '@stdlib/math-base-special-sin' );
49+
// returns '@stdlib/math/base/special/sin'
50+
```
51+
52+
If provided an unrecognized standalone package name, the function returns `null`.
53+
54+
```javascript
55+
var v = standalone2pkg( '@stdlib/unrecognized_alias_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 alias2standalone = require( '@stdlib/namespace/alias2standalone' );
85+
var standalone2pkg = require( '@stdlib/namespace/standalone2pkg' );
86+
87+
var list;
88+
var len;
89+
var pkg;
90+
var v;
91+
var i;
92+
93+
list = aliases();
94+
len = list.length;
95+
96+
for ( i = 0; i < 100; i++ ) {
97+
v = list[ discreteUniform( 0, len-1 ) ];
98+
pkg = alias2standalone( v );
99+
console.log( 'alias: %s. standalone: %s.', v, pkg );
100+
console.log( 'standalone: %s. pkg: %s.', pkg, standalone2pkg( pkg ) );
101+
}
102+
```
103+
104+
</section>
105+
106+
<!-- /.examples -->
107+
108+
<!-- Section for describing a command-line interface. -->
109+
110+
* * *
111+
112+
<section class="cli">
113+
114+
## CLI
115+
116+
<!-- CLI usage documentation. -->
117+
118+
<section class="usage">
119+
120+
### Usage
121+
122+
```text
123+
Usage: stdlib-standalone2pkg [options] <alias>
124+
125+
Options:
126+
127+
-h, --help Print this message.
128+
-V, --version Print the package version.
129+
```
130+
131+
</section>
132+
133+
<!-- /.usage -->
134+
135+
<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
136+
137+
<section class="notes">
138+
139+
</section>
140+
141+
<!-- /.notes -->
142+
143+
<!-- CLI usage examples. -->
144+
145+
<section class="examples">
146+
147+
### Examples
148+
149+
```bash
150+
$ stdlib-standalone2pkg '@stdlib/math-base-special-sin'
151+
@stdlib/math/base/special/sin
152+
```
153+
154+
</section>
155+
156+
<!-- /.examples -->
157+
158+
</section>
159+
160+
<!-- /.cli -->
161+
162+
<!-- 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. -->
163+
164+
<section class="references">
165+
166+
</section>
167+
168+
<!-- /.references -->
169+
170+
<!-- <license> -->
171+
172+
## License
173+
174+
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].
175+
176+
<!-- </license> -->
177+
178+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
179+
180+
<section class="links">
181+
182+
[pddl-1.0]: http://opendatacommons.org/licenses/pddl/1.0/
183+
184+
[cc0]: https://creativecommons.org/publicdomain/zero/1.0
185+
186+
[apache-license]: https://www.apache.org/licenses/LICENSE-2.0
187+
188+
</section>
189+
190+
<!-- /.links -->
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 standalone2pkg = 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-cos',
39+
'@stdlib/utils-copy',
40+
'@stdlib/assert-is-string',
41+
'@stdlib/assert-is-function'
42+
];
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
v = standalone2pkg( values[ i%values.length ] );
47+
if ( typeof v !== 'string' ) {
48+
b.fail( 'should return a string' );
49+
}
50+
}
51+
b.toc();
52+
if ( !isString( v ) ) {
53+
b.fail( 'should return a string' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});
Lines changed: 71 additions & 0 deletions
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 standalone2pkg = 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 standalone package name to an internal package name...
63+
out = standalone2pkg( 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)