Comparing version 1.2.0 to 2.0.0
@@ -0,1 +1,10 @@ | ||
## 2.0.0 (9 May 2018) | ||
* [style] switch to modules and use babel | ||
* [documentation] update examples and add scripts to run them, update readme | ||
* [documentation] add JSDoc types | ||
* [test] snapshot testing of examples | ||
* [dep] update zoroaster and catchment | ||
* [repository] move to [Art Deco Code](https://artdeco.bz) | ||
## 1.2.0 (29 May 2017) | ||
@@ -2,0 +11,0 @@ |
{ | ||
"name": "restream", | ||
"version": "1.2.0", | ||
"description": "Regular Expression Transform Stream for Node.js", | ||
"main": "src/index.js", | ||
"version": "2.0.0", | ||
"description": "Regular Expression Detection & Replacement streams", | ||
"main": "build", | ||
"scripts": { | ||
"test": "zoroaster test/spec" | ||
"test": "zoroaster test/spec --babel", | ||
"t": "zoroaster --babel", | ||
"build": "babel src --out-dir build", | ||
"e": "node examples/run", | ||
"examples/replace-function.js": "yarn e examples/replace-function", | ||
"examples/replace-stream.js": "yarn e examples/replace-stream", | ||
"examples/restream.js": "yarn e examples/restream" | ||
}, | ||
"files": [ | ||
"src/" | ||
"build" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Sobesednik/restream.git" | ||
"url": "git+https://github.com/artdecocode/restream.git" | ||
}, | ||
@@ -21,15 +27,27 @@ "keywords": [ | ||
"regexp", | ||
"re", | ||
"exec", | ||
"regular", | ||
"expression" | ||
"expression", | ||
"regular expression" | ||
], | ||
"author": "Anton <anton@sobesednik.media>", | ||
"author": "Anton <anton@adc.sh>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/Sobesednik/restream/issues" | ||
"url": "https://github.com/artdecocode/restream/issues" | ||
}, | ||
"homepage": "https://github.com/Sobesednik/restream#readme", | ||
"homepage": "https://github.com/artdecocode/restream#readme", | ||
"devDependencies": { | ||
"catchment": "1.0.0", | ||
"zoroaster": "0.4.4" | ||
"@babel/cli": "7.0.0-beta.46", | ||
"@babel/core": "7.0.0-beta.46", | ||
"@babel/plugin-syntax-object-rest-spread": "7.0.0-beta.46", | ||
"@babel/plugin-transform-modules-commonjs": "7.0.0-beta.46", | ||
"@babel/register": "7.0.0-beta.46", | ||
"catchment": "2.0.1", | ||
"spawncommand": "1.1.0", | ||
"zoroaster": "1.1.0" | ||
}, | ||
"dependencies": { | ||
"snapshot-context": "^1.1.0" | ||
} | ||
} |
172
README.md
@@ -5,4 +5,12 @@ # restream | ||
Regular Expression Transform Stream for Node.js | ||
``` | ||
yarn add -E restream | ||
``` | ||
Regular expression detection implemented as a transform Steam and regex-based buffer replacement stream to replace streamed data on-the-fly. | ||
```js | ||
import restream, { replaceStream } from 'restream' | ||
``` | ||
## restream(regex: RegExp) => Transform | ||
@@ -15,30 +23,23 @@ | ||
```js | ||
const restream = require('restream') | ||
const Readable = require('stream').Readable | ||
const Writable = require('stream').Writable | ||
/** yarn examples/restream.js **/ | ||
import restream from 'restream' | ||
import { createReadable, createWritable } from './lib' | ||
// your input readable stream which outputs strings | ||
const input = 'test-string-{12345}-{67890}' | ||
const rs = new Readable({ | ||
read: () => { | ||
rs.push(input) | ||
rs.push(null) | ||
}, | ||
}) | ||
(async () => { | ||
try { | ||
const rs = createReadable('test-string-{12345}-{67890}') | ||
// your output writable sream which saves incoming data | ||
const ws = new Writable({ objectMode: true }) | ||
const data = [] | ||
ws._write = (chunk, _, next) => { | ||
data.push(chunk) | ||
next() | ||
} | ||
const stream = restream(/{(\d+)}/g) // create a transform stream | ||
rs.pipe(stream) | ||
const regex = /{(\d+)}/g | ||
const rts = restream(regex) | ||
rs.pipe(rts).pipe(ws) | ||
const { data, ws } = createWritable() | ||
stream.pipe(ws) | ||
ws.once('finish', () => { | ||
console.log(data) | ||
}) | ||
ws.once('finish', () => { | ||
console.log(data) | ||
}) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
})() | ||
``` | ||
@@ -57,5 +58,5 @@ | ||
## restream.replaceStream(regexes: object[]) => Readable | ||
## replaceStream({re:RegExp, replacement:string }[]) => Transform | ||
Create a `Readable` stream which will make data available | ||
Creates a `Transform` stream which will make data available | ||
when an incoming chunk has been updated according to the `regex` input, which can | ||
@@ -67,37 +68,31 @@ be either a single regex object (`{ re: /regex/, replacement: 'hello-world' }`), | ||
```js | ||
const restream = require('restream') | ||
const Catchment = require('catchment') | ||
const Readable = require('stream').Readable | ||
/** yarn examples/replace-stream.js */ | ||
import Catchment from 'catchment' | ||
import { replaceStream } from 'restream' | ||
import { createReadable } from './lib' | ||
function createReadable() { | ||
const rs = new Readable({ | ||
read: () => { | ||
rs.push('Hello {{ name }}, your username is {{ user }}' | ||
+ ' and you have {{ stars }} stars') | ||
rs.push(null) | ||
}, | ||
}) | ||
return rs | ||
} | ||
(async () => { | ||
try { | ||
const stream = replaceStream([{ | ||
re: /{{ user }}/, | ||
replacement: 'fred', | ||
}, { | ||
re: /{{ name }}/g, | ||
replacement: 'Fred', | ||
}, { | ||
re: /{{ stars }}/, | ||
replacement: '5', | ||
}]) | ||
const regexes = [{ | ||
re: /{{ user }}/, | ||
replacement: 'fred', | ||
}, { | ||
re: /{{ name }}/g, | ||
replacement: 'Fred', | ||
}, { | ||
re: /{{ stars }}/, | ||
replacement: '5', | ||
}] | ||
const stream = restream.replaceStream(regexes) | ||
const rs = createReadable() | ||
rs.pipe(stream) | ||
const catchment = new Catchment() | ||
stream.pipe(catchment) | ||
catchment.promise | ||
.then((res) => { | ||
console.log(res) | ||
const rs = createReadable('Hello {{ name }}, your username is {{ user }} and you have {{ stars }} stars') | ||
rs.pipe(stream) | ||
const { promise } = new Catchment({ | ||
rs: stream, | ||
}) | ||
const res = await promise | ||
console.log(res) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
})() | ||
``` | ||
@@ -111,39 +106,33 @@ | ||
### Using a function | ||
## replaceStream({re:RegExp, replacement: function(match, ...params) }[]) => Transform | ||
You can replace matches using a function. See ([MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter)) | ||
for more documentation. | ||
You can replace matches using a function. See [MDN][2] for more documentation. | ||
```js | ||
const restream = require('restream') | ||
const Catchment = require('catchment') | ||
const Readable = require('stream').Readable | ||
/** yarn examples/replace-function.js */ | ||
import { replaceStream } from '../src' | ||
import Catchment from 'catchment' | ||
import { createReadable } from './lib' | ||
function createReadable() { | ||
const rs = new Readable({ | ||
read: () => { | ||
rs.push('Hello __Fred__, your username is __fred__' | ||
+ ' and you have __5__ stars') | ||
rs.push(null) | ||
}, | ||
}) | ||
return rs | ||
} | ||
const regexes = [{ | ||
re: /__(\S+)__/g, | ||
replacement: (match, p1) => { | ||
(async () => { | ||
try { | ||
const stream = replaceStream([{ | ||
re: /__(\S+)__/g, | ||
replacement(match, p1) { | ||
return `<em>${p1}</em>` | ||
}, | ||
}] | ||
}, | ||
}]) | ||
const rs = createReadable('Hello __Fred__, your username is __fred__ and you have __5__ stars.') | ||
rs.pipe(stream) | ||
const stream = restream.replaceStream(regexes) | ||
const rs = createReadable() | ||
rs.pipe(stream) | ||
const catchment = new Catchment() | ||
stream.pipe(catchment) | ||
catchment.promise | ||
.then((res) => { | ||
console.log(res) | ||
const { promise } = new Catchment({ | ||
rs: stream, | ||
}) | ||
const res = await promise | ||
console.log(res) | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
})() | ||
``` | ||
@@ -158,2 +147,5 @@ | ||
2017, [Sobesednik Media](https://sobesednik.media) | ||
(c) [Art Deco Code][1] 2018 | ||
[1]: https://artdeco.bz | ||
[2]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_function_as_a_parameter |
Sorry, the diff of this file is not supported yet
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
9264
1
8
61
146
+ Addedsnapshot-context@^1.1.0
+ Addedassert-diff@1.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedcatchment@2.0.1(transitive)
+ Addedclean-stack@1.3.0(transitive)
+ Addedcli-color@0.1.7(transitive)
+ Addeddiff@3.5.0(transitive)
+ Addeddifflib@0.2.4(transitive)
+ Addeddreamopt@0.6.0(transitive)
+ Addederotic@0.2.01.1.0(transitive)
+ Addederte@1.1.3(transitive)
+ Addedes5-ext@0.8.2(transitive)
+ Addedheap@0.2.7(transitive)
+ Addedjson-diff@0.5.2(transitive)
+ Addedmakepromise@1.1.1(transitive)
+ Addedpromto@1.0.1(transitive)
+ Addedreloquent@0.2.0(transitive)
+ Addedrestream@1.2.0(transitive)
+ Addedsnapshot-context@1.1.7(transitive)
+ Addedwordwrap@1.0.0(transitive)
+ Addedwrote@1.4.0(transitive)