WIP - add extractor, generate snippet_data
This commit is contained in:
79
node_modules/into-stream/index.js
generated
vendored
Normal file
79
node_modules/into-stream/index.js
generated
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
'use strict';
|
||||
const from = require('from2');
|
||||
const pIsPromise = require('p-is-promise');
|
||||
|
||||
module.exports = x => {
|
||||
if (Array.isArray(x)) {
|
||||
x = x.slice();
|
||||
}
|
||||
|
||||
let promise;
|
||||
let iterator;
|
||||
|
||||
prepare(x);
|
||||
|
||||
function prepare(value) {
|
||||
x = value;
|
||||
promise = pIsPromise(x) ? x : null;
|
||||
// we don't iterate on strings and buffers since slicing them is ~7x faster
|
||||
const shouldIterate = !promise && x[Symbol.iterator] && typeof x !== 'string' && !Buffer.isBuffer(x);
|
||||
iterator = shouldIterate ? x[Symbol.iterator]() : null;
|
||||
}
|
||||
|
||||
return from(function reader(size, cb) {
|
||||
if (promise) {
|
||||
promise.then(prepare).then(() => reader.call(this, size, cb), cb);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iterator) {
|
||||
const obj = iterator.next();
|
||||
setImmediate(cb, null, obj.done ? null : obj.value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (x.length === 0) {
|
||||
setImmediate(cb, null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
const chunk = x.slice(0, size);
|
||||
x = x.slice(size);
|
||||
|
||||
setImmediate(cb, null, chunk);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports.obj = x => {
|
||||
if (Array.isArray(x)) {
|
||||
x = x.slice();
|
||||
}
|
||||
|
||||
let promise;
|
||||
let iterator;
|
||||
|
||||
prepare(x);
|
||||
|
||||
function prepare(value) {
|
||||
x = value;
|
||||
promise = pIsPromise(x) ? x : null;
|
||||
iterator = !promise && x[Symbol.iterator] ? x[Symbol.iterator]() : null;
|
||||
}
|
||||
|
||||
return from.obj(function reader(size, cb) {
|
||||
if (promise) {
|
||||
promise.then(prepare).then(() => reader.call(this, size, cb), cb);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iterator) {
|
||||
const obj = iterator.next();
|
||||
setImmediate(cb, null, obj.done ? null : obj.value);
|
||||
return;
|
||||
}
|
||||
|
||||
this.push(x);
|
||||
|
||||
setImmediate(cb, null, null);
|
||||
});
|
||||
};
|
||||
21
node_modules/into-stream/license
generated
vendored
Normal file
21
node_modules/into-stream/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
|
||||
10
node_modules/into-stream/node_modules/p-is-promise/index.js
generated
vendored
Normal file
10
node_modules/into-stream/node_modules/p-is-promise/index.js
generated
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
'use strict';
|
||||
module.exports = x => (
|
||||
x instanceof Promise ||
|
||||
(
|
||||
x !== null &&
|
||||
typeof x === 'object' &&
|
||||
typeof x.then === 'function' &&
|
||||
typeof x.catch === 'function'
|
||||
)
|
||||
);
|
||||
21
node_modules/into-stream/node_modules/p-is-promise/license
generated
vendored
Normal file
21
node_modules/into-stream/node_modules/p-is-promise/license
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.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.
|
||||
75
node_modules/into-stream/node_modules/p-is-promise/package.json
generated
vendored
Normal file
75
node_modules/into-stream/node_modules/p-is-promise/package.json
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
{
|
||||
"_from": "p-is-promise@^1.1.0",
|
||||
"_id": "p-is-promise@1.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-nJRWmJ6fZYgBewQ01WCXZ1w9oF4=",
|
||||
"_location": "/into-stream/p-is-promise",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "p-is-promise@^1.1.0",
|
||||
"name": "p-is-promise",
|
||||
"escapedName": "p-is-promise",
|
||||
"rawSpec": "^1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/into-stream"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/p-is-promise/-/p-is-promise-1.1.0.tgz",
|
||||
"_shasum": "9c9456989e9f6588017b0434d56097675c3da05e",
|
||||
"_spec": "p-is-promise@^1.1.0",
|
||||
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/into-stream",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/p-is-promise/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Check if something is a promise",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"bluebird": "^3.4.6",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/p-is-promise#readme",
|
||||
"keywords": [
|
||||
"promise",
|
||||
"is",
|
||||
"detect",
|
||||
"check",
|
||||
"kind",
|
||||
"type",
|
||||
"thenable",
|
||||
"es2015",
|
||||
"async",
|
||||
"await",
|
||||
"promises",
|
||||
"bluebird"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "p-is-promise",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/p-is-promise.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "1.1.0",
|
||||
"xo": {
|
||||
"esnext": true
|
||||
}
|
||||
}
|
||||
43
node_modules/into-stream/node_modules/p-is-promise/readme.md
generated
vendored
Normal file
43
node_modules/into-stream/node_modules/p-is-promise/readme.md
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
# p-is-promise [](https://travis-ci.org/sindresorhus/p-is-promise)
|
||||
|
||||
> Check if something is a promise
|
||||
|
||||
Why not [`is-promise`](https://github.com/then/is-promise)? That module [checks for a thenable](https://github.com/then/is-promise/issues/6), not an ES2015 promise. This one is stricter.
|
||||
|
||||
You most likely don't need this. Just pass your value to `Promise.resolve()` and let it handle it.
|
||||
|
||||
Can be useful if you need to create a fast path for a synchronous operation.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save p-is-promise
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const pIsPromise = require('p-is-promise');
|
||||
const Bluebird = require('bluebird');
|
||||
|
||||
pIsPromise(Promise.resolve('🦄'));
|
||||
//=> true
|
||||
|
||||
pIsPromise(Bluebird.resolve('🦄'));
|
||||
//=> true
|
||||
|
||||
pIsPromise('🦄');
|
||||
//=> false
|
||||
```
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
84
node_modules/into-stream/package.json
generated
vendored
Normal file
84
node_modules/into-stream/package.json
generated
vendored
Normal file
@ -0,0 +1,84 @@
|
||||
{
|
||||
"_from": "into-stream@^3.1.0",
|
||||
"_id": "into-stream@3.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-lvsKk2wSur1v8XUqF9BWFqvQlMY=",
|
||||
"_location": "/into-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "into-stream@^3.1.0",
|
||||
"name": "into-stream",
|
||||
"escapedName": "into-stream",
|
||||
"rawSpec": "^3.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^3.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/bin-wrapper/got",
|
||||
"/gatsby-plugin-sharp/got",
|
||||
"/got"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/into-stream/-/into-stream-3.1.0.tgz",
|
||||
"_shasum": "96fb0a936c12babd6ff1752a17d05616abd094c6",
|
||||
"_spec": "into-stream@^3.1.0",
|
||||
"_where": "/Users/stefanfejes/Projects/30-seconds-of-python-code/node_modules/got",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/into-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"from2": "^2.1.1",
|
||||
"p-is-promise": "^1.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Convert a buffer/string/array/object/iterable/promise into a stream",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"get-stream": "^3.0.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/sindresorhus/into-stream#readme",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"buffer",
|
||||
"string",
|
||||
"object",
|
||||
"array",
|
||||
"iterable",
|
||||
"promise",
|
||||
"promises",
|
||||
"from",
|
||||
"into",
|
||||
"to",
|
||||
"transform",
|
||||
"convert",
|
||||
"readable",
|
||||
"pull",
|
||||
"gulpfriendly",
|
||||
"value",
|
||||
"str"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "into-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/into-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "3.1.0"
|
||||
}
|
||||
42
node_modules/into-stream/readme.md
generated
vendored
Normal file
42
node_modules/into-stream/readme.md
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
# into-stream [](https://travis-ci.org/sindresorhus/into-stream)
|
||||
|
||||
> Convert a buffer/string/array/object/iterable/promise into a stream
|
||||
|
||||
Correctly chunks up the input and handles backpressure.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save into-stream
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const intoStream = require('into-stream');
|
||||
|
||||
intoStream('unicorn').pipe(process.stdout);
|
||||
//=> 'unicorn'
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### intoStream(input)
|
||||
|
||||
Type: `Buffer` `string` `Iterable<Buffer|string>` `Promise`<br>
|
||||
Returns: [Readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable)
|
||||
|
||||
Adheres to the requested chunk size, except for `array` where each element will be a chunk.
|
||||
|
||||
### intoStream.obj(input)
|
||||
|
||||
Type: `Object`, `Iterable<Object>` `Promise`<br>
|
||||
Returns: [Readable object stream](https://nodejs.org/api/stream.html#stream_object_mode)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
Reference in New Issue
Block a user