List stdlib namespaces.
var ls = require( '@stdlib/_tools/pkgs/namespaces' );Asynchronously returns a list of stdlib namespaces.
ls( onList );
function onList( error, names ) {
if ( error ) {
throw error;
}
console.log( names.join( '\n' ) );
}The function accepts the following options:
- dir: directory from which to search for namespaces. May be either an absolute path or a path relative to the
stdlib/lib/node_modules/directory (e.g.,./@stdlib/math). Default:/path/to/stdlib/lib/node_modules/. - pattern: glob pattern used to find namespaces. Default:
'**/package.json'(note: pattern must end withpackage.json). - ignore: list of glob patterns used to exclude matches.
To search from a descendant directory, set the dir option.
var opts = {
'dir': './@stdlib/math/base'
};
ls( opts, onList );
function onList( error, names ) {
if ( error ) {
throw error;
}
console.log( names.join( '\n' ) );
}To provide an alternative include filter, set the pattern option.
var opts = {
'pattern': '**/foo/**/package.json'
};
ls( opts, onList );
function onList( error, names ) {
if ( error ) {
throw error;
}
console.log( names.join( '\n' ) );
}To exclude matches, set the ignore option.
var opts = {
'ignore': [
'node_modules/**',
'build/**',
'reports/**',
'foo/**'
]
};
ls( opts, onList );
function onList( error, names ) {
if ( error ) {
throw error;
}
console.log( names.join( '\n' ) );
}Synchronously returns a list of stdlib namespaces.
var names = ls.sync();
// returns [...]The function accepts the same options as ls() above.
- Both functions only return namespaces under the
@stdlibscope. - Both functions always ignore
examples/fixtures,test/fixtures, andbenchmark/fixturesdirectories, irrespective of whether anignoreoption is provided. - Be careful when using the
patternoption. Both functions first resolve a list of packages matching the search criteria and then prune the list to resolve "namespaces" relative to the resolved list. For example, if thepatternoption results in resolving only a single package, both functions will always fail to resolve a namespace, regardless as to whether the package actually is a namespace. Only when both functions resolve leaf packages will the functions resolve namespaces.
var ls = require( '@stdlib/_tools/pkgs/namespaces' );
ls( onList );
function onList( error, names ) {
if ( error ) {
throw error;
}
console.log( names.join( '\n' ) );
}Usage: stdlib-namespaces [options] [<dir>]
Options:
-h, --help Print this message.
-V, --version Print the package version.
--pattern pattern Inclusion glob pattern.
--ignore pattern Exclusion glob pattern.
-
If not provided a
dirargument, the search directory is the current working directory. -
To provide multiple exclusion glob patterns, set multiple
--ignoreoption arguments.$ stdlib-namespaces --ignore=node_modules/** --ignore=build/** --ignore=reports/**
$ stdlib-namespaces
<package_name>
<package_name>
...