
Product
Introducing Pull Request Stories to Help Security Teams Track Supply Chain Risks
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
@paulshryock/abstractions
Advanced tools
:warning: This project is in early development and not for production use. |
---|
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
Reads and writes messages to and from the command line.
options
: Record<string, boolean | number | string>
All short and long options from the current process. Boolean strings ('true'
|'false'
) are converted to boolean.
positionalArguments
: string[]
Positional arguments from the current process.
ask(question)
question
: <string>
Question to print to output stream.<Promise<string>>
Answer read from input stream.Prints question to output stream and reads answer from input stream.
out(message[, options])
message
: <string>
Message for output stream.options
: <Object>
trace
: <boolean>
Whether or not to include a stack trace.<void>
Writes message to output stream. Optionally includes a stack trace.
error(error[, options])
error
: string
Error message for error stream.options
: <Object>
trace
: <boolean>
Whether or not to include a stack trace.<void>
Writes error message to error stream. Optionally includes a stack trace.
import { CommandLine } from '@paulshryock/abstractions'
class MyClass {
public construct(private commandLine: CommandLine) {}
/** Gets all short and long options from the current process. */
public getOptions(): Record<string, boolean | number | string> {
return this.commandLine.options
}
/** Gets positional arguments from the current process. */
public getPositionalArguments(): string[] {
return this.commandLine.positionalArguments
}
/** 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!' with a stack trace to stderr. */
public printHelloErrorToStderr(): void {
this.commandLine.error('Hello, error!', { trace: true })
}
}
const myClass = new MyClass(new CommandLine())
const options = myClass.getOptions()
const positionalArguments = myClass.getPositionalArguments()
myClass.printHelloWorldToStdout()
myClass.printHelloNameToStdout()
myClass.printHelloErrorToStderr()
LocalFileSystem
readFile(path)
path
: <string>
Path to file.<Promise<string>>
File contents.Reads a file.
writeFile(path, content)
path
: <string>
Path to file.content
: <string>
Content to write to file.<Promise<void>>
Writes to a file.
appendFile(path, content)
path
: <string>
Path to file.content
: <string>
Content to write to file.<Promise<void>>
Appends to a file.
deleteFile(path)
path
: <string>
Path to file.<Promise<void>>
Deletes a file.
isFile(path)
path
: <string>
Path to file.<Promise<boolean>>
Whether or not the path is a file.Checks if a path is a file.
createDirectory(path)
path
: <string>
Path to directory.<Promise<void>>
Creates a directory.
readDirectory(path)
path
: <string>
Path to directory.<Promise<string[]>>
Contents of the directory.Reads a directory and returns the contents.
readDirectoryRecursive(path)
path
: <string>
Path to directory.<Promise<string[]>>
Recursive contents of the directory.Reads a directory and returns the contents.
Reads a directory and returns the contents recursively.
deleteDirectory(path)
path
: <string>
Path to directory.<Promise<void>>
Deletes a directory.
isDirectory(path)
path
: <string>
Path to directory.<Promise<boolean>>
Whether or not the path is a directory.Checks if a path is a directory.
copy(src, dest)
src
: <string>
Source path.dest
: <string>
Destination path.<Promise<void>>
Copies a file or directory to another location.
When src
and dest
are path names to files, the program copies the contents of the first file to the second file, creating the second file if necessary.
When src
is a path name of a file and dest
is a path to a directory, then the program copies the source file into the destination directory, creating the file if necessary.
When src
and dest
are both the path names to two directories, the program copies the source directory into the destination directory, creating any files or directories needed. If the destination directory already exists, the source is copied into the destination, while a new directory is created if the destination does not exist.
move(src, dest)
src
: <string>
Source path.dest
: <string>
Destination path.<Promise<void>>
Moves a file or directory to another location.
exists(path)
path
: <string>
Path to directory.<Promise<boolean>>
Whether or not the path is an existing file or directory.Checks if a file or directory exists.
import { LocalFileSystem, VirtualFileSystem } from '@paulshryock/abstractions'
class MyClass {
public constructor(private fileSystem = VirtualFileSystem) {}
}
const myClass = new MyClass(new LocalFileSystem())
Contributions are welcome! Read the contribution guidelines, and then submit a pull request.
v0.3.1 - 2024-12-29
FAQs
Reusable abstractions for Node.js.
The npm package @paulshryock/abstractions receives a total of 29 weekly downloads. As such, @paulshryock/abstractions popularity was classified as not popular.
We found that @paulshryock/abstractions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Socket’s new Pull Request Stories give security teams clear visibility into dependency risks and outcomes across scanned pull requests.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.