uri2id

Return the id corresponding to a provided URI.

Usage

var uri2id = require( '@stdlib/_tools/links/uri2id' );

uri2id( uri, [options,] clbk )

Returns the id corresponding to a provided URI.

uri2id( 'http://www.bibtex.org/', clbk );

function clbk( error, id ) {
    if ( error ) {
        throw error;
    }
    console.log( id );
    // => 'bibtex'
}

The function accepts the following options:

  • database: path to a link database.

To use an alternative link database, set the database option.

var opts = {
    'database': './path/to/link/database/json'
};

uri2id( 'http://www.bibtex.org/', opts, clbk );

function clbk( error, id ) {
    if ( error ) {
        throw error;
    }
    console.log( id );
}

uri2id.sync( uri[, options] )

Synchronously returns the id which corresponds to a provided URI.

var id = uri2id.sync( 'http://www.bibtex.org/' );
if ( id instanceof Error ) {
    throw id;
}
console.log( id );
// => 'bibtex'

The method accepts the same options as uri2id() above.

Notes

  • If a function is unable to resolve an id, the function returns null.
  • A link database is resolved relative to the current working directory of the calling process and should be a JSON file.

Examples

var uri2id = require( '@stdlib/_tools/links/uri2id' );

uri2id( 'https://github.com/stdlib-js/stdlib', clbk );

function clbk( error, id ) {
    if ( error ) {
        throw error;
    }
    console.log( id );
}

CLI

Usage

Usage: uri2id [options] [<uri>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --database filepath   Database filepath.

Notes

  • If invoked without a URI, the CLI will interactively prompt for argument input.

Examples

$ uri2id http://www.bibtex.org/