Insert Link

Create a link entry in a link database.

Usage

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

create( opts, clbk )

Creates a link entry in a link database.

var opts = {
    'uri': 'https://stdlib.io',
    'id': 'stdlib',
    'description': 'A standard library for JavaScript and Node.js.'
};

create( opts, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
    console.log( 'Success!' );
}

The function accepts the following options:

  • uri: link URI.
  • id: unique identifier.
  • description: link description.
  • keywords: array of keywords.
  • database: path to a link database.

To specify keywords which pertain to the link, set the keywords option.

var opts = {
    'uri': 'https://stdlib.io',
    'id': 'stdlib',
    'description': 'A standard library for JavaScript and Node.js.',
    'keywords': [
        'standard',
        'library',
        'stdlib',
        'javascript',
        'node.js',
        'nodejs'
    ]
};

create( opts, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
    console.log( 'Success!' );
}

To insert the link into a particular link database, set the database option.

var opts = {
    'uri': 'https://stdlib.io',
    'id': 'stdlib',
    'description': 'A standard library for JavaScript and Node.js.',
    'database': './beep/boop/links.json'
};

create( opts, done );

function done( error ) {
    if ( error ) {
        throw error;
    }
    console.log( 'Success!' );
}

create.sync( opts )

Synchronously inserts a link into a link database.

var opts = {
    'uri': 'https://stdlib.io',
    'id': 'stdlib',
    'description': 'A standard library for JavaScript and Node.js.'
};

var err = create.sync( opts );
if ( err ) {
    throw err;
}
console.log( 'Success!' );

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

Notes

  • A link database should be a JSON file.

Examples

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

var opts = {
    'uri': 'https://stdlib.io',
    'id': 'stdlib',
    'description': 'A standard library for JavaScript and Node.js.',
    'keywords': [
        'standard',
        'library',
        'lib',
        'stdlib',
        'javascript',
        'js',
        'node.js',
        'nodejs',
        'node-js',
        'node'
    ]
};

function done( error ) {
    if ( error ) {
        throw error;
    }
    console.log( 'Success!' );
}

create( opts, done );

CLI

Usage

Usage: insert-link [options] [<uri> --id <id> --desc <description>]

Options:

  -h,    --help                Print this message.
  -V,    --version             Print the package version.
         --id id               Unique identifier.
         --desc description    Link description.
         --keywords w1,w2,...  Comma-separated list of keywords.
         --database filepath   Database filepath.

Notes

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

Examples

$ insert-link https://stdlib.io/ --id stdlib --description 'A standard library for JavaScript and Node.js'