Socket
Book a DemoInstallSign in
Socket

final

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

final

A set of tools for writing JavaScript code once that runs on the command line, browser, and more.

0.2.0
latest
Source
npmnpm
Version published
Weekly downloads
145
104.23%
Maintainers
1
Weekly downloads
 
Created
Source

Final

npm version Build Status Dependency Status Code Climate Test Coverage js-standard-style

A set of tools for writing JavaScript code once that runs on the command line, browser, and more.

Project Status

Final is in early (pre-1.0) development. It is usable, but its API may change frequently until it reaches 1.0. Additionally, several core features (and runners) have not been implemented yet.

Examples

The examples below can be run in a Node.js script or shell.

Getting Started

First, create an instance of Command with a function implementing the Command's core. Skip to the Usage section for more information about how to write Commands.

var adder = new final.Command(options => {
  var first = parseInt(options.first, 10)
  var second = parseInt(options.second, 10)

  return first + second
})

This Command exposes a run() method which wraps the given core with some extra type conversion and validation. This is the recommended way of running Commands. Note that your core function should treat all options as Strings, since all inputs and outputs are converted to and from Strings by the run() method.

var result = adder.run({ first: 1, second: 2 }) // this returns a String
console.log(result)

API Runner

Final can generate callbacks for Node's http.Server class, allowing you to wrap Commands in web APIs. You can also embed Commands in larger Node web apps.

new final.API(adder).run()

Here, Final starts a web API at localhost:3000 that wraps your Command. You can call it with HTTP requests like GET localhost:3000?first=1&second=2, and you will get a plain text response with the result.

CLI Runner

Final can create command line interfaces around your Command.

new final.CLI(adder).run()

Final will read arguments from the shell command running this JavaScript code, and then it will immediately run the Command with the given options and print the result to STDOUT. For example, try putting this in add.js and running node add --first 1 --second 2 in the same directory.

Installation

  • Install Node.js (version 4 or higher)
  • npm install --save final
  • var final = require ('final')

License

ISC (it's similar to MIT, but simpler)

Keywords

api

FAQs

Package last updated on 07 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.