From 8fbf3fd18f7e9addcea95f60cdb9c9f0b23b8136 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sat, 25 Jan 2020 10:36:43 +0100 Subject: [PATCH] Refactor prose --- readme.md | 77 +++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/readme.md b/readme.md index f91e814..ce3d38b 100644 --- a/readme.md +++ b/readme.md @@ -7,18 +7,18 @@ > **trough** /trôf/ — a channel used to convey a liquid. -`trough` is like [`ware`][ware] with less sugar, and middleware -functions can change the input of the next. +`trough` is like [`ware`][ware] with less sugar, and middleware functions can +change the input of the next. -## Installation +## Install [npm][]: -```bash +```sh npm install trough ``` -## Usage +## Use ```js var fs = require('fs') @@ -27,7 +27,7 @@ var trough = require('trough') var pipeline = trough() .use(function(fileName) { - console.log('Checking... ' + fileName) + console.log('Checking… ' + fileName) }) .use(function(fileName) { return path.join(process.cwd(), fileName) @@ -52,8 +52,8 @@ pipeline.run('node_modules', console.log) Yields: ```txt -Checking... readme.md -Checking... node_modules +Checking… readme.md +Checking… node_modules Error: Expected file at ~/example.js:21:12 at wrapped (~/node_modules/trough/index.js:93:19) @@ -70,7 +70,7 @@ null Note! as the length of input defines whether [async][] functions get a `next` +> Note! +> as the length of input defines whether [async][] functions get a `next` > function, it’s recommended to keep `input` at one value normally. -##### `function done(err?, [output...])` +##### `function done(err?, [output…])` -The final handler passed to [`run()`][run], invoked with an error -if a [middleware function][fn] rejected, passed, or threw one, or -the output of the last middleware function. +The final handler passed to [`run()`][run], invoked with an error if a +[middleware function][fn] rejected, passed, or threw one, or the output of the +last middleware function. #### `Trough#use(fn)` Add `fn`, a [middleware function][fn], to the pipeline. -##### `function fn([input..., ][next])` +##### `function fn([input…, ][next])` A middleware function invoked with the output of its predecessor. ###### Synchronous -If `fn` returns or throws an error, the pipeline fails and `done` is -invoked with that error. +If `fn` returns or throws an error, the pipeline fails and `done` is invoked +with that error. -If `fn` returns a value (neither `null` nor `undefined`), the first -`input` of the next function is set to that value (all other `input` -is passed through). +If `fn` returns a value (neither `null` nor `undefined`), the first `input` of +the next function is set to that value (all other `input` is passed through). The following example shows how returning an error stops the pipeline: @@ -142,7 +143,7 @@ Yields: ```txt Error: Got: some value at ~/example.js:5:12 - ... + … ``` The following example shows how throwing an error stops the pipeline: @@ -162,7 +163,7 @@ Yields: ```txt Error: Got: more value at ~/example.js:5:11 - ... + … ``` The following example shows how the first output can be modified: @@ -185,12 +186,12 @@ null 'even more value' 'untouched' ###### Promise -If `fn` returns a promise, and that promise rejects, the pipeline fails -and `done` is invoked with the rejected value. +If `fn` returns a promise, and that promise rejects, the pipeline fails and +`done` is invoked with the rejected value. -If `fn` returns a promise, and that promise resolves with a value -(neither `null` nor `undefined`), the first `input` of the next function -is set to that value (all other `input` is passed through). +If `fn` returns a promise, and that promise resolves with a value (neither +`null` nor `undefined`), the first `input` of the next function is set to that +value (all other `input` is passed through). The following example shows how rejecting a promise stops the pipeline: @@ -212,8 +213,7 @@ Yields: Got: val ``` -The following example shows how the input isn’t touched by resolving -to `null`. +The following example shows how the input isn’t touched by resolving to `null`. ```js var trough = require('trough') @@ -237,9 +237,9 @@ null 'Input' ###### Asynchronous -If `fn` accepts one more argument than the given `input`, a `next` -function is given (after the input). `next` must be called, but doesn’t -have to be called async. +If `fn` accepts one more argument than the given `input`, a `next` function is +given (after the input). `next` must be called, but doesn’t have to be called +async. If `next` is given a value (neither `null` nor `undefined`) as its first argument, the pipeline fails and `done` is invoked with that value. @@ -248,8 +248,7 @@ If `next` is given no value (either `null` or `undefined`) as the first argument, all following non-nully values change the input of the following function, and all nully values default to the `input`. -The following example shows how passing a first argument stops the -pipeline: +The following example shows how passing a first argument stops the pipeline: ```js var trough = require('trough')