Comparing version 3.2.1 to 3.3.0
@@ -43,2 +43,3 @@ const { Transform } = require('stream'); | ||
const $_Replaceable = require('./Replaceable'); | ||
const $_SyncReplaceable = require('./SyncReplaceable'); | ||
@@ -62,2 +63,2 @@ /* documentary types/rules.xml */ | ||
module.exports.Replaceable = $_Replaceable | ||
//# sourceMappingURL=index.js.map | ||
module.exports.SyncReplaceable = $_SyncReplaceable |
@@ -11,4 +11,14 @@ function checkRule(reObject) { | ||
const hideStack = (commonError, thrownError) => { | ||
if (!(thrownError instanceof Error)) throw thrownError | ||
const [, , commonLine] = commonError.stack.split('\n', 3) | ||
const i = thrownError.stack.indexOf(commonLine) | ||
if (i == -1) throw thrownError | ||
const stack = thrownError.stack.substr(0, i - 1) | ||
const li = stack.lastIndexOf('\n') | ||
thrownError.stack = stack.substr(0, li) | ||
throw thrownError | ||
} | ||
module.exports.checkRule = checkRule | ||
//# sourceMappingURL=index.js.map | ||
module.exports.hideStack = hideStack |
@@ -116,3 +116,2 @@ const getDefaultRegExp = (name) => { | ||
module.exports.makePasteRule = makePasteRule | ||
module.exports.makeCutRule = makeCutRule | ||
//# sourceMappingURL=markers.js.map | ||
module.exports.makeCutRule = makeCutRule |
const { Transform } = require('stream'); | ||
const { checkRule } = require('./lib'); | ||
const { checkRule, hideStack } = require('./lib'); | ||
let cleanStack = require('@artdeco/clean-stack'); if (cleanStack && cleanStack.__esModule) cleanStack = cleanStack.default; | ||
@@ -94,14 +94,2 @@ | ||
const hideStack = (commonError, thrownError) => { | ||
if (!(thrownError instanceof Error)) throw thrownError | ||
const [, , commonLine] = commonError.stack.split('\n', 3) | ||
const i = thrownError.stack.indexOf(commonLine) | ||
if (i == -1) throw thrownError | ||
const stack = thrownError.stack.substr(0, i - 1) | ||
const li = stack.lastIndexOf('\n') | ||
thrownError.stack = stack.substr(0, li) | ||
throw thrownError | ||
} | ||
module.exports = Replaceable | ||
//# sourceMappingURL=Replaceable.js.map | ||
module.exports = Replaceable |
@@ -1,3 +0,11 @@ | ||
## 13 September | ||
## 1 November 2018 | ||
### 3.3.0 | ||
- [feature] Add `SyncReplaceable` to the API, doc, and test. | ||
- [build] Build without source maps. | ||
- [deps] Update the dev dependencies. | ||
## 13 September 2018 | ||
### 3.2.1 | ||
@@ -4,0 +12,0 @@ |
{ | ||
"name": "restream", | ||
"version": "3.2.1", | ||
"version": "3.3.0", | ||
"description": "Regular Expression Detection & Replacement streams", | ||
@@ -8,7 +8,7 @@ "main": "build", | ||
"t": "zoroaster -a", | ||
"test": "zoroaster test/spec -a", | ||
"test": "zoroaster test/spec test/result -a", | ||
"test-build": "ALAMODE_ENV=test-build yarn test", | ||
"test-examples/": "zoroaster test-examples/spec -a", | ||
"build": "yarn-s d doc b", | ||
"b": "alamode src -o build", | ||
"b": "alamode src -o build -s", | ||
"d1": "NODE_DEBUG=doc doc src/index.js -g", | ||
@@ -53,10 +53,10 @@ "d2": "NODE_DEBUG=doc doc src/lib/markers.js -g", | ||
"devDependencies": { | ||
"alamode": "1.4.0", | ||
"alamode": "1.6.0", | ||
"catchment": "3.1.1", | ||
"documentary": "1.15.1", | ||
"documentary": "1.20.1", | ||
"eslint-config-artdeco": "1.0.1", | ||
"snapshot-context": "2.0.4", | ||
"spawncommand": "2.0.1", | ||
"spawncommand": "2.1.0", | ||
"yarn-s": "1.1.0", | ||
"zoroaster": "3.1.0" | ||
"zoroaster": "3.6.6" | ||
}, | ||
@@ -63,0 +63,0 @@ "dependencies": { |
@@ -5,4 +5,12 @@ # restream | ||
Regular expression detection implemented as a `Transform` steam; and regex-based buffer replacement stream to replace incoming data on-the-fly. | ||
**Restream**: Regular expression detection implemented as a `Transform` steam; | ||
_and_ | ||
**Replaceable**: Regex-based replacement stream to update incoming data on-the-fly (possibly with async functions). Transforms data from a stream using a set of regular expressions. Allows to build complex pipelines for transforming string using cut-and-paste rules to prevent certain rules to work on undesired piece of input; | ||
_and_ | ||
**SyncReplaceable**: The synchronous version of the _Replaceable_ that that is just a function and not a stream. Returns the result immediately and is deterministic. | ||
``` | ||
@@ -26,11 +34,12 @@ yarn add -E restream | ||
* [`Replacer` Context](#replacer-context) | ||
* [`brake()`](#brake-void) | ||
* [`Replacer` Errors](#replacer-errors) | ||
* [Collecting Into Catchment](#collecting-into-catchment) | ||
- [`SyncReplaceable(input: string, rules: Rules[]): string`](#syncreplaceableinput-stringrules-rules-string) | ||
- [Markers](#markers) | ||
* [`makeMarkers(matchers: { [name]: RegExp }, config?: MakeMarkersConfig): { [name]: Marker }`](#makemarkersmatchers--name-regexp-config-makemarkersconfig--name-marker-) | ||
* [`MakeMarkersConfig`](#makemarkersconfig) | ||
* [`MakeMarkersConfig`](#type-makemarkersconfig) | ||
* [`makeCutRule(marker: Marker): Rule`](#makecutrulemarker-marker-rule) | ||
* [`makePasteRule(marker: Marker): Rule`](#makepasterulemarker-marker-rule) | ||
* [Accessing Replacements](#accessing-replacements) | ||
- [TODO](#todo) | ||
- [Related Packages](#related-packages) | ||
@@ -45,3 +54,3 @@ - [Copyright](#copyright) | ||
import restream, { | ||
Replaceable, | ||
Replaceable, SyncReplaceable, | ||
makeMarkers, makeCutRule, makePasteRule, | ||
@@ -247,4 +256,5 @@ } from 'restream' | ||
Author: <strong>John</strong> | ||
on <em>2018-9-5 05:28:04</em> | ||
on <em>2018-11-1 17:10:51</em> | ||
``` | ||
### `Replacer` Context | ||
@@ -463,2 +473,43 @@ | ||
## `SyncReplaceable(`<br/> `input: string,`<br/> `rules: Rules[],`<br/>`): string` | ||
The _SyncReplaceable_ can be used when data is already stored on memory (for example, if you're running an Azure function with Node.js and it doesn't support streaming), and needs to be transformed using the synchronous flow. This implies that the asynchronous methods would not work also. | ||
```js | ||
/** yarn e example/sync.js */ | ||
import { SyncReplaceable } from 'replaceable' | ||
const n = ['zero', 'one', 'two', 'three', 'four', | ||
'five', 'six', 'seven', 'eight', 'nine'] | ||
const input = `Test String: {12345} | ||
Example Test: {67890}` | ||
const res = SyncReplaceable(input, [ | ||
// The rule to map numbers into their names. | ||
{ | ||
re: /{(\d+)}/g, | ||
replacement(match, num) { | ||
return num.split('').map((nn) => { | ||
return n[nn] | ||
}).join(', ') | ||
}, | ||
}, | ||
// The rule to end every line with a dot. | ||
{ | ||
re: /^[\s\S]*$/, | ||
replacement(match) { | ||
return match | ||
.split('\n') | ||
.map(a => `${a}.`) | ||
.join('\n') | ||
}, | ||
}, | ||
]) | ||
``` | ||
``` | ||
Test String: one, two, three, four, five. | ||
Example Test: six, seven, eight, nine, zero. | ||
``` | ||
## Markers | ||
@@ -607,8 +658,8 @@ | ||
__<a name="makemarkersconfig">`MakeMarkersConfig`</a>__: Additional configuration. | ||
__<a name="type-makemarkersconfig">`MakeMarkersConfig`</a>__: Additional configuration. | ||
| Name | Type | Description | Default | | ||
| ---- | ---- | ----------- | ------- | | ||
| getReplacement | _(name: string, index: number) => string_ | A function used to create a replacement when some text needs to be cut. | - | | ||
| getRegex | _(name: string) => RegExp_ | A function used to create a RegExp to detect replaced chunks. | - | | ||
| Name | Type | Description | | ||
| -------------- | -------------------------------------------- | ----------------------------------------------------------------------- | | ||
| getReplacement | _(name: string, index: number) => string_ | A function used to create a replacement when some text needs to be cut. | | ||
| getRegex | _(name: string) => RegExp_ | A function used to create a RegExp to detect replaced chunks. | | ||
@@ -755,8 +806,2 @@ By default, `%%_RESTREAM_${name.toUpperCase()}_REPLACEMENT_${index}_%%` replacement is used with <code>new RegExp(`%%_RESTREAM_${name.toUpperCase()}_REPLACEMENT_(\\d+)_%%`, 'g')</code> regex to detect it and restore the original value. | ||
## TODO | ||
- [ ] Serial execution of async replacers. | ||
- [ ] Allow to accumulate all data into memory (i.e. embed catchment). | ||
- [ ] Document testing w/ `zoroaster` masks. | ||
## Related Packages | ||
@@ -766,8 +811,9 @@ | ||
| Name | Description | | ||
| ---- | ----------- | | ||
| Name | Description | | ||
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- | | ||
| [`catchment`](https://github.com/artdecocode/catchment) | Collect all data flowing in from the stream into memory, and provide a promise resolved when the stream finishes. | | ||
| [`pedantry`](https://github.com/artdecocode/pedantry) | Read a directory as a stream. | | ||
| [`which-stream`](https://github.com/artdecocode/which-stream) | Create or choose source and destination (including `stdout`) streams easily. | | ||
| [`pedantry`](https://github.com/artdecocode/pedantry) | Read a directory as a stream. | | ||
| [`which-stream`](https://github.com/artdecocode/which-stream) | Create or choose source and destination (including `stdout`) streams easily. | | ||
| [`spawncommand`](https://github.com/artdecocode/spawncommand) | Spawn or fork a process and return a promise resolved with `stdout` and `stderr` data when it exits. | | ||
| [`documentary`](https://github.com/artdecocode/documentary) | Transforms the markdown files to be able to insert the content of example files and their output asynchronously. | | ||
@@ -778,2 +824,2 @@ ## Copyright | ||
[1]: https://artdeco.bz | ||
[1]: https://artd.eco |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
371
816
43046
9