mirror of
https://github.com/abrendan/MicDropMessages.git
synced 2025-08-25 05:52:02 +02:00
Initial commit
This commit is contained in:
37
node_modules/loadware/.npmignore
generated
vendored
Normal file
37
node_modules/loadware/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules
|
||||
jspm_packages
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
21
node_modules/loadware/LICENSE
generated
vendored
Normal file
21
node_modules/loadware/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Francisco Presencia
|
||||
|
||||
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.
|
21
node_modules/loadware/README.md
generated
vendored
Normal file
21
node_modules/loadware/README.md
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# loadware
|
||||
|
||||
Make sense of a bunch of middleware definitions and return an array of middleware:
|
||||
|
||||
```js
|
||||
const loadware = require('loadware');
|
||||
|
||||
let router = require('express').Router();
|
||||
router.get('/', (req, res) => { res.send('Hello there'); });
|
||||
|
||||
let middlewares = loadware(
|
||||
'body-parser',
|
||||
(req, res, next) => { next(); },
|
||||
'./middle/whatever.js',
|
||||
router
|
||||
);
|
||||
```
|
||||
|
||||
The middleware can be a string, a function or an array of any of the previous.
|
||||
|
||||
This is part of another project which is WIP right now, but I think this is independently enough so it can be launched separately.
|
26
node_modules/loadware/loadware.js
generated
vendored
Normal file
26
node_modules/loadware/loadware.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
// loadware.js - Turn different middleware descriptors into an array of middleware
|
||||
require('app-module-path').addPath(process.cwd());
|
||||
|
||||
// Put it all into a single array of non-arrays recursively
|
||||
// ['a', ['b', ['c', ...]]] => ['a', 'b', 'c', ...]
|
||||
let flat = arr => arr.reduce((good, one) => {
|
||||
let flatten = Array.isArray(one) ? flat(one) : one || [];
|
||||
return good.concat(flatten)
|
||||
}, []);
|
||||
|
||||
// Fetches the absolute path from the root
|
||||
// ['a', 'b'] => [require('a'), require('b')]
|
||||
// Note: this doesn't work: 'require(mid)'
|
||||
let include = mid => typeof mid === 'string'
|
||||
? require(require('path').resolve(mid))
|
||||
: mid;
|
||||
|
||||
// Throw an error if there's something that is not a function anymore
|
||||
// [{ a: 'b' }] => throw new Error();
|
||||
let others = mid => {
|
||||
if (mid instanceof Function) return mid;
|
||||
throw new Error("Only boolean, string, array or function can be middleware");
|
||||
}
|
||||
|
||||
// The actual glue for them all
|
||||
module.exports = (...middle) => flat(middle).map(include).filter(others);
|
62
node_modules/loadware/package.json
generated
vendored
Normal file
62
node_modules/loadware/package.json
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"_from": "loadware@^2.0.0",
|
||||
"_id": "loadware@2.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-V6crbxjuK6/40a0foFpdFuWv1Cw=",
|
||||
"_location": "/loadware",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "loadware@^2.0.0",
|
||||
"name": "loadware",
|
||||
"escapedName": "loadware",
|
||||
"rawSpec": "^2.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/server"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/loadware/-/loadware-2.0.0.tgz",
|
||||
"_shasum": "57a72b6f18ee2baff8d1ad1fa05a5d16e5afd42c",
|
||||
"_spec": "loadware@^2.0.0",
|
||||
"_where": "/home/runner/Socketio-Chat-Template/node_modules/server",
|
||||
"author": {
|
||||
"name": "Francisco Presencia",
|
||||
"email": "public@francisco.io",
|
||||
"url": "http://francisco.io/"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/franciscop/loadware/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"app-module-path": "^2.1.0"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "A library to make sense of a bunch of middleware definitions and return a simple array of middleware\"",
|
||||
"devDependencies": {
|
||||
"express": "^4.14.0",
|
||||
"jest": "^17.0.3",
|
||||
"pray": "^1.0.2"
|
||||
},
|
||||
"homepage": "https://github.com/franciscop/loadware#readme",
|
||||
"keywords": [
|
||||
"loadware",
|
||||
"middleware",
|
||||
"load",
|
||||
"normalize"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "loadware.js",
|
||||
"name": "loadware",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+ssh://git@github.com/franciscop/loadware.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
},
|
||||
"version": "2.0.0"
|
||||
}
|
1
node_modules/loadware/tests/a.js
generated
vendored
Normal file
1
node_modules/loadware/tests/a.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function(){}
|
1
node_modules/loadware/tests/b.js
generated
vendored
Normal file
1
node_modules/loadware/tests/b.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function(){}
|
1
node_modules/loadware/tests/c.js
generated
vendored
Normal file
1
node_modules/loadware/tests/c.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
module.exports = function(){}
|
110
node_modules/loadware/tests/loadware.test.js
generated
vendored
Normal file
110
node_modules/loadware/tests/loadware.test.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
let pray = require('pray');
|
||||
let express = require('express');
|
||||
let loadware = require('../loadware');
|
||||
|
||||
pray.isFn = (el) => expect(el instanceof Function).toBe(true);
|
||||
let allFn = arr => arr.forEach(pray.isFn);
|
||||
let fn = ctx => {};
|
||||
let throws = cb => {
|
||||
let error;
|
||||
try { cb(); } catch(err) { error = err; }
|
||||
if (typeof error === 'undefined') {
|
||||
throw new Error(cb + ' did not throw an error as expected.');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
describe('Initialization', () => {
|
||||
it('Can be used empty', () => {
|
||||
pray([])(loadware());
|
||||
});
|
||||
|
||||
it('Ignores falsy values', () => {
|
||||
expect(loadware([], 0, "", false, null, undefined).length).toBe(0);
|
||||
});
|
||||
|
||||
it('Rejects numbers', () => {
|
||||
throws(() => loadware(5));
|
||||
});
|
||||
|
||||
it('Rejects different objects', () => {
|
||||
throws(() => loadware({ a: 'b' }));
|
||||
throws(() => loadware(new Date()));
|
||||
throws(() => loadware(new Promise(() => {})));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('works with strings', () => {
|
||||
it('Can load from a string', () => {
|
||||
pray(allFn)(loadware('./tests/a'));
|
||||
});
|
||||
|
||||
it('handles many arguments', () => {
|
||||
expect(loadware('./tests/a', './tests/b', './tests/c').length).toBe(3);
|
||||
});
|
||||
|
||||
it('handles nested strings', () => {
|
||||
expect(loadware(['./tests/a'], ['./tests/b', './tests/c']).length).toBe(3);
|
||||
});
|
||||
|
||||
it('handles deeply nested strings', () => {
|
||||
expect(loadware(['./tests/a', ['./tests/b', ['./tests/c']]]).length).toBe(3);
|
||||
});
|
||||
|
||||
it('Throws an error when non-existing string', () => {
|
||||
throws(() => loadware('./tests/dsfs'));
|
||||
});
|
||||
})
|
||||
|
||||
|
||||
|
||||
describe('works with functions', () => {
|
||||
|
||||
it('Converts function to array', () => {
|
||||
pray([fn])(loadware(fn));
|
||||
});
|
||||
|
||||
it('handles many arguments', () => {
|
||||
expect(loadware(fn, fn, fn, fn, fn, fn).length).toBe(6);
|
||||
});
|
||||
|
||||
it('handles nested arrays', () => {
|
||||
expect(loadware([fn], [fn, fn], [fn, fn, fn]).length).toBe(6);
|
||||
});
|
||||
|
||||
it('handles deeply nested arrays', () => {
|
||||
expect(loadware([fn, [fn, [fn, [fn, [fn, [fn]]]]]]).length).toBe(6);
|
||||
});
|
||||
|
||||
// When passing Router() it only rendered the last one since it had some properties
|
||||
it('Treats a function as a function even if it has properties', () => {
|
||||
let fnA = function(){};
|
||||
let fnB = function(){};
|
||||
fnA.a = 'a';
|
||||
fnB.a = 'b';
|
||||
expect(loadware([fnA, fnB])).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('plays well with others', () => {
|
||||
it('works with express router USE', () => {
|
||||
let router = express.Router();
|
||||
router.use('/', fn);
|
||||
pray([router])(loadware(router));
|
||||
});
|
||||
|
||||
it('works with express router GET', () => {
|
||||
let router = express.Router();
|
||||
router.get('/', fn);
|
||||
pray([router])(loadware(router));
|
||||
});
|
||||
|
||||
it('works with express router POST', () => {
|
||||
let router = express.Router();
|
||||
router.post('/', fn);
|
||||
pray([router])(loadware(router));
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user