diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/readdirp/examples | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) |
update packages
Diffstat (limited to 'node_modules/readdirp/examples')
-rw-r--r-- | node_modules/readdirp/examples/Readme.md | 37 | ||||
-rw-r--r-- | node_modules/readdirp/examples/callback-api.js | 10 | ||||
-rw-r--r-- | node_modules/readdirp/examples/grep.js | 71 | ||||
-rw-r--r-- | node_modules/readdirp/examples/package.json | 9 | ||||
-rw-r--r-- | node_modules/readdirp/examples/stream-api-pipe.js | 19 | ||||
-rw-r--r-- | node_modules/readdirp/examples/stream-api.js | 15 |
6 files changed, 0 insertions, 161 deletions
diff --git a/node_modules/readdirp/examples/Readme.md b/node_modules/readdirp/examples/Readme.md deleted file mode 100644 index 55fc4611b..000000000 --- a/node_modules/readdirp/examples/Readme.md +++ /dev/null @@ -1,37 +0,0 @@ -# readdirp examples - -## How to run the examples - -Assuming you installed readdirp (`npm install readdirp`), you can do the following: - -1. `npm explore readdirp` -2. `cd examples` -3. `npm install` - -At that point you can run the examples with node, i.e., `node grep`. - -## stream api - -[stream-api.js](https://github.com/thlorenz/readdirp/blob/master/examples/stream-api.js) - -Demonstrates error and data handling by listening to events emitted from the readdirp stream. - -## stream api pipe - -[stream-api-pipe.js](https://github.com/thlorenz/readdirp/blob/master/examples/stream-api-pipe.js) - -Demonstrates error handling by listening to events emitted from the readdirp stream and how to pipe the data stream into -another destination stream. - -## grep - -[grep.js](https://github.com/thlorenz/readdirp/blob/master/examples/grep.js) - -Very naive implementation of grep, for demonstration purposes only. - -## using callback api - -[callback-api.js](https://github.com/thlorenz/readdirp/blob/master/examples/callback-api.js) - -Shows how to pass callbacks in order to handle errors and/or data. - diff --git a/node_modules/readdirp/examples/callback-api.js b/node_modules/readdirp/examples/callback-api.js deleted file mode 100644 index 39bd2d798..000000000 --- a/node_modules/readdirp/examples/callback-api.js +++ /dev/null @@ -1,10 +0,0 @@ -var readdirp = require('..'); - -readdirp({ root: '.', fileFilter: '*.js' }, function (errors, res) { - if (errors) { - errors.forEach(function (err) { - console.error('Error: ', err); - }); - } - console.log('all javascript files', res); -}); diff --git a/node_modules/readdirp/examples/grep.js b/node_modules/readdirp/examples/grep.js deleted file mode 100644 index 01d5f2954..000000000 --- a/node_modules/readdirp/examples/grep.js +++ /dev/null @@ -1,71 +0,0 @@ -'use strict'; -var readdirp = require('..') - , util = require('util') - , fs = require('fs') - , path = require('path') - , es = require('event-stream') - ; - -function findLinesMatching (searchTerm) { - - return es.through(function (entry) { - var lineno = 0 - , matchingLines = [] - , fileStream = this; - - function filter () { - return es.mapSync(function (line) { - lineno++; - return ~line.indexOf(searchTerm) ? lineno + ': ' + line : undefined; - }); - } - - function aggregate () { - return es.through( - function write (data) { - matchingLines.push(data); - } - , function end () { - - // drop files that had no matches - if (matchingLines.length) { - var result = { file: entry, lines: matchingLines }; - - // pass result on to file stream - fileStream.emit('data', result); - } - this.emit('end'); - } - ); - } - - fs.createReadStream(entry.fullPath, { encoding: 'utf-8' }) - - // handle file contents line by line - .pipe(es.split('\n')) - - // keep only the lines that matched the term - .pipe(filter()) - - // aggregate all matching lines and delegate control back to the file stream - .pipe(aggregate()) - ; - }); -} - -console.log('grepping for "arguments"'); - -// create a stream of all javascript files found in this and all sub directories -readdirp({ root: path.join(__dirname), fileFilter: '*.js' }) - - // find all lines matching the term for each file (if none found, that file is ignored) - .pipe(findLinesMatching('arguments')) - - // format the results and output - .pipe( - es.mapSync(function (res) { - return '\n\n' + res.file.path + '\n\t' + res.lines.join('\n\t'); - }) - ) - .pipe(process.stdout) - ; diff --git a/node_modules/readdirp/examples/package.json b/node_modules/readdirp/examples/package.json deleted file mode 100644 index 2d9b34119..000000000 --- a/node_modules/readdirp/examples/package.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "readdirp-examples", - "version": "0.0.0", - "description": "Examples for readdirp.", - "dependencies": { - "tap-stream": "~0.1.0", - "event-stream": "~3.0.7" - } -} diff --git a/node_modules/readdirp/examples/stream-api-pipe.js b/node_modules/readdirp/examples/stream-api-pipe.js deleted file mode 100644 index 4003be8d3..000000000 --- a/node_modules/readdirp/examples/stream-api-pipe.js +++ /dev/null @@ -1,19 +0,0 @@ -var readdirp = require('..') - , path = require('path') - , through = require('through2') - -// print out all JavaScript files along with their size -readdirp({ root: path.join(__dirname), fileFilter: '*.js' }) - .on('warn', function (err) { console.error('non-fatal error', err); }) - .on('error', function (err) { console.error('fatal error', err); }) - .pipe(through.obj(function (entry, _, cb) { - this.push({ path: entry.path, size: entry.stat.size }); - cb(); - })) - .pipe(through.obj( - function (res, _, cb) { - this.push(JSON.stringify(res) + '\n'); - cb(); - }) - ) - .pipe(process.stdout); diff --git a/node_modules/readdirp/examples/stream-api.js b/node_modules/readdirp/examples/stream-api.js deleted file mode 100644 index 0f7b327eb..000000000 --- a/node_modules/readdirp/examples/stream-api.js +++ /dev/null @@ -1,15 +0,0 @@ -var readdirp = require('..') - , path = require('path'); - -readdirp({ root: path.join(__dirname), fileFilter: '*.js' }) - .on('warn', function (err) { - console.error('something went wrong when processing an entry', err); - }) - .on('error', function (err) { - console.error('something went fatally wrong and the stream was aborted', err); - }) - .on('data', function (entry) { - console.log('%s is ready for processing', entry.path); - // process entry here - }); - |