WIP - add extractor, generate snippet_data
This commit is contained in:
74
node_modules/trough/index.js
generated
vendored
Normal file
74
node_modules/trough/index.js
generated
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
'use strict'
|
||||
|
||||
var wrap = require('./wrap.js')
|
||||
|
||||
module.exports = trough
|
||||
|
||||
trough.wrap = wrap
|
||||
|
||||
var slice = [].slice
|
||||
|
||||
// Create new middleware.
|
||||
function trough() {
|
||||
var fns = []
|
||||
var middleware = {}
|
||||
|
||||
middleware.run = run
|
||||
middleware.use = use
|
||||
|
||||
return middleware
|
||||
|
||||
// Run `fns`. Last argument must be a completion handler.
|
||||
function run() {
|
||||
var index = -1
|
||||
var input = slice.call(arguments, 0, -1)
|
||||
var done = arguments[arguments.length - 1]
|
||||
|
||||
if (typeof done !== 'function') {
|
||||
throw new Error('Expected function as last argument, not ' + done)
|
||||
}
|
||||
|
||||
next.apply(null, [null].concat(input))
|
||||
|
||||
// Run the next `fn`, if any.
|
||||
function next(err) {
|
||||
var fn = fns[++index]
|
||||
var params = slice.call(arguments, 0)
|
||||
var values = params.slice(1)
|
||||
var length = input.length
|
||||
var pos = -1
|
||||
|
||||
if (err) {
|
||||
done(err)
|
||||
return
|
||||
}
|
||||
|
||||
// Copy non-nully input into values.
|
||||
while (++pos < length) {
|
||||
if (values[pos] === null || values[pos] === undefined) {
|
||||
values[pos] = input[pos]
|
||||
}
|
||||
}
|
||||
|
||||
input = values
|
||||
|
||||
// Next or done.
|
||||
if (fn) {
|
||||
wrap(fn, next).apply(null, input)
|
||||
} else {
|
||||
done.apply(null, [null].concat(input))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add `fn` to the list.
|
||||
function use(fn) {
|
||||
if (typeof fn !== 'function') {
|
||||
throw new Error('Expected `fn` to be a function, not ' + fn)
|
||||
}
|
||||
|
||||
fns.push(fn)
|
||||
|
||||
return middleware
|
||||
}
|
||||
}
|
||||
21
node_modules/trough/license
generated
vendored
Normal file
21
node_modules/trough/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
110
node_modules/trough/package.json
generated
vendored
Normal file
110
node_modules/trough/package.json
generated
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
{
|
||||
"_from": "trough@^1.0.0",
|
||||
"_id": "trough@1.0.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-tdzBRDGWcI1OpPVmChbdSKhvSVurznZ8X36AYURAcl+0o2ldlCY2XPzyXNNxwJwwyIU+rIglTCG4kxtNKBQH7Q==",
|
||||
"_location": "/trough",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "trough@^1.0.0",
|
||||
"name": "trough",
|
||||
"escapedName": "trough",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/remark/unified",
|
||||
"/unified"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/trough/-/trough-1.0.4.tgz",
|
||||
"_shasum": "3b52b1f13924f460c3fbfd0df69b587dbcbc762e",
|
||||
"_spec": "trough@^1.0.0",
|
||||
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/remark/node_modules/unified",
|
||||
"author": {
|
||||
"name": "Titus Wormer",
|
||||
"email": "tituswormer@gmail.com",
|
||||
"url": "https://wooorm.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wooorm/trough/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Titus Wormer",
|
||||
"email": "tituswormer@gmail.com",
|
||||
"url": "https://wooorm.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Middleware: a channel used to convey a liquid",
|
||||
"devDependencies": {
|
||||
"browserify": "^16.0.0",
|
||||
"nyc": "^14.0.0",
|
||||
"prettier": "^1.12.0",
|
||||
"remark-cli": "^6.0.0",
|
||||
"remark-preset-wooorm": "^4.0.0",
|
||||
"tape": "^4.4.0",
|
||||
"tinyify": "^2.4.3",
|
||||
"xo": "^0.24.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"wrap.js"
|
||||
],
|
||||
"homepage": "https://github.com/wooorm/trough#readme",
|
||||
"keywords": [
|
||||
"middleware",
|
||||
"ware"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "trough",
|
||||
"nyc": {
|
||||
"check-coverage": true,
|
||||
"lines": 100,
|
||||
"functions": 100,
|
||||
"branches": 100
|
||||
},
|
||||
"prettier": {
|
||||
"tabWidth": 2,
|
||||
"useTabs": false,
|
||||
"singleQuote": true,
|
||||
"bracketSpacing": false,
|
||||
"semi": false,
|
||||
"trailingComma": "none"
|
||||
},
|
||||
"remarkConfig": {
|
||||
"plugins": [
|
||||
"preset-wooorm"
|
||||
]
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wooorm/trough.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "npm run build-bundle && npm run build-mangle",
|
||||
"build-bundle": "browserify index.js -s trough > trough.js",
|
||||
"build-mangle": "browserify index.js -s trough -p tinyify > trough.min.js",
|
||||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
|
||||
"test": "npm run format && npm run build && npm run test-coverage",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "nyc --reporter lcov tape test.js"
|
||||
},
|
||||
"version": "1.0.4",
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"esnext": false,
|
||||
"rules": {
|
||||
"guard-for-in": "off",
|
||||
"unicorn/prefer-type-error": "off"
|
||||
},
|
||||
"ignores": [
|
||||
"trough.js"
|
||||
]
|
||||
}
|
||||
}
|
||||
331
node_modules/trough/readme.md
generated
vendored
Normal file
331
node_modules/trough/readme.md
generated
vendored
Normal file
@ -0,0 +1,331 @@
|
||||
# trough
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
|
||||
> **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.
|
||||
|
||||
## Installation
|
||||
|
||||
[npm][]:
|
||||
|
||||
```bash
|
||||
npm install trough
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
var fs = require('fs')
|
||||
var path = require('path')
|
||||
var trough = require('trough')
|
||||
|
||||
var pipeline = trough()
|
||||
.use(function(fileName) {
|
||||
console.log('Checking... ' + fileName)
|
||||
})
|
||||
.use(function(fileName) {
|
||||
return path.join(process.cwd(), fileName)
|
||||
})
|
||||
.use(function(filePath, next) {
|
||||
fs.stat(filePath, function(err, stats) {
|
||||
next(err, {filePath, stats})
|
||||
})
|
||||
})
|
||||
.use(function(ctx, next) {
|
||||
if (ctx.stats.isFile()) {
|
||||
fs.readFile(ctx.filePath, next)
|
||||
} else {
|
||||
next(new Error('Expected file'))
|
||||
}
|
||||
})
|
||||
|
||||
pipeline.run('readme.md', console.log)
|
||||
pipeline.run('node_modules', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
Checking... readme.md
|
||||
Checking... node_modules
|
||||
Error: Expected file
|
||||
at ~/example.js:21:12
|
||||
at wrapped (~/node_modules/trough/index.js:93:19)
|
||||
at next (~/node_modules/trough/index.js:56:24)
|
||||
at done (~/node_modules/trough/index.js:124:12)
|
||||
at ~/node_modules/example.js:14:7
|
||||
at FSReqWrap.oncomplete (fs.js:153:5)
|
||||
null <Buffer 23 20 74 72 6f 75 67 68 20 5b 21 5b 42 75 69 6c 64 20 53 74 61 74 75 73 5d 5b 74 72 61 76 69 73 2d 62 61 64 67 65 5d 5d 5b 74 72 61 76 69 73 5d 20 5b ... >
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `trough()`
|
||||
|
||||
Create a new [`Trough`][trough].
|
||||
|
||||
#### `trough.wrap(middleware, callback[, ...input])`
|
||||
|
||||
Call `middleware` with all input.
|
||||
If `middleware` accepts more arguments than given in input, and extra `done`
|
||||
function is passed in after the input when calling it.
|
||||
It must be called.
|
||||
|
||||
The first value in `input` is called the main input value.
|
||||
All other input values are called the rest input values.
|
||||
The values given to `callback` are the input values, merged with every
|
||||
non-nully output value.
|
||||
|
||||
* If `middleware` throws an error, returns a promise that is rejected, or
|
||||
calls the given `done` function with an error, `callback` is invoked with
|
||||
that error
|
||||
* If `middleware` returns a value or returns a promise that is resolved, that
|
||||
value is the main output value
|
||||
* If `middleware` calls `done`, all non-nully values except for the first one
|
||||
(the error) overwrite the output values
|
||||
|
||||
### `Trough`
|
||||
|
||||
A pipeline.
|
||||
|
||||
#### `Trough#run([input..., ]done)`
|
||||
|
||||
Run the pipeline (all [`use()`][use]d middleware). Invokes [`done`][done]
|
||||
on completion with either an error or the output of the last middleware
|
||||
|
||||
> 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...])`
|
||||
|
||||
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])`
|
||||
|
||||
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 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:
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function(val) {
|
||||
return new Error('Got: ' + val)
|
||||
})
|
||||
.run('some value', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
Error: Got: some value
|
||||
at ~/example.js:5:12
|
||||
...
|
||||
```
|
||||
|
||||
The following example shows how throwing an error stops the pipeline:
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function(val) {
|
||||
throw new Error('Got: ' + val)
|
||||
})
|
||||
.run('more value', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
Error: Got: more value
|
||||
at ~/example.js:5:11
|
||||
...
|
||||
```
|
||||
|
||||
The following example shows how the first output can be modified:
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function(val) {
|
||||
return 'even ' + val
|
||||
})
|
||||
.run('more value', 'untouched', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
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 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:
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function(val) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
reject('Got: ' + val)
|
||||
})
|
||||
})
|
||||
.run('val', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
Got: val
|
||||
```
|
||||
|
||||
The following example shows how the input isn’t touched by resolving
|
||||
to `null`.
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function() {
|
||||
return new Promise(function(resolve) {
|
||||
setTimeout(function() {
|
||||
resolve(null)
|
||||
}, 100)
|
||||
})
|
||||
})
|
||||
.run('Input', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
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 `next` is given a value (neither `null` nor `undefined`) as its first
|
||||
argument, the pipeline fails and `done` is invoked with that value.
|
||||
|
||||
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:
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function(val, next) {
|
||||
next(new Error('Got: ' + val))
|
||||
})
|
||||
.run('val', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
Error: Got: val
|
||||
at ~/example.js:5:10
|
||||
```
|
||||
|
||||
The following example shows how more values than the input are passed.
|
||||
|
||||
```js
|
||||
var trough = require('trough')
|
||||
|
||||
trough()
|
||||
.use(function(val, next) {
|
||||
setTimeout(function() {
|
||||
next(null, null, 'values')
|
||||
}, 100)
|
||||
})
|
||||
.run('some', console.log)
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```txt
|
||||
null 'some' 'values'
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://img.shields.io/travis/wooorm/trough.svg
|
||||
|
||||
[build]: https://travis-ci.org/wooorm/trough
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/trough.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/wooorm/trough
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/trough.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/trough
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/trough.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=trough
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
|
||||
[ware]: https://github.com/segmentio/ware
|
||||
|
||||
[trough]: #trough-1
|
||||
|
||||
[use]: #troughusefn
|
||||
|
||||
[run]: #troughruninput-done
|
||||
|
||||
[fn]: #function-fninput-next
|
||||
|
||||
[done]: #function-doneerr-output
|
||||
|
||||
[async]: #asynchronous
|
||||
64
node_modules/trough/wrap.js
generated
vendored
Normal file
64
node_modules/trough/wrap.js
generated
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
'use strict'
|
||||
|
||||
var slice = [].slice
|
||||
|
||||
module.exports = wrap
|
||||
|
||||
// Wrap `fn`.
|
||||
// Can be sync or async; return a promise, receive a completion handler, return
|
||||
// new values and errors.
|
||||
function wrap(fn, callback) {
|
||||
var invoked
|
||||
|
||||
return wrapped
|
||||
|
||||
function wrapped() {
|
||||
var params = slice.call(arguments, 0)
|
||||
var callback = fn.length > params.length
|
||||
var result
|
||||
|
||||
if (callback) {
|
||||
params.push(done)
|
||||
}
|
||||
|
||||
try {
|
||||
result = fn.apply(null, params)
|
||||
} catch (error) {
|
||||
// Well, this is quite the pickle.
|
||||
// `fn` received a callback and invoked it (thus continuing the pipeline),
|
||||
// but later also threw an error.
|
||||
// We’re not about to restart the pipeline again, so the only thing left
|
||||
// to do is to throw the thing instead.
|
||||
if (callback && invoked) {
|
||||
throw error
|
||||
}
|
||||
|
||||
return done(error)
|
||||
}
|
||||
|
||||
if (!callback) {
|
||||
if (result && typeof result.then === 'function') {
|
||||
result.then(then, done)
|
||||
} else if (result instanceof Error) {
|
||||
done(result)
|
||||
} else {
|
||||
then(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke `next`, only once.
|
||||
function done() {
|
||||
if (!invoked) {
|
||||
invoked = true
|
||||
|
||||
callback.apply(null, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
// Invoke `done` with one value.
|
||||
// Tracks if an error is passed, too.
|
||||
function then(value) {
|
||||
done(null, value)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user