Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restream

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restream - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

build/index.js

9

CHANGELOG.md

@@ -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 @@

42

package.json
{
"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"
}
}

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc