Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

main-function

vilic14MIT0.1.7TypeScript support: included

A simple wrapper that handles error and return code.

readme

NPM Package Build Status

Main Function

A simple wrapper that handles error and return code.

Install

yarn add main-function

Usage

import main, {ProgramError} from 'main-function';

main(async (args: string[]) => {
  // Throw an `ProgramError` to exit:
  throw new ProgramError(0, 'Some friendly error message');

  // Or throw a normal error (will print error stack and exit with code `1`):
  throw new Error():

  // Optional return statement for exit code:
  return 0;
});

License

MIT License.