plugins 0.4.2 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -230
- package/dist/index.js +946 -0
- package/package.json +11 -40
- package/LICENSE +0 -24
- package/index.js +0 -119
- package/iterators.js +0 -102
package/package.json
CHANGED
|
@@ -1,49 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plugins",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"bugs": {
|
|
9
|
-
"url": "https://github.com/jonschlinkert/plugins/issues"
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Install open-plugin format plugins into agent tools",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"plugins": "dist/index.js"
|
|
10
8
|
},
|
|
11
|
-
"license": "MIT",
|
|
12
9
|
"files": [
|
|
13
|
-
"
|
|
14
|
-
"iterators.js"
|
|
10
|
+
"dist"
|
|
15
11
|
],
|
|
16
|
-
"main": "index.js",
|
|
17
|
-
"engines": {
|
|
18
|
-
"node": ">=0.10.0"
|
|
19
|
-
},
|
|
20
12
|
"scripts": {
|
|
21
|
-
"
|
|
13
|
+
"build": "tsup",
|
|
14
|
+
"start": "node dist/index.js"
|
|
22
15
|
},
|
|
23
16
|
"devDependencies": {
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"should": "^7.0.4"
|
|
27
|
-
},
|
|
28
|
-
"dependencies": {
|
|
29
|
-
"async-array-reduce": "^0.1.0",
|
|
30
|
-
"event-stream": "^3.3.1"
|
|
31
|
-
},
|
|
32
|
-
"keywords": [
|
|
33
|
-
"extension",
|
|
34
|
-
"extensions",
|
|
35
|
-
"helper",
|
|
36
|
-
"helpers",
|
|
37
|
-
"middleware",
|
|
38
|
-
"use",
|
|
39
|
-
"plugin",
|
|
40
|
-
"fn",
|
|
41
|
-
"fns",
|
|
42
|
-
"plugins"
|
|
43
|
-
],
|
|
44
|
-
"verb": {
|
|
45
|
-
"related": {
|
|
46
|
-
"list": "async-array-reduce"
|
|
47
|
-
}
|
|
17
|
+
"tsup": "^8",
|
|
18
|
+
"typescript": "^5"
|
|
48
19
|
}
|
|
49
|
-
}
|
|
20
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2014, 2015 Jon Schlinkert.
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person
|
|
6
|
-
obtaining a copy of this software and associated documentation
|
|
7
|
-
files (the "Software"), to deal in the Software without
|
|
8
|
-
restriction, including without limitation the rights to use,
|
|
9
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
copies of the Software, and to permit persons to whom the
|
|
11
|
-
Software is furnished to do so, subject to the following
|
|
12
|
-
conditions:
|
|
13
|
-
|
|
14
|
-
The above copyright notice and this permission notice shall be
|
|
15
|
-
included in all copies or substantial portions of the Software.
|
|
16
|
-
|
|
17
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
19
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
20
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
21
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
22
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
23
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
24
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
package/index.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* plugins <https://github.com/jonschlinkert/plugins>
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2014 Jon Schlinkert, contributors.
|
|
5
|
-
* Licensed under the MIT License
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
var iterators = require('./iterators');
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Initialize `Plugins`
|
|
14
|
-
*
|
|
15
|
-
* ```js
|
|
16
|
-
* var Plugins = require('plugins');
|
|
17
|
-
* var plugins = new Plugins();
|
|
18
|
-
* ```
|
|
19
|
-
* @constructor
|
|
20
|
-
* @api public
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
function Plugins(options) {
|
|
24
|
-
if (!(this instanceof Plugins)) {
|
|
25
|
-
return new Plugins(options);
|
|
26
|
-
}
|
|
27
|
-
this.iterators = {};
|
|
28
|
-
this.fns = [];
|
|
29
|
-
this.init();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Register default iterators
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
Plugins.prototype.init = function() {
|
|
37
|
-
this.iterator('async', iterators.async.bind(this));
|
|
38
|
-
this.iterator('stream', iterators.stream.bind(this));
|
|
39
|
-
this.iterator('sync', iterators.sync.bind(this));
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Add a plugin `fn` to the `plugins` stack.
|
|
44
|
-
*
|
|
45
|
-
* ```js
|
|
46
|
-
* plugins
|
|
47
|
-
* .use(foo)
|
|
48
|
-
* .use(bar)
|
|
49
|
-
* .use(baz)
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @param {Function} `fn` Plugin function to add to the `plugins` stack.
|
|
53
|
-
* @return {Object} `Plugins` to enable chaining.
|
|
54
|
-
* @api public
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
Plugins.prototype.use = function (fn) {
|
|
58
|
-
this.fns.push(fn);
|
|
59
|
-
return this;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Call each `fn` in the `plugins` stack
|
|
64
|
-
* to iterate over `val`.
|
|
65
|
-
*
|
|
66
|
-
* ```js
|
|
67
|
-
* plugins.run(value)
|
|
68
|
-
* ```
|
|
69
|
-
* @param {Array|Object|String} `val` The value to iterate over.
|
|
70
|
-
* @api public
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
Plugins.prototype.run = function () {
|
|
74
|
-
var last = arguments[arguments.length - 1];
|
|
75
|
-
var type = isFunction(last) ? 'async' : 'sync';
|
|
76
|
-
return this.iterators[type].apply(this, arguments);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Register an iterator `fn` by its `type`.
|
|
81
|
-
*
|
|
82
|
-
* @param {String} `type` The iterator type.
|
|
83
|
-
* @param {Function} `fn` Iterator function
|
|
84
|
-
* @api public
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
Plugins.prototype.iterator = function(type, fn) {
|
|
88
|
-
this.iterators[type] = fn;
|
|
89
|
-
return this;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Add each plugin to a pipeline to be used with streams.
|
|
94
|
-
* Plugins must either be a stream or a function that returns a stream.
|
|
95
|
-
*
|
|
96
|
-
* ```js
|
|
97
|
-
* var pipeline = plugins.pipeline(plugin());
|
|
98
|
-
* ```
|
|
99
|
-
* @param {Array|Object|String} `val` The value to iterate over.
|
|
100
|
-
* @api public
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
Plugins.prototype.pipeline = function() {
|
|
104
|
-
return this.iterators.stream.apply(this, arguments);
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Utilities
|
|
109
|
-
*/
|
|
110
|
-
|
|
111
|
-
function isFunction(val) {
|
|
112
|
-
return typeof val === 'function';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Expose `Plugins`
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
module.exports = Plugins;
|
package/iterators.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
var reduce = require('async-array-reduce');
|
|
2
|
-
var es = require('event-stream');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Expose `iterators`
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
var iterators = module.exports;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Async iterator
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
iterators.async = function asyncIterator(val) {
|
|
15
|
-
var args = [].slice.call(arguments);
|
|
16
|
-
var fns = this.fns;
|
|
17
|
-
var cb = args.pop();
|
|
18
|
-
|
|
19
|
-
// if the second arg is an array,
|
|
20
|
-
// assume it's a plugin array
|
|
21
|
-
if (Array.isArray(args[1])) {
|
|
22
|
-
fns = fns.concat(args.pop());
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var isArray = Array.isArray(args[0]);
|
|
26
|
-
var self = this, i = 0;
|
|
27
|
-
|
|
28
|
-
return reduce(fns, args, function (acc, fn, next) {
|
|
29
|
-
acc = arrayify(acc);
|
|
30
|
-
if (isArray && i > 0) acc = [acc];
|
|
31
|
-
i++;
|
|
32
|
-
fn.apply(self, acc.concat(next));
|
|
33
|
-
}.bind(this), cb);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Sync iterator
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
iterators.sync = function syncIterator() {
|
|
41
|
-
var args = [].slice.call(arguments);
|
|
42
|
-
var fns = this.fns;
|
|
43
|
-
|
|
44
|
-
if (Array.isArray(args[1])) {
|
|
45
|
-
fns = fns.concat(args.pop());
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return fns.reduce(function (acc, fn) {
|
|
49
|
-
return fn.apply(this, arrayify(acc));
|
|
50
|
-
}, args);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Stream iterator
|
|
55
|
-
* TODO: this needs to be updated to work like an iterator.
|
|
56
|
-
* currently it works like a plugin itself.
|
|
57
|
-
*/
|
|
58
|
-
|
|
59
|
-
iterators.stream = function streamIterator() {
|
|
60
|
-
var args = [].slice.call(arguments);
|
|
61
|
-
var fns = this.fns;
|
|
62
|
-
|
|
63
|
-
if (Array.isArray(args[0])) {
|
|
64
|
-
fns = fns.concat(args.unshift());
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var len = fns.length, i = -1;
|
|
68
|
-
var pipeline = [];
|
|
69
|
-
|
|
70
|
-
while (++i < len) {
|
|
71
|
-
var fn = fns[i];
|
|
72
|
-
// if stream, push into pipeline
|
|
73
|
-
if (isStream(fn)) {
|
|
74
|
-
pipeline.push(fn);
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
// otherwise, call the function and pass in the args
|
|
78
|
-
// expect a stream to be returned to push onto the pipeline
|
|
79
|
-
try {
|
|
80
|
-
pipeline.push(fn.apply(this, args));
|
|
81
|
-
} catch (err) {
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return es.pipe.apply(es, pipeline);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Utilities
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
function isStream(obj) {
|
|
93
|
-
return typeof obj === 'object' && obj.pipe && isFunction(obj.pipe);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function isFunction(val) {
|
|
97
|
-
return typeof val === 'function';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function arrayify(val) {
|
|
101
|
-
return Array.isArray(val) ? val : [val];
|
|
102
|
-
}
|