Library of Node.js abstractions for side effects at the edges of software.
Reduce accidental complexity and focus on application business logic.
npm install @paulshryock/abstractions
CommandLine
makes use of Node.js stdout and stderr streams.
import { CommandLine } from '@paulshryock/abstractions'
class MyClass {
public construct(private commandLine: CommandLine) {}
/** Prints 'Hello, world!' to stdout. */
public printHelloWorldToStdout(): void {
this.commandLine.out('Hello, world!')
}
/**
* Prints 'What is your name?' to stdout and waits for an answer. Then
* prints 'Hello, Paul!' to stdout (if the name given is 'Paul').
*/
public async printHelloNameToStdout(): Promise<void> {
const name = await this.commandLine.ask('What is your name?')
this.commandLine.out(`Hello, ${name}!`)
}
/** Prints 'Hello, error!' to stderr. */
public printHelloErrorToStderr(): void {
this.commandLine.error('Hello, error!', { trace: true })
}
}
const myClass = new MyClass(new CommandLine())
myClass.printHelloWorldToStdout()
myClass.printHelloNameToStdout()
myClass.printHelloErrorToStderr()
import { FileSystem } from '@paulshryock/abstractions'
Contributions are welcome! Read the contribution guidelines, and then submit a pull request.