Class

RegexpOutputWriter

RegexpOutputWriter(cmd, lock, regexp, flags)

Constructor

# new RegexpOutputWriter(cmd, lock, regexp, flags)

This class extends StandardOutputWriter to provide regex-based output processing. It allows for pattern matching in the output stream and can trigger specific actions based on matched patterns.

A specialized output writer that uses regular expressions to process output.

sequenceDiagram participant Client participant RegexpOutputWriter participant StandardOutputWriter participant Logger Client->>RegexpOutputWriter: new RegexpOutputWriter(cmd, lock, regexp, flags) RegexpOutputWriter->>StandardOutputWriter: super(cmd, lock) StandardOutputWriter->>Logger: Logging.for(cmd) RegexpOutputWriter->>RegexpOutputWriter: compile regexp Client->>RegexpOutputWriter: data(chunk) RegexpOutputWriter->>StandardOutputWriter: super.data(chunk) StandardOutputWriter->>Logger: logger.info(log) RegexpOutputWriter->>RegexpOutputWriter: testAndResolve(chunk) RegexpOutputWriter->>RegexpOutputWriter: test(chunk) alt match found RegexpOutputWriter->>RegexpOutputWriter: resolve(match[0]) RegexpOutputWriter->>StandardOutputWriter: resolve(match[0]) end Client->>RegexpOutputWriter: error(chunk) RegexpOutputWriter->>StandardOutputWriter: super.error(chunk) StandardOutputWriter->>Logger: logger.info(log) RegexpOutputWriter->>RegexpOutputWriter: testAndReject(chunk) RegexpOutputWriter->>RegexpOutputWriter: test(chunk) alt match found RegexpOutputWriter->>RegexpOutputWriter: reject(match[0]) RegexpOutputWriter->>StandardOutputWriter: reject(match[0]) end
Parameters:
Name Type Description
cmd

The command string to be executed.

lock

A PromiseExecutor to control the asynchronous flow.

regexp

A string or RegExp to match against the output.

flags

Optional flags for the RegExp constructor, defaults to "g".

View Source writers/RegexpOutputWriter.ts, line 67

Example
```typescript
import { RegexpOutputWriter } from '@decaf-ts/utils';
import { PromiseExecutor } from '@decaf-ts/utils';

// Create a promise executor
const executor: PromiseExecutor<string, Error> = {
  resolve: (value) => console.log(`Resolved: ${value}`),
  reject: (error) => console.error(`Rejected: ${error.message}`)
};

// Create a regexp output writer that matches version numbers
const writer = new RegexpOutputWriter('node --version', executor, /v(\d+\.\d+\.\d+)/);

// Use the writer to handle command output
writer.data('v14.17.0');  // This will automatically resolve with "v14.17.0"
```

Classes

RegexpOutputWriter

This class extends StandardOutputWriter to provide regex-based output processing. It allows for pattern matching in the output stream and can trigger specific actions based on matched patterns.

Members

# regexp

This readonly property stores the compiled RegExp used for pattern matching.

The regular expression used for matching output.

View Source writers/RegexpOutputWriter.ts, line 72

RegExp

# protected regexp

This readonly property stores the compiled RegExp used for pattern matching.

The regular expression used for matching output.

View Source writers/RegexpOutputWriter.ts, line 154

Methods

# data(chunk)

Calls the parent class data method and then tests the data for a match to potentially resolve the promise.

Processes incoming data chunks.

Parameters:
Name Type Description
chunk

The data chunk to process.

View Source writers/RegexpOutputWriter.ts, line 190

# error(chunk)

Calls the parent class error method and then tests the data for a match to potentially reject the promise.

Processes incoming error chunks.

Parameters:
Name Type Description
chunk

The error chunk to process.

View Source writers/RegexpOutputWriter.ts, line 198

# test(data)

Executes the regular expression on the input data and returns the match result.

Tests the input data against the stored regular expression.

Parameters:
Name Type Description
data

The string to test against the regular expression.

View Source writers/RegexpOutputWriter.ts, line 90

The result of the regular expression execution, or undefined if an error occurs.

# protected testAndReject(data)

Executes the test method and rejects the promise with the first match group if successful.

Tests the data and rejects the promise if a match is found.

Parameters:
Name Type Description
data

The string to test against the regular expression.

View Source writers/RegexpOutputWriter.ts, line 182

# protected testAndResolve(data)

Executes the test method and resolves the promise with the first match group if successful.

Tests the data and resolves the promise if a match is found.

Parameters:
Name Type Description
data

The string to test against the regular expression.

View Source writers/RegexpOutputWriter.ts, line 173