mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 22:46:36 +01:00
Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Collapse whitespace to a single space.
|
||||
*
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export function collapseWhiteSpace(value: string): string;
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Collapse whitespace to a single space.
|
||||
*
|
||||
* @param {string} value
|
||||
* @returns {string}
|
||||
*/
|
||||
export function collapseWhiteSpace(value) {
|
||||
return String(value).replace(/\s+/g, ' ')
|
||||
}
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2015 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.
|
||||
Generated
Vendored
+8360
File diff suppressed because it is too large
Load Diff
Generated
Vendored
+109
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"_from": "collapse-white-space",
|
||||
"_id": "collapse-white-space@2.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-eh9krktAIMDL0KHuN7WTBJ/0PMv8KUvfQRBkIlGmW61idRM2DJjgd1qXEPr4wyk2PimZZeNww3RVYo6CMvDGlg==",
|
||||
"_location": "/collapse-white-space",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "collapse-white-space",
|
||||
"name": "collapse-white-space",
|
||||
"escapedName": "collapse-white-space",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/collapse-white-space/-/collapse-white-space-2.0.0.tgz",
|
||||
"_shasum": "37d8521344cdd36635db180a7c83e9d515ac281b",
|
||||
"_spec": "collapse-white-space",
|
||||
"_where": "/Users/kzantow/projects/syft/test/integration/test-fixtures/npm-lock",
|
||||
"author": {
|
||||
"name": "Titus Wormer",
|
||||
"email": "tituswormer@gmail.com",
|
||||
"url": "https://wooorm.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/wooorm/collapse-white-space/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Titus Wormer",
|
||||
"email": "tituswormer@gmail.com",
|
||||
"url": "https://wooorm.com"
|
||||
}
|
||||
],
|
||||
"deprecated": false,
|
||||
"description": "Replace multiple white space characters with a single space",
|
||||
"devDependencies": {
|
||||
"@types/tape": "^4.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^9.0.0",
|
||||
"remark-preset-wooorm": "^8.0.0",
|
||||
"rimraf": "^3.0.0",
|
||||
"tape": "^5.0.0",
|
||||
"typescript": "^4.0.0",
|
||||
"xo": "^0.38.0"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/wooorm"
|
||||
},
|
||||
"homepage": "https://github.com/wooorm/collapse-white-space#readme",
|
||||
"keywords": [
|
||||
"collapse",
|
||||
"white",
|
||||
"space"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "collapse-white-space",
|
||||
"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/collapse-white-space.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
|
||||
"prebuild": "rimraf \"*.d.ts\"",
|
||||
"prepublishOnly": "npm run build",
|
||||
"test": "npm run format && npm run build && npm run test-coverage",
|
||||
"test-api": "node test",
|
||||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"type": "module",
|
||||
"types": "index.d.ts",
|
||||
"version": "2.0.0",
|
||||
"xo": {
|
||||
"prettier": true,
|
||||
"rules": {
|
||||
"no-var": "off",
|
||||
"prefer-arrow-callback": "off"
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
# collapse-white-space
|
||||
|
||||
[![Build][build-badge]][build]
|
||||
[![Coverage][coverage-badge]][coverage]
|
||||
[![Downloads][downloads-badge]][downloads]
|
||||
[![Size][size-badge]][size]
|
||||
|
||||
Replace multiple whitespace characters with a single space.
|
||||
|
||||
## Install
|
||||
|
||||
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed
|
||||
instead of `require`d.
|
||||
|
||||
[npm][]:
|
||||
|
||||
```sh
|
||||
npm install collapse-white-space
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {collapseWhiteSpace} from 'collapse-white-space'
|
||||
|
||||
collapseWhiteSpace('\tfoo \n\tbar \t\r\nbaz') //=> ' foo bar baz'
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the following identifiers: `collapseWhiteSpace`.
|
||||
There is no default export.
|
||||
|
||||
### `collapseWhiteSpace(value)`
|
||||
|
||||
Replace multiple whitespace characters in `value` (`string`) with a single
|
||||
space.
|
||||
|
||||
## License
|
||||
|
||||
[MIT][license] © [Titus Wormer][author]
|
||||
|
||||
<!-- Definitions -->
|
||||
|
||||
[build-badge]: https://github.com/wooorm/collapse-white-space/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/wooorm/collapse-white-space/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/collapse-white-space.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/wooorm/collapse-white-space
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/collapse-white-space.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/collapse-white-space
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/collapse-white-space.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=collapse-white-space
|
||||
|
||||
[npm]: https://docs.npmjs.com/cli/install
|
||||
|
||||
[license]: license
|
||||
|
||||
[author]: https://wooorm.com
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
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.
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
# end-of-stream
|
||||
|
||||
A node module that calls a callback when a readable/writable/duplex stream has completed or failed.
|
||||
|
||||
npm install end-of-stream
|
||||
|
||||
[](https://travis-ci.org/mafintosh/end-of-stream)
|
||||
|
||||
## Usage
|
||||
|
||||
Simply pass a stream and a callback to the `eos`.
|
||||
Both legacy streams, streams2 and stream3 are supported.
|
||||
|
||||
``` js
|
||||
var eos = require('end-of-stream');
|
||||
|
||||
eos(readableStream, function(err) {
|
||||
// this will be set to the stream instance
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended', this === readableStream);
|
||||
});
|
||||
|
||||
eos(writableStream, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has finished', this === writableStream);
|
||||
});
|
||||
|
||||
eos(duplexStream, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended and finished', this === duplexStream);
|
||||
});
|
||||
|
||||
eos(duplexStream, {readable:false}, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has finished but might still be readable');
|
||||
});
|
||||
|
||||
eos(duplexStream, {writable:false}, function(err) {
|
||||
if (err) return console.log('stream had an error or closed early');
|
||||
console.log('stream has ended but might still be writable');
|
||||
});
|
||||
|
||||
eos(readableStream, {error:false}, function(err) {
|
||||
// do not treat emit('error', err) as a end-of-stream
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Related
|
||||
|
||||
`end-of-stream` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
var once = require('once');
|
||||
|
||||
var noop = function() {};
|
||||
|
||||
var isRequest = function(stream) {
|
||||
return stream.setHeader && typeof stream.abort === 'function';
|
||||
};
|
||||
|
||||
var isChildProcess = function(stream) {
|
||||
return stream.stdio && Array.isArray(stream.stdio) && stream.stdio.length === 3
|
||||
};
|
||||
|
||||
var eos = function(stream, opts, callback) {
|
||||
if (typeof opts === 'function') return eos(stream, null, opts);
|
||||
if (!opts) opts = {};
|
||||
|
||||
callback = once(callback || noop);
|
||||
|
||||
var ws = stream._writableState;
|
||||
var rs = stream._readableState;
|
||||
var readable = opts.readable || (opts.readable !== false && stream.readable);
|
||||
var writable = opts.writable || (opts.writable !== false && stream.writable);
|
||||
var cancelled = false;
|
||||
|
||||
var onlegacyfinish = function() {
|
||||
if (!stream.writable) onfinish();
|
||||
};
|
||||
|
||||
var onfinish = function() {
|
||||
writable = false;
|
||||
if (!readable) callback.call(stream);
|
||||
};
|
||||
|
||||
var onend = function() {
|
||||
readable = false;
|
||||
if (!writable) callback.call(stream);
|
||||
};
|
||||
|
||||
var onexit = function(exitCode) {
|
||||
callback.call(stream, exitCode ? new Error('exited with error code: ' + exitCode) : null);
|
||||
};
|
||||
|
||||
var onerror = function(err) {
|
||||
callback.call(stream, err);
|
||||
};
|
||||
|
||||
var onclose = function() {
|
||||
process.nextTick(onclosenexttick);
|
||||
};
|
||||
|
||||
var onclosenexttick = function() {
|
||||
if (cancelled) return;
|
||||
if (readable && !(rs && (rs.ended && !rs.destroyed))) return callback.call(stream, new Error('premature close'));
|
||||
if (writable && !(ws && (ws.ended && !ws.destroyed))) return callback.call(stream, new Error('premature close'));
|
||||
};
|
||||
|
||||
var onrequest = function() {
|
||||
stream.req.on('finish', onfinish);
|
||||
};
|
||||
|
||||
if (isRequest(stream)) {
|
||||
stream.on('complete', onfinish);
|
||||
stream.on('abort', onclose);
|
||||
if (stream.req) onrequest();
|
||||
else stream.on('request', onrequest);
|
||||
} else if (writable && !ws) { // legacy streams
|
||||
stream.on('end', onlegacyfinish);
|
||||
stream.on('close', onlegacyfinish);
|
||||
}
|
||||
|
||||
if (isChildProcess(stream)) stream.on('exit', onexit);
|
||||
|
||||
stream.on('end', onend);
|
||||
stream.on('finish', onfinish);
|
||||
if (opts.error !== false) stream.on('error', onerror);
|
||||
stream.on('close', onclose);
|
||||
|
||||
return function() {
|
||||
cancelled = true;
|
||||
stream.removeListener('complete', onfinish);
|
||||
stream.removeListener('abort', onclose);
|
||||
stream.removeListener('request', onrequest);
|
||||
if (stream.req) stream.req.removeListener('finish', onfinish);
|
||||
stream.removeListener('end', onlegacyfinish);
|
||||
stream.removeListener('close', onlegacyfinish);
|
||||
stream.removeListener('finish', onfinish);
|
||||
stream.removeListener('exit', onexit);
|
||||
stream.removeListener('end', onend);
|
||||
stream.removeListener('error', onerror);
|
||||
stream.removeListener('close', onclose);
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = eos;
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"_from": "end-of-stream@^1.1.0",
|
||||
"_id": "end-of-stream@1.4.4",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
|
||||
"_location": "/end-of-stream",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "end-of-stream@^1.1.0",
|
||||
"name": "end-of-stream",
|
||||
"escapedName": "end-of-stream",
|
||||
"rawSpec": "^1.1.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.1.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/pump"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
|
||||
"_shasum": "5ae64a5f45057baf3626ec14da0ca5e4b2431eb0",
|
||||
"_spec": "end-of-stream@^1.1.0",
|
||||
"_where": "/Users/kzantow/projects/syft/test/integration/test-fixtures/npm-lock/node_modules/pump",
|
||||
"author": {
|
||||
"name": "Mathias Buus",
|
||||
"email": "mathiasbuus@gmail.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/end-of-stream/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"once": "^1.4.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Call a callback when a readable/writable/duplex stream has completed or failed.",
|
||||
"devDependencies": {
|
||||
"tape": "^4.11.0"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"homepage": "https://github.com/mafintosh/end-of-stream",
|
||||
"keywords": [
|
||||
"stream",
|
||||
"streams",
|
||||
"callback",
|
||||
"finish",
|
||||
"close",
|
||||
"end",
|
||||
"wait"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "end-of-stream",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mafintosh/end-of-stream.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test.js"
|
||||
},
|
||||
"version": "1.4.4"
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
This software is released under the MIT license:
|
||||
|
||||
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.
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
var on = require('dom-event');
|
||||
var insertCss = require('./');
|
||||
|
||||
document.querySelector('body').innerHTML = '<h1>insert-css example</h1><button id="blue">blue</button><button id="red">red</button>';
|
||||
|
||||
on(document.querySelector('#blue'), 'click', function() {
|
||||
insertCss('body{background: blue}');
|
||||
});
|
||||
|
||||
on(document.querySelector('#red'), 'click', function() {
|
||||
insertCss('body{background: red}');
|
||||
});
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
var containers = []; // will store container HTMLElement references
|
||||
var styleElements = []; // will store {prepend: HTMLElement, append: HTMLElement}
|
||||
|
||||
var usage = 'insert-css: You need to provide a CSS string. Usage: insertCss(cssString[, options]).';
|
||||
|
||||
function insertCss(css, options) {
|
||||
options = options || {};
|
||||
|
||||
if (css === undefined) {
|
||||
throw new Error(usage);
|
||||
}
|
||||
|
||||
var position = options.prepend === true ? 'prepend' : 'append';
|
||||
var container = options.container !== undefined ? options.container : document.querySelector('head');
|
||||
var containerId = containers.indexOf(container);
|
||||
|
||||
// first time we see this container, create the necessary entries
|
||||
if (containerId === -1) {
|
||||
containerId = containers.push(container) - 1;
|
||||
styleElements[containerId] = {};
|
||||
}
|
||||
|
||||
// try to get the correponding container + position styleElement, create it otherwise
|
||||
var styleElement;
|
||||
|
||||
if (styleElements[containerId] !== undefined && styleElements[containerId][position] !== undefined) {
|
||||
styleElement = styleElements[containerId][position];
|
||||
} else {
|
||||
styleElement = styleElements[containerId][position] = createStyleElement();
|
||||
|
||||
if (position === 'prepend') {
|
||||
container.insertBefore(styleElement, container.childNodes[0]);
|
||||
} else {
|
||||
container.appendChild(styleElement);
|
||||
}
|
||||
}
|
||||
|
||||
// strip potential UTF-8 BOM if css was read from a file
|
||||
if (css.charCodeAt(0) === 0xFEFF) { css = css.substr(1, css.length); }
|
||||
|
||||
// actually add the stylesheet
|
||||
if (styleElement.styleSheet) {
|
||||
styleElement.styleSheet.cssText += css
|
||||
} else {
|
||||
styleElement.textContent += css;
|
||||
}
|
||||
|
||||
return styleElement;
|
||||
};
|
||||
|
||||
function createStyleElement() {
|
||||
var styleElement = document.createElement('style');
|
||||
styleElement.setAttribute('type', 'text/css');
|
||||
return styleElement;
|
||||
}
|
||||
|
||||
module.exports = insertCss;
|
||||
module.exports.insertCss = insertCss;
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"_from": "insert-css",
|
||||
"_id": "insert-css@2.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-610Ql7dUL0x56jBg067gfQU4gPQ=",
|
||||
"_location": "/insert-css",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "insert-css",
|
||||
"name": "insert-css",
|
||||
"escapedName": "insert-css",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#USER",
|
||||
"/"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/insert-css/-/insert-css-2.0.0.tgz",
|
||||
"_shasum": "eb5d1097b7542f4c79ea3060d3aee07d053880f4",
|
||||
"_spec": "insert-css",
|
||||
"_where": "/Users/kzantow/projects/syft/test/integration/test-fixtures/npm-lock",
|
||||
"author": {
|
||||
"name": "James Halliday",
|
||||
"email": "mail@substack.net",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/insert-css/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "insert a string of css into the <head>",
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.1",
|
||||
"budo": "^8.3.0",
|
||||
"computed-style": "^0.3.0",
|
||||
"dom-event": "^1.0.0",
|
||||
"tape": "^4.6.0",
|
||||
"tape-run": "^2.1.4"
|
||||
},
|
||||
"homepage": "https://github.com/substack/insert-css",
|
||||
"keywords": [
|
||||
"css",
|
||||
"insert",
|
||||
"dom",
|
||||
"browser",
|
||||
"browserify",
|
||||
"inject",
|
||||
"styles",
|
||||
"stylesheet",
|
||||
"style",
|
||||
"html",
|
||||
"head",
|
||||
"link"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"name": "insert-css",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/substack/insert-css.git"
|
||||
},
|
||||
"scripts": {
|
||||
"example": "budo example.js",
|
||||
"test": "browserify test.js | tape-run"
|
||||
},
|
||||
"testling": {
|
||||
"files": "test.js",
|
||||
"browsers": [
|
||||
"ie/6..latest",
|
||||
"chrome/20..latest",
|
||||
"firefox/10..latest",
|
||||
"safari/latest",
|
||||
"opera/11.0..latest",
|
||||
"iphone/6",
|
||||
"ipad/6"
|
||||
]
|
||||
},
|
||||
"version": "2.0.0"
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
# insert-css
|
||||
|
||||
insert a string of css into the `<head>`
|
||||
|
||||
[](https://ci.testling.com/substack/insert-css)
|
||||
|
||||
# example
|
||||
|
||||
``` js
|
||||
var insertCss = require('insert-css');
|
||||
var styleElement = insertCss('body { background:blue; }');
|
||||
```
|
||||
|
||||
# api
|
||||
|
||||
``` js
|
||||
var insertCss = require('insert-css');
|
||||
```
|
||||
|
||||
## var styleElement = insertCss(css, opts);
|
||||
|
||||
Insert some CSS into the page.
|
||||
|
||||
* `opts.container` - Which HTMLElement to use as the base mounting point, defaults to
|
||||
`document.querySelector('head')`.
|
||||
|
||||
* `opts.prepend` - Add the CSS at the top level of the container instead of at the bottom level (default).
|
||||
|
||||
This is particullary useful for library creators where you may want your default CSS to be prepended so it
|
||||
can be easily overriden by user styles.
|
||||
|
||||
# development
|
||||
|
||||
## example
|
||||
|
||||
``` sh
|
||||
npm run example
|
||||
```
|
||||
|
||||
## test
|
||||
|
||||
``` sh
|
||||
npm test
|
||||
```
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
var test = require('tape');
|
||||
|
||||
test(function (t) {
|
||||
var insertCss = require('./');
|
||||
var initialNbStyleTags = nbStyleTags();
|
||||
|
||||
// basic usage
|
||||
var baseStyle = 'body{position:relative;text-decoration:overline}';
|
||||
insertCss(baseStyle);
|
||||
t.equal(position(), 'relative', 'initial position is `relative`');
|
||||
|
||||
// adds one style tag
|
||||
t.equal(nbStyleTags(), initialNbStyleTags + 1, 'we added one style tag');
|
||||
|
||||
// default to appending style
|
||||
var appendStyle = 'body{position:absolute}';
|
||||
var appendStyleTag = insertCss(appendStyle);
|
||||
t.equal(position(), 'absolute', 'new position is `absolute`');
|
||||
|
||||
// reuse same style tag
|
||||
t.equal(nbStyleTags(), initialNbStyleTags + 1, 'we kept using the same style tag');
|
||||
|
||||
// prepend should add a new style tag before the append one
|
||||
t.equal(textDecoration(), 'overline', 'text-decoration is overline by default');
|
||||
var prependStyleTag = insertCss('body{text-decoration:underline !important}', {prepend: true});
|
||||
t.equal(nbStyleTags(), initialNbStyleTags + 2, 'we added a new style tag');
|
||||
t.equal(textDecoration(), 'underline', 'text-decoration is now underline');
|
||||
var tag = prependStyleTag;
|
||||
while (tag !== appendStyleTag) {
|
||||
tag = tag.nextSibling;
|
||||
}
|
||||
t.equal(tag, appendStyleTag, 'prepend mode should add a style tag before the append one');
|
||||
|
||||
// uses old school styleSheet prop when present (IE)
|
||||
if (!appendStyleTag.styleSheet) {
|
||||
appendStyleTag.styleSheet = {cssText: 'a'};
|
||||
insertCss('p{color:blue}');
|
||||
t.equal(appendStyleTag.styleSheet.cssText, 'ap{color:blue}', 'we use old school styleSheet prop');
|
||||
delete appendStyleTag.styleSheet;
|
||||
}
|
||||
|
||||
// allow re-adding added style
|
||||
insertCss(baseStyle);
|
||||
t.equal(position(), 'relative', 'position is again `relative`');
|
||||
|
||||
// allow using a custom container
|
||||
var customContainer = document.createElement('div');
|
||||
document.querySelector('body').appendChild(customContainer);
|
||||
t.equal(nbStyleTags(customContainer), 0, 'no style tag in custom container');
|
||||
insertCss('body{position:absolute}', {container: customContainer});
|
||||
t.equal(nbStyleTags(customContainer), 1, 'new style tag added in custom container');
|
||||
t.equal(position(), 'absolute', 'position is absolute again');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test(function testEmpty(t) {
|
||||
var insertCss = require('./');
|
||||
|
||||
t.equal(insertCss(), false, 'insertCss() with no arguments returns `false`');
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
function position() {
|
||||
var getStyle = require('computed-style');
|
||||
return getStyle(document.querySelector('body'), 'position');
|
||||
}
|
||||
|
||||
function textDecoration() {
|
||||
var getStyle = require('computed-style');
|
||||
return getStyle(document.querySelector('body'), 'text-decoration');
|
||||
}
|
||||
|
||||
function nbStyleTags(container) {
|
||||
if (!container) container = document;
|
||||
return container.querySelectorAll('style').length
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
# once
|
||||
|
||||
Only call a function once.
|
||||
|
||||
## usage
|
||||
|
||||
```javascript
|
||||
var once = require('once')
|
||||
|
||||
function load (file, cb) {
|
||||
cb = once(cb)
|
||||
loader.load('file')
|
||||
loader.once('load', cb)
|
||||
loader.once('error', cb)
|
||||
}
|
||||
```
|
||||
|
||||
Or add to the Function.prototype in a responsible way:
|
||||
|
||||
```javascript
|
||||
// only has to be done once
|
||||
require('once').proto()
|
||||
|
||||
function load (file, cb) {
|
||||
cb = cb.once()
|
||||
loader.load('file')
|
||||
loader.once('load', cb)
|
||||
loader.once('error', cb)
|
||||
}
|
||||
```
|
||||
|
||||
Ironically, the prototype feature makes this module twice as
|
||||
complicated as necessary.
|
||||
|
||||
To check whether you function has been called, use `fn.called`. Once the
|
||||
function is called for the first time the return value of the original
|
||||
function is saved in `fn.value` and subsequent calls will continue to
|
||||
return this value.
|
||||
|
||||
```javascript
|
||||
var once = require('once')
|
||||
|
||||
function load (cb) {
|
||||
cb = once(cb)
|
||||
var stream = createStream()
|
||||
stream.once('data', cb)
|
||||
stream.once('end', function () {
|
||||
if (!cb.called) cb(new Error('not found'))
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## `once.strict(func)`
|
||||
|
||||
Throw an error if the function is called twice.
|
||||
|
||||
Some functions are expected to be called only once. Using `once` for them would
|
||||
potentially hide logical errors.
|
||||
|
||||
In the example below, the `greet` function has to call the callback only once:
|
||||
|
||||
```javascript
|
||||
function greet (name, cb) {
|
||||
// return is missing from the if statement
|
||||
// when no name is passed, the callback is called twice
|
||||
if (!name) cb('Hello anonymous')
|
||||
cb('Hello ' + name)
|
||||
}
|
||||
|
||||
function log (msg) {
|
||||
console.log(msg)
|
||||
}
|
||||
|
||||
// this will print 'Hello anonymous' but the logical error will be missed
|
||||
greet(null, once(msg))
|
||||
|
||||
// once.strict will print 'Hello anonymous' and throw an error when the callback will be called the second time
|
||||
greet(null, once.strict(msg))
|
||||
```
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
var wrappy = require('wrappy')
|
||||
module.exports = wrappy(once)
|
||||
module.exports.strict = wrappy(onceStrict)
|
||||
|
||||
once.proto = once(function () {
|
||||
Object.defineProperty(Function.prototype, 'once', {
|
||||
value: function () {
|
||||
return once(this)
|
||||
},
|
||||
configurable: true
|
||||
})
|
||||
|
||||
Object.defineProperty(Function.prototype, 'onceStrict', {
|
||||
value: function () {
|
||||
return onceStrict(this)
|
||||
},
|
||||
configurable: true
|
||||
})
|
||||
})
|
||||
|
||||
function once (fn) {
|
||||
var f = function () {
|
||||
if (f.called) return f.value
|
||||
f.called = true
|
||||
return f.value = fn.apply(this, arguments)
|
||||
}
|
||||
f.called = false
|
||||
return f
|
||||
}
|
||||
|
||||
function onceStrict (fn) {
|
||||
var f = function () {
|
||||
if (f.called)
|
||||
throw new Error(f.onceError)
|
||||
f.called = true
|
||||
return f.value = fn.apply(this, arguments)
|
||||
}
|
||||
var name = fn.name || 'Function wrapped with `once`'
|
||||
f.onceError = name + " shouldn't be called more than once"
|
||||
f.called = false
|
||||
return f
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"_from": "once@^1.3.1",
|
||||
"_id": "once@1.4.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"_location": "/once",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "once@^1.3.1",
|
||||
"name": "once",
|
||||
"escapedName": "once",
|
||||
"rawSpec": "^1.3.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.3.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/end-of-stream",
|
||||
"/pump"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"_shasum": "583b1aa775961d4b113ac17d9c50baef9dd76bd1",
|
||||
"_spec": "once@^1.3.1",
|
||||
"_where": "/Users/kzantow/projects/syft/test/integration/test-fixtures/npm-lock/node_modules/pump",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/isaacs/once/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"wrappy": "1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Run a function exactly one time",
|
||||
"devDependencies": {
|
||||
"tap": "^7.0.1"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"once.js"
|
||||
],
|
||||
"homepage": "https://github.com/isaacs/once#readme",
|
||||
"keywords": [
|
||||
"once",
|
||||
"function",
|
||||
"one",
|
||||
"single"
|
||||
],
|
||||
"license": "ISC",
|
||||
"main": "once.js",
|
||||
"name": "once",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/isaacs/once.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"version": "1.4.0"
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.10"
|
||||
|
||||
script: "npm test"
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Mathias Buus
|
||||
|
||||
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.
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
# pump
|
||||
|
||||
pump is a small node module that pipes streams together and destroys all of them if one of them closes.
|
||||
|
||||
```
|
||||
npm install pump
|
||||
```
|
||||
|
||||
[](http://travis-ci.org/mafintosh/pump)
|
||||
|
||||
## What problem does it solve?
|
||||
|
||||
When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error.
|
||||
You are also not able to provide a callback to tell when then pipe has finished.
|
||||
|
||||
pump does these two things for you
|
||||
|
||||
## Usage
|
||||
|
||||
Simply pass the streams you want to pipe together to pump and add an optional callback
|
||||
|
||||
``` js
|
||||
var pump = require('pump')
|
||||
var fs = require('fs')
|
||||
|
||||
var source = fs.createReadStream('/dev/random')
|
||||
var dest = fs.createWriteStream('/dev/null')
|
||||
|
||||
pump(source, dest, function(err) {
|
||||
console.log('pipe finished', err)
|
||||
})
|
||||
|
||||
setTimeout(function() {
|
||||
dest.destroy() // when dest is closed pump will destroy source
|
||||
}, 1000)
|
||||
```
|
||||
|
||||
You can use pump to pipe more than two streams together as well
|
||||
|
||||
``` js
|
||||
var transform = someTransformStream()
|
||||
|
||||
pump(source, transform, anotherTransform, dest, function(err) {
|
||||
console.log('pipe finished', err)
|
||||
})
|
||||
```
|
||||
|
||||
If `source`, `transform`, `anotherTransform` or `dest` closes all of them will be destroyed.
|
||||
|
||||
Similarly to `stream.pipe()`, `pump()` returns the last stream passed in, so you can do:
|
||||
|
||||
```
|
||||
return pump(s1, s2) // returns s2
|
||||
```
|
||||
|
||||
If you want to return a stream that combines *both* s1 and s2 to a single stream use
|
||||
[pumpify](https://github.com/mafintosh/pumpify) instead.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Related
|
||||
|
||||
`pump` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
var once = require('once')
|
||||
var eos = require('end-of-stream')
|
||||
var fs = require('fs') // we only need fs to get the ReadStream and WriteStream prototypes
|
||||
|
||||
var noop = function () {}
|
||||
var ancient = /^v?\.0/.test(process.version)
|
||||
|
||||
var isFn = function (fn) {
|
||||
return typeof fn === 'function'
|
||||
}
|
||||
|
||||
var isFS = function (stream) {
|
||||
if (!ancient) return false // newer node version do not need to care about fs is a special way
|
||||
if (!fs) return false // browser
|
||||
return (stream instanceof (fs.ReadStream || noop) || stream instanceof (fs.WriteStream || noop)) && isFn(stream.close)
|
||||
}
|
||||
|
||||
var isRequest = function (stream) {
|
||||
return stream.setHeader && isFn(stream.abort)
|
||||
}
|
||||
|
||||
var destroyer = function (stream, reading, writing, callback) {
|
||||
callback = once(callback)
|
||||
|
||||
var closed = false
|
||||
stream.on('close', function () {
|
||||
closed = true
|
||||
})
|
||||
|
||||
eos(stream, {readable: reading, writable: writing}, function (err) {
|
||||
if (err) return callback(err)
|
||||
closed = true
|
||||
callback()
|
||||
})
|
||||
|
||||
var destroyed = false
|
||||
return function (err) {
|
||||
if (closed) return
|
||||
if (destroyed) return
|
||||
destroyed = true
|
||||
|
||||
if (isFS(stream)) return stream.close(noop) // use close for fs streams to avoid fd leaks
|
||||
if (isRequest(stream)) return stream.abort() // request.destroy just do .end - .abort is what we want
|
||||
|
||||
if (isFn(stream.destroy)) return stream.destroy()
|
||||
|
||||
callback(err || new Error('stream was destroyed'))
|
||||
}
|
||||
}
|
||||
|
||||
var call = function (fn) {
|
||||
fn()
|
||||
}
|
||||
|
||||
var pipe = function (from, to) {
|
||||
return from.pipe(to)
|
||||
}
|
||||
|
||||
var pump = function () {
|
||||
var streams = Array.prototype.slice.call(arguments)
|
||||
var callback = isFn(streams[streams.length - 1] || noop) && streams.pop() || noop
|
||||
|
||||
if (Array.isArray(streams[0])) streams = streams[0]
|
||||
if (streams.length < 2) throw new Error('pump requires two streams per minimum')
|
||||
|
||||
var error
|
||||
var destroys = streams.map(function (stream, i) {
|
||||
var reading = i < streams.length - 1
|
||||
var writing = i > 0
|
||||
return destroyer(stream, reading, writing, function (err) {
|
||||
if (!error) error = err
|
||||
if (err) destroys.forEach(call)
|
||||
if (reading) return
|
||||
destroys.forEach(call)
|
||||
callback(error)
|
||||
})
|
||||
})
|
||||
|
||||
return streams.reduce(pipe)
|
||||
}
|
||||
|
||||
module.exports = pump
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"_from": "pump",
|
||||
"_id": "pump@3.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
|
||||
"_location": "/pump",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "tag",
|
||||
"registry": true,
|
||||
"raw": "pump",
|
||||
"name": "pump",
|
||||
"escapedName": "pump",
|
||||
"rawSpec": "",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "latest"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"#DEV:/",
|
||||
"#USER"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||
"_shasum": "b4a2116815bde2f4e1ea602354e8c75565107a64",
|
||||
"_spec": "pump",
|
||||
"_where": "/Users/kzantow/projects/syft/test/integration/test-fixtures/npm-lock",
|
||||
"author": {
|
||||
"name": "Mathias Buus Madsen",
|
||||
"email": "mathiasbuus@gmail.com"
|
||||
},
|
||||
"browser": {
|
||||
"fs": false
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/pump/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"end-of-stream": "^1.1.0",
|
||||
"once": "^1.3.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "pipe streams together and close all of them if one of them closes",
|
||||
"homepage": "https://github.com/mafintosh/pump#readme",
|
||||
"keywords": [
|
||||
"streams",
|
||||
"pipe",
|
||||
"destroy",
|
||||
"callback"
|
||||
],
|
||||
"license": "MIT",
|
||||
"name": "pump",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/mafintosh/pump.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test-browser.js && node test-node.js"
|
||||
},
|
||||
"version": "3.0.0"
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
var stream = require('stream')
|
||||
var pump = require('./index')
|
||||
|
||||
var rs = new stream.Readable()
|
||||
var ws = new stream.Writable()
|
||||
|
||||
rs._read = function (size) {
|
||||
this.push(Buffer(size).fill('abc'))
|
||||
}
|
||||
|
||||
ws._write = function (chunk, encoding, cb) {
|
||||
setTimeout(function () {
|
||||
cb()
|
||||
}, 100)
|
||||
}
|
||||
|
||||
var toHex = function () {
|
||||
var reverse = new (require('stream').Transform)()
|
||||
|
||||
reverse._transform = function (chunk, enc, callback) {
|
||||
reverse.push(chunk.toString('hex'))
|
||||
callback()
|
||||
}
|
||||
|
||||
return reverse
|
||||
}
|
||||
|
||||
var wsClosed = false
|
||||
var rsClosed = false
|
||||
var callbackCalled = false
|
||||
|
||||
var check = function () {
|
||||
if (wsClosed && rsClosed && callbackCalled) {
|
||||
console.log('test-browser.js passes')
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}
|
||||
|
||||
ws.on('finish', function () {
|
||||
wsClosed = true
|
||||
check()
|
||||
})
|
||||
|
||||
rs.on('end', function () {
|
||||
rsClosed = true
|
||||
check()
|
||||
})
|
||||
|
||||
var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {
|
||||
callbackCalled = true
|
||||
check()
|
||||
})
|
||||
|
||||
if (res !== ws) {
|
||||
throw new Error('should return last stream')
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
rs.push(null)
|
||||
rs.emit('close')
|
||||
}, 1000)
|
||||
|
||||
var timeout = setTimeout(function () {
|
||||
check()
|
||||
throw new Error('timeout')
|
||||
}, 5000)
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
var pump = require('./index')
|
||||
|
||||
var rs = require('fs').createReadStream('/dev/random')
|
||||
var ws = require('fs').createWriteStream('/dev/null')
|
||||
|
||||
var toHex = function () {
|
||||
var reverse = new (require('stream').Transform)()
|
||||
|
||||
reverse._transform = function (chunk, enc, callback) {
|
||||
reverse.push(chunk.toString('hex'))
|
||||
callback()
|
||||
}
|
||||
|
||||
return reverse
|
||||
}
|
||||
|
||||
var wsClosed = false
|
||||
var rsClosed = false
|
||||
var callbackCalled = false
|
||||
|
||||
var check = function () {
|
||||
if (wsClosed && rsClosed && callbackCalled) {
|
||||
console.log('test-node.js passes')
|
||||
clearTimeout(timeout)
|
||||
}
|
||||
}
|
||||
|
||||
ws.on('close', function () {
|
||||
wsClosed = true
|
||||
check()
|
||||
})
|
||||
|
||||
rs.on('close', function () {
|
||||
rsClosed = true
|
||||
check()
|
||||
})
|
||||
|
||||
var res = pump(rs, toHex(), toHex(), toHex(), ws, function () {
|
||||
callbackCalled = true
|
||||
check()
|
||||
})
|
||||
|
||||
if (res !== ws) {
|
||||
throw new Error('should return last stream')
|
||||
}
|
||||
|
||||
setTimeout(function () {
|
||||
rs.destroy()
|
||||
}, 1000)
|
||||
|
||||
var timeout = setTimeout(function () {
|
||||
throw new Error('timeout')
|
||||
}, 5000)
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
The ISC License
|
||||
|
||||
Copyright (c) Isaac Z. Schlueter and Contributors
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
||||
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
# wrappy
|
||||
|
||||
Callback wrapping utility
|
||||
|
||||
## USAGE
|
||||
|
||||
```javascript
|
||||
var wrappy = require("wrappy")
|
||||
|
||||
// var wrapper = wrappy(wrapperFunction)
|
||||
|
||||
// make sure a cb is called only once
|
||||
// See also: http://npm.im/once for this specific use case
|
||||
var once = wrappy(function (cb) {
|
||||
var called = false
|
||||
return function () {
|
||||
if (called) return
|
||||
called = true
|
||||
return cb.apply(this, arguments)
|
||||
}
|
||||
})
|
||||
|
||||
function printBoo () {
|
||||
console.log('boo')
|
||||
}
|
||||
// has some rando property
|
||||
printBoo.iAmBooPrinter = true
|
||||
|
||||
var onlyPrintOnce = once(printBoo)
|
||||
|
||||
onlyPrintOnce() // prints 'boo'
|
||||
onlyPrintOnce() // does nothing
|
||||
|
||||
// random property is retained!
|
||||
assert.equal(onlyPrintOnce.iAmBooPrinter, true)
|
||||
```
|
||||
+1859
File diff suppressed because it is too large
Load Diff
+58
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"_from": "wrappy@1",
|
||||
"_id": "wrappy@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"_location": "/wrappy",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "wrappy@1",
|
||||
"name": "wrappy",
|
||||
"escapedName": "wrappy",
|
||||
"rawSpec": "1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/once"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"_shasum": "b5243d8f3ec1aa35f1364605bc0d1036e30ab69f",
|
||||
"_spec": "wrappy@1",
|
||||
"_where": "/Users/kzantow/projects/syft/test/integration/test-fixtures/npm-lock/node_modules/once",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
"url": "http://blog.izs.me/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/npm/wrappy/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {},
|
||||
"deprecated": false,
|
||||
"description": "Callback wrapping utility",
|
||||
"devDependencies": {
|
||||
"tap": "^2.3.1"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"files": [
|
||||
"wrappy.js"
|
||||
],
|
||||
"homepage": "https://github.com/npm/wrappy",
|
||||
"license": "ISC",
|
||||
"main": "wrappy.js",
|
||||
"name": "wrappy",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/npm/wrappy.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap --coverage test/*.js"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// Returns a wrapper function that returns a wrapped callback
|
||||
// The wrapper function should do some stuff, and return a
|
||||
// presumably different callback function.
|
||||
// This makes sure that own properties are retained, so that
|
||||
// decorations and such are not lost along the way.
|
||||
module.exports = wrappy
|
||||
function wrappy (fn, cb) {
|
||||
if (fn && cb) return wrappy(fn)(cb)
|
||||
|
||||
if (typeof fn !== 'function')
|
||||
throw new TypeError('need wrapper function')
|
||||
|
||||
Object.keys(fn).forEach(function (k) {
|
||||
wrapper[k] = fn[k]
|
||||
})
|
||||
|
||||
return wrapper
|
||||
|
||||
function wrapper() {
|
||||
var args = new Array(arguments.length)
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i] = arguments[i]
|
||||
}
|
||||
var ret = fn.apply(this, args)
|
||||
var cb = args[args.length-1]
|
||||
if (typeof ret === 'function' && ret !== cb) {
|
||||
Object.keys(cb).forEach(function (k) {
|
||||
ret[k] = cb[k]
|
||||
})
|
||||
}
|
||||
return ret
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user