Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
paulshryock committed Sep 22, 2024
1 parent 0dd8c95 commit f595772
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 45 deletions.
18 changes: 12 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Fixed** for any bug fixes.
- **Security** in case of vulnerabilities.

## [Unreleased](https://github.com/paulshryock/node-abstractions.git/compare/HEAD..v0.1.3)
## [Unreleased](https://github.com/paulshryock/node-abstractions.git/compare/HEAD..v0.2.0)

### Added

- Export stable `CommandLine` and `FileSystem` interfaces.
- Export stable `LocalCommandLine`, `LocalFileSystem`, and `Exception` classes.

### Changed

### Deprecated

### Removed

- Remove all other exports.

### Fixed

### Security

## [v0.2.0](https://github.com/paulshryock/node-abstractions.git/releases/tag/v0.2.0) - 2024-09-22

### Added

- Export stable `CommandLine` and `FileSystem` interfaces.
- Export stable `LocalCommandLine`, `LocalFileSystem`, `StackTrace`, and `Exception` classes.

### Removed

- Remove all other exports.

## [v0.1.3](https://github.com/paulshryock/node-abstractions.git/releases/tag/v0.1.3) - 2023-10-01

### Added
Expand Down
2 changes: 1 addition & 1 deletion config/typedoc/typedoc-plugin-default-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class DefaultValuesPlugin {
*
* @param {Reflection} reflection Reflection instance.
* @return {unknown} Reflection node.
* @since unreleased
* @since 0.2.0
*/
#getReflectionNode(reflection) {
return reflection.project.getSymbolFromReflection(reflection)
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@paulshryock/abstractions",
"version": "0.1.3",
"version": "0.2.0",
"description": "Reusable abstractions for Node.js.",
"keywords": [
"abstraction",
Expand Down
14 changes: 7 additions & 7 deletions src/CommandLine/CommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { Options } from './Options.ts'
/**
* Means of writing to and reading from the command line.
*
* @since unreleased
* @since 0.2.0
*/
export interface CommandLine {
/**
* All options from the current process, including short and long flags.
*
* Boolean strings are converted to boolean.
*
* @since unreleased
* @since 0.2.0
*/
options: Options

/**
* Positional arguments from the current process.
*
* @since unreleased
* @since 0.2.0
*/
positionalArguments: string[]

Expand All @@ -27,7 +27,7 @@ export interface CommandLine {
*
* @param {string} question Question to print to output stream.
* @return {Promise<string>} Answer read from input stream.
* @since unreleased
* @since 0.2.0
*/
ask(question: string): Promise<string>

Expand All @@ -37,7 +37,7 @@ export interface CommandLine {
* @param {string} message Message for output stream.
* @param {CommandLineOutputOptions} options Output options.
* @return {void}
* @since unreleased
* @since 0.2.0
*/
out(message: string, options?: CommandLineOutputOptions): void

Expand All @@ -47,15 +47,15 @@ export interface CommandLine {
* @param {Error} error Error for error stream.
* @param {CommandLineOutputOptions} options Output options.
* @return {void}
* @since unreleased
* @since 0.2.0
*/
error(error: Error, options?: CommandLineOutputOptions): void
}

/**
* Output options for IO methods.
*
* @since unreleased
* @since 0.2.0
*/
export type CommandLineOutputOptions = {
trace: boolean
Expand Down
18 changes: 9 additions & 9 deletions src/CommandLine/LocalCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ import { StackTrace } from '../StackTrace/StackTrace.ts'
* Means of writing to and reading from the command line.
*
* @throws {FinalClassWasExtended}
* @since unreleased
* @since 0.2.0
*/
export class LocalCommandLine implements CommandLine {
/**
* Console interface for writing to the console.
*
* @since unreleased
* @since 0.2.0
*/
readonly #console: Console

/**
* Input, output, and error streams.
*
* @since unreleased
* @since 0.2.0
*/
readonly #streams: Streams

Expand All @@ -34,14 +34,14 @@ export class LocalCommandLine implements CommandLine {
*
* Boolean strings are converted to boolean.
*
* @since unreleased
* @since 0.2.0
*/
public readonly options: Options

/**
* Positional arguments from the current process.
*
* @since unreleased
* @since 0.2.0
*/
public readonly positionalArguments: string[]

Expand All @@ -50,7 +50,7 @@ export class LocalCommandLine implements CommandLine {
*
* @param {Streams} streams Command line interface streams.
* @throws {FinalClassWasExtended}
* @since unreleased
* @since 0.2.0
*/
public constructor(streams: Streams = STREAMS) {
if (new.target !== LocalCommandLine)
Expand All @@ -70,7 +70,7 @@ export class LocalCommandLine implements CommandLine {
*
* @param {string} question Question to print to output stream.
* @return {Promise<string>} Answer read from input stream.
* @since unreleased
* @since 0.2.0
*/
public async ask(question: string): Promise<string> {
const { stdin: input, stdout: output } = this.#streams
Expand All @@ -88,7 +88,7 @@ export class LocalCommandLine implements CommandLine {
* @param {string} message Message for output stream.
* @param {CommandLineOutputOptions} options Output options.
* @return {void}
* @since unreleased
* @since 0.2.0
*/
public out(message: string, options?: CommandLineOutputOptions): void {
const output = options?.trace ? new StackTrace(message).toString() : message
Expand All @@ -102,7 +102,7 @@ export class LocalCommandLine implements CommandLine {
* @param {Error} error Error for error stream.
* @param {CommandLineOutputOptions} options Output options.
* @return {void}
* @since unreleased
* @since 0.2.0
*/
public error(error: Error, options?: CommandLineOutputOptions): void {
const method = options?.trace ? 'trace' : 'error'
Expand Down
19 changes: 8 additions & 11 deletions src/CommandLine/Options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/**
* Command line options.
*
* @since unreleased
* @todo Refactor and make this immutable.
* @todo Remove private options.
* @since 0.2.0
*/
export class Options {
[index: string]: unknown
Expand All @@ -15,7 +13,7 @@ export class Options {
* Constructs process configuration object from args.
*
* @param {string[]} args Process args to build configuration from.
* @since unreleased
* @since 0.2.0
*/
public constructor(args: string[]) {
this.#args = args
Expand All @@ -30,7 +28,7 @@ export class Options {
*
* @internal
* @return {void}
* @since unreleased
* @since 0.2.0
*/
private setPrivateOptions(): void {
this.#options = this.#args.reduce(
Expand All @@ -54,7 +52,7 @@ export class Options {
*
* @param {string} value String value which might have enclosing quotes.
* @return {string} Value without enclosing quotes.
* @since unreleased
* @since 0.2.0
*/
private removeEnclosingQuotes(value: string): string {
return value.replaceAll(/(?<quote>^\\?['"]|\\?['"]$)/gu, '')
Expand All @@ -65,7 +63,7 @@ export class Options {
*
* @internal
* @return {void}
* @since unreleased
* @since 0.2.0
*/
private buildFromPrivateOptions(): void {
this.#options.forEach((option: string, index: number) => {
Expand All @@ -88,7 +86,7 @@ export class Options {
*
* @internal
* @return {void}
* @since unreleased
* @since 0.2.0
*/
private convertBooleanOptions(): void {
for (const prop in this) {
Expand All @@ -106,8 +104,7 @@ export class Options {
* @param {string} arg Current arg being filtered.
* @param {number} index Current arg index.
* @return {boolean} Whether the arg is a positional arg.
* @since unreleased
* @todo Refactor.
* @since 0.2.0
*/
private isPositionalArg(arg: string, index: number): boolean {
const previousArg = this.#args[index - 1]
Expand All @@ -130,7 +127,7 @@ export class Options {
* splitShortFlagsToArgs('--abc') === ['--abc']
* @example
* splitShortFlagsToArgs('-abc') === ['-a', '-b', '-c']
* @since unreleased
* @since 0.2.0
*/
private splitShortFlagsToArgs(arg: string): string[] {
return /^-[^-]/u.test(arg)
Expand Down
8 changes: 4 additions & 4 deletions src/CommandLine/PositionalArguments.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/**
* @internal
* @since unreleased
* @since 0.2.0
*/
export class PositionalArguments {
/**
* Positional arguments from current process.
*
* @since unreleased
* @since 0.2.0
*/
readonly #positionalArguments: string[]

/**
* Filters positional arguments from a list of all process arguments.
*
* @param {string[]} args All process arguments.
* @since unreleased
* @since 0.2.0
*/
public constructor(args: string[]) {
this.#positionalArguments = args.filter(
Expand All @@ -33,7 +33,7 @@ export class PositionalArguments {
* Returns positional arguments as an array.
*
* @return {string[]} Positional arguments represented as an array.
* @since unreleased
* @since 0.2.0
*/
public toArray(): string[] {
return this.#positionalArguments
Expand Down
4 changes: 2 additions & 2 deletions src/CommandLine/Streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Duplex } from 'node:stream'
/**
* Command line interface streams.
*
* @since unreleased
* @since 0.2.0
*/
export type Streams = {
stderr: Duplex
Expand All @@ -15,7 +15,7 @@ export type Streams = {
/**
* Default command line interface streams.
*
* @since unreleased
* @since 0.2.0
*/
export const STREAMS: Streams = {
stderr,
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/Exception.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Exception extends Error {}
/**
* Final class was extended extension.
*
* @since unreleased
* @since 0.2.0
*/
export class FinalClassWasExtended extends Exception {
public readonly finalClass: string
Expand All @@ -19,7 +19,7 @@ export class FinalClassWasExtended extends Exception {
* Constructs a FinalClassWasExtended exception.
*
* @param {string} finalClass Final class which was extended.
* @since unreleased
* @since 0.2.0
*/
public constructor(finalClass: FinalClass) {
super(`Final class ${finalClass.name} may not be extended.`)
Expand Down
1 change: 0 additions & 1 deletion src/Input/NetworkInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export class NetworkInput {
*
* @return {Promise<Configuration>} Configuration data.
* @since unreleased
* @todo Refactor.
*/
public async getConfiguration(): Promise<Configuration> {
const configuration: Configuration = {
Expand Down

0 comments on commit f595772

Please sign in to comment.