mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 10:52:47 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
28
node_modules/kareem/.npmignore
generated
vendored
Normal file
28
node_modules/kareem/.npmignore
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
|
||||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Compiled binary addons (http://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directory
|
||||
# Commenting this out is preferred by some people, see
|
||||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
|
||||
node_modules
|
||||
|
||||
# Users Environment Variables
|
||||
.lock-wscript
|
||||
7
node_modules/kareem/.travis.yml
generated
vendored
Normal file
7
node_modules/kareem/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "0.12"
|
||||
- "0.10"
|
||||
- "iojs"
|
||||
script: "npm run-script test-travis"
|
||||
after_script: "npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls"
|
||||
202
node_modules/kareem/LICENSE
generated
vendored
Normal file
202
node_modules/kareem/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
5
node_modules/kareem/Makefile
generated
vendored
Normal file
5
node_modules/kareem/Makefile
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
docs:
|
||||
node ./docs.js
|
||||
|
||||
coverage:
|
||||
./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*
|
||||
379
node_modules/kareem/README.md
generated
vendored
Normal file
379
node_modules/kareem/README.md
generated
vendored
Normal file
@@ -0,0 +1,379 @@
|
||||
# kareem
|
||||
|
||||
[](https://travis-ci.org/vkarpov15/kareem)
|
||||
[](https://coveralls.io/r/vkarpov15/kareem)
|
||||
|
||||
Re-imagined take on the [hooks](http://npmjs.org/package/hooks) module, meant to offer additional flexibility in allowing you to execute hooks whenever necessary, as opposed to simply wrapping a single function.
|
||||
|
||||
Named for the NBA's all-time leading scorer Kareem Abdul-Jabbar, known for his mastery of the [hook shot](http://en.wikipedia.org/wiki/Kareem_Abdul-Jabbar#Skyhook)
|
||||
|
||||
<img src="http://upload.wikimedia.org/wikipedia/commons/0/00/Kareem-Abdul-Jabbar_Lipofsky.jpg" width="220">
|
||||
|
||||
# API
|
||||
|
||||
## pre hooks
|
||||
|
||||
Much like [hooks](https://npmjs.org/package/hooks), kareem lets you define
|
||||
pre and post hooks: pre hooks are called before a given function executes.
|
||||
Unlike hooks, kareem stores hooks and other internal state in a separate
|
||||
object, rather than relying on inheritance. Furthermore, kareem exposes
|
||||
an `execPre()` function that allows you to execute your pre hooks when
|
||||
appropriate, giving you more fine-grained control over your function hooks.
|
||||
|
||||
|
||||
#### It runs without any hooks specified
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It runs basic serial pre hooks
|
||||
|
||||
pre hook functions take one parameter, a "done" function that you execute
|
||||
when your pre hook is finished.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
var count = 0;
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It can run multipe pre hooks
|
||||
|
||||
```javascript
|
||||
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count1;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count2;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It can run fully synchronous pre hooks
|
||||
|
||||
If your pre hook function takes no parameters, its assumed to be
|
||||
fully synchronous.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
++count1;
|
||||
});
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
++count2;
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It properly attaches context to pre hooks
|
||||
|
||||
Pre save hook functions are bound to the second parameter to `execPre()`
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
this.bacon = 3;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
this.eggs = 4;
|
||||
done();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
// In the pre hooks, `this` will refer to `obj`
|
||||
hooks.execPre('cook', obj, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It can execute parallel (async) pre hooks
|
||||
|
||||
Like the hooks module, you can declare "async" pre hooks - these take two
|
||||
parameters, the functions `next()` and `done()`. `next()` passes control to
|
||||
the next pre hook, but the underlying function won't be called until all
|
||||
async pre hooks have called `done()`.
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
## post hooks
|
||||
|
||||
#### It runs without any hooks specified
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.execPost('cook', null, [1], function(error, eggs) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It executes with parameters passed in
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
#### It can use synchronous post hooks
|
||||
|
||||
```javascript
|
||||
|
||||
var execed = {};
|
||||
|
||||
hooks.post('cook', function(eggs, bacon) {
|
||||
execed.first = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
});
|
||||
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
execed.second = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
## wrap()
|
||||
|
||||
#### It wraps pre and post calls into one call
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
```
|
||||
|
||||
## createWrapper()
|
||||
|
||||
#### It wraps wrap() into a callable function
|
||||
|
||||
```javascript
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var cook = hooks.createWrapper(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj);
|
||||
|
||||
cook(obj, function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
done();
|
||||
});
|
||||
|
||||
```
|
||||
|
||||
## clone()
|
||||
|
||||
#### It clones a Kareem object
|
||||
|
||||
```javascript
|
||||
|
||||
var k1 = new Kareem();
|
||||
k1.pre('cook', function() {});
|
||||
k1.post('cook', function() {});
|
||||
|
||||
var k2 = k1.clone();
|
||||
assert.deepEqual(['cook'], Object.keys(k2._pres));
|
||||
assert.deepEqual(['cook'], Object.keys(k2._posts));
|
||||
|
||||
```
|
||||
|
||||
37
node_modules/kareem/docs.js
generated
vendored
Normal file
37
node_modules/kareem/docs.js
generated
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
var acquit = require('acquit');
|
||||
|
||||
var content = require('fs').readFileSync('./test/examples.test.js').toString();
|
||||
var blocks = acquit.parse(content);
|
||||
|
||||
var mdOutput =
|
||||
'# kareem\n\n' +
|
||||
' [](https://travis-ci.org/vkarpov15/kareem)\n' +
|
||||
' [](https://coveralls.io/r/vkarpov15/kareem)\n\n' +
|
||||
'Re-imagined take on the [hooks](http://npmjs.org/package/hooks) module, ' +
|
||||
'meant to offer additional flexibility in allowing you to execute hooks ' +
|
||||
'whenever necessary, as opposed to simply wrapping a single function.\n\n' +
|
||||
'Named for the NBA\'s all-time leading scorer Kareem Abdul-Jabbar, known ' +
|
||||
'for his mastery of the [hook shot](http://en.wikipedia.org/wiki/Kareem_Abdul-Jabbar#Skyhook)\n\n' +
|
||||
'<img src="http://upload.wikimedia.org/wikipedia/commons/0/00/Kareem-Abdul-Jabbar_Lipofsky.jpg" width="220">\n\n' +
|
||||
'# API\n\n';
|
||||
|
||||
for (var i = 0; i < blocks.length; ++i) {
|
||||
var describe = blocks[i];
|
||||
mdOutput += '## ' + describe.contents + '\n\n';
|
||||
mdOutput += describe.comments[0] ?
|
||||
acquit.trimEachLine(describe.comments[0]) + '\n\n' :
|
||||
'';
|
||||
|
||||
for (var j = 0; j < describe.blocks.length; ++j) {
|
||||
var it = describe.blocks[j];
|
||||
mdOutput += '#### It ' + it.contents + '\n\n';
|
||||
mdOutput += it.comments[0] ?
|
||||
acquit.trimEachLine(it.comments[0]) + '\n\n' :
|
||||
'';
|
||||
mdOutput += '```javascript\n';
|
||||
mdOutput += ' ' + it.code + '\n';
|
||||
mdOutput += '```\n\n';
|
||||
}
|
||||
}
|
||||
|
||||
require('fs').writeFileSync('README.md', mdOutput);
|
||||
18
node_modules/kareem/gulpfile.js
generated
vendored
Normal file
18
node_modules/kareem/gulpfile.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
var gulp = require('gulp');
|
||||
var mocha = require('gulp-mocha');
|
||||
var config = require('./package.json');
|
||||
var jscs = require('gulp-jscs');
|
||||
|
||||
gulp.task('mocha', function() {
|
||||
return gulp.src('./test/*').
|
||||
pipe(mocha({ reporter: 'dot' }));
|
||||
});
|
||||
|
||||
gulp.task('jscs', function() {
|
||||
return gulp.src('./index.js').
|
||||
pipe(jscs(config.jscsConfig));
|
||||
});
|
||||
|
||||
gulp.task('watch', function() {
|
||||
gulp.watch('./index.js', ['jscs', 'mocha']);
|
||||
});
|
||||
229
node_modules/kareem/index.js
generated
vendored
Normal file
229
node_modules/kareem/index.js
generated
vendored
Normal file
@@ -0,0 +1,229 @@
|
||||
'use strict';
|
||||
|
||||
function Kareem() {
|
||||
this._pres = {};
|
||||
this._posts = {};
|
||||
}
|
||||
|
||||
Kareem.prototype.execPre = function(name, context, callback) {
|
||||
var pres = this._pres[name] || [];
|
||||
var numPres = pres.length;
|
||||
var numAsyncPres = pres.numAsync || 0;
|
||||
var currentPre = 0;
|
||||
var asyncPresLeft = numAsyncPres;
|
||||
var done = false;
|
||||
|
||||
if (!numPres) {
|
||||
return process.nextTick(function() {
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
|
||||
var next = function() {
|
||||
if (currentPre >= numPres) {
|
||||
return;
|
||||
}
|
||||
var pre = pres[currentPre];
|
||||
|
||||
if (pre.isAsync) {
|
||||
pre.fn.call(
|
||||
context,
|
||||
function(error) {
|
||||
if (error) {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
++currentPre;
|
||||
next.apply(context, arguments);
|
||||
},
|
||||
function(error) {
|
||||
if (error) {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
if (--numAsyncPres === 0) {
|
||||
return callback(null);
|
||||
}
|
||||
});
|
||||
} else if (pre.fn.length > 0) {
|
||||
var args = [function(error) {
|
||||
if (error) {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
if (++currentPre >= numPres) {
|
||||
if (asyncPresLeft > 0) {
|
||||
// Leave parallel hooks to run
|
||||
return;
|
||||
} else {
|
||||
return callback(null);
|
||||
}
|
||||
}
|
||||
|
||||
next.apply(context, arguments);
|
||||
}];
|
||||
if (arguments.length >= 2) {
|
||||
for (var i = 1; i < arguments.length; ++i) {
|
||||
args.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
pre.fn.apply(context, args);
|
||||
} else {
|
||||
pre.fn.call(context);
|
||||
if (++currentPre >= numPres) {
|
||||
if (asyncPresLeft > 0) {
|
||||
// Leave parallel hooks to run
|
||||
return;
|
||||
} else {
|
||||
return process.nextTick(function() {
|
||||
callback(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
Kareem.prototype.execPost = function(name, context, args, callback) {
|
||||
var posts = this._posts[name] || [];
|
||||
var numPosts = posts.length;
|
||||
var currentPost = 0;
|
||||
|
||||
if (!numPosts) {
|
||||
return process.nextTick(function() {
|
||||
callback.apply(null, [null].concat(args));
|
||||
});
|
||||
}
|
||||
|
||||
var next = function() {
|
||||
var post = posts[currentPost];
|
||||
|
||||
if (post.length > args.length) {
|
||||
post.apply(context, args.concat(function(error) {
|
||||
if (error) {
|
||||
return callback(error);
|
||||
}
|
||||
|
||||
if (++currentPost >= numPosts) {
|
||||
return callback.apply(null, [null].concat(args));
|
||||
}
|
||||
|
||||
next();
|
||||
}));
|
||||
} else {
|
||||
post.apply(context, args);
|
||||
|
||||
if (++currentPost >= numPosts) {
|
||||
return callback.apply(null, [null].concat(args));
|
||||
}
|
||||
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
Kareem.prototype.wrap = function(name, fn, context, args, useLegacyPost) {
|
||||
var lastArg = (args.length > 0 ? args[args.length - 1] : null);
|
||||
var _this = this;
|
||||
|
||||
this.execPre(name, context, function(error) {
|
||||
if (error) {
|
||||
if (typeof lastArg === 'function') {
|
||||
return lastArg(error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var end = (typeof lastArg === 'function' ? args.length - 1 : args.length);
|
||||
|
||||
fn.apply(context, args.slice(0, end).concat(function() {
|
||||
if (arguments[0]) {
|
||||
// Assume error
|
||||
return typeof lastArg === 'function' ?
|
||||
lastArg(arguments[0]) :
|
||||
undefined;
|
||||
}
|
||||
|
||||
if (useLegacyPost && typeof lastArg === 'function') {
|
||||
lastArg.apply(context, arguments);
|
||||
}
|
||||
|
||||
var argsWithoutError = Array.prototype.slice.call(arguments, 1);
|
||||
_this.execPost(name, context, argsWithoutError, function() {
|
||||
if (arguments[0]) {
|
||||
return typeof lastArg === 'function' ?
|
||||
lastArg(arguments[0]) :
|
||||
undefined;
|
||||
}
|
||||
|
||||
return typeof lastArg === 'function' && !useLegacyPost ?
|
||||
lastArg.apply(context, arguments) :
|
||||
undefined;
|
||||
});
|
||||
}));
|
||||
});
|
||||
};
|
||||
|
||||
Kareem.prototype.createWrapper = function(name, fn, context) {
|
||||
var _this = this;
|
||||
return function() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
_this.wrap(name, fn, context, args);
|
||||
};
|
||||
};
|
||||
|
||||
Kareem.prototype.pre = function(name, isAsync, fn, error) {
|
||||
if (typeof arguments[1] !== 'boolean') {
|
||||
error = fn;
|
||||
fn = isAsync;
|
||||
isAsync = false;
|
||||
}
|
||||
|
||||
this._pres[name] = this._pres[name] || [];
|
||||
var pres = this._pres[name];
|
||||
|
||||
if (isAsync) {
|
||||
pres.numAsync = pres.numAsync || 0;
|
||||
++pres.numAsync;
|
||||
}
|
||||
|
||||
pres.push({ fn: fn, isAsync: isAsync });
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Kareem.prototype.post = function(name, fn) {
|
||||
(this._posts[name] = this._posts[name] || []).push(fn);
|
||||
return this;
|
||||
};
|
||||
|
||||
Kareem.prototype.clone = function() {
|
||||
var n = new Kareem();
|
||||
for (var key in this._pres) {
|
||||
n._pres[key] = this._pres[key].slice();
|
||||
}
|
||||
for (var key in this._posts) {
|
||||
n._posts[key] = this._posts[key].slice();
|
||||
}
|
||||
|
||||
return n;
|
||||
};
|
||||
|
||||
module.exports = Kareem;
|
||||
86
node_modules/kareem/package.json
generated
vendored
Normal file
86
node_modules/kareem/package.json
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"kareem@1.0.1",
|
||||
"/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/mongoose"
|
||||
]
|
||||
],
|
||||
"_from": "kareem@1.0.1",
|
||||
"_id": "kareem@1.0.1",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/kareem",
|
||||
"_nodeVersion": "0.12.2",
|
||||
"_npmUser": {
|
||||
"email": "valkar207@gmail.com",
|
||||
"name": "vkarpov15"
|
||||
},
|
||||
"_npmVersion": "2.7.4",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "kareem",
|
||||
"raw": "kareem@1.0.1",
|
||||
"rawSpec": "1.0.1",
|
||||
"scope": null,
|
||||
"spec": "1.0.1",
|
||||
"type": "version"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/mongoose"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/kareem/-/kareem-1.0.1.tgz",
|
||||
"_shasum": "7805d215bb53214ec3af969a1d0b1f17e3e7b95c",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "kareem@1.0.1",
|
||||
"_where": "/home/mitchell/Desktop/test-mywebsite/mywebsite/node_modules/mongoose",
|
||||
"author": {
|
||||
"email": "val@karpov.io",
|
||||
"name": "Valeri Karpov"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/vkarpov15/kareem/issues"
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "Next-generation take on pre/post function hooks",
|
||||
"devDependencies": {
|
||||
"acquit": "0.0.3",
|
||||
"gulp": "3.8.10",
|
||||
"gulp-jscs": "1.4.0",
|
||||
"gulp-mocha": "2.0.0",
|
||||
"istanbul": "0.3.5",
|
||||
"jscs": "1.9.0",
|
||||
"mocha": "2.0.0"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"shasum": "7805d215bb53214ec3af969a1d0b1f17e3e7b95c",
|
||||
"tarball": "http://registry.npmjs.org/kareem/-/kareem-1.0.1.tgz"
|
||||
},
|
||||
"gitHead": "69710887f85dee09afac690df770dd2febde7268",
|
||||
"homepage": "https://github.com/vkarpov15/kareem",
|
||||
"jscsConfig": {
|
||||
"disallowMultipleVarDecl": true,
|
||||
"preset": "airbnb",
|
||||
"requireMultipleVarDecl": null
|
||||
},
|
||||
"license": "Apache 2.0",
|
||||
"main": "index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "vkarpov15",
|
||||
"email": "valkar207@gmail.com"
|
||||
}
|
||||
],
|
||||
"name": "kareem",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/vkarpov15/kareem.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "./node_modules/mocha/bin/mocha ./test/*",
|
||||
"test-travis": "./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha -- -R spec ./test/*"
|
||||
},
|
||||
"version": "1.0.1"
|
||||
}
|
||||
339
node_modules/kareem/test/examples.test.js
generated
vendored
Normal file
339
node_modules/kareem/test/examples.test.js
generated
vendored
Normal file
@@ -0,0 +1,339 @@
|
||||
var assert = require('assert');
|
||||
var Kareem = require('../');
|
||||
|
||||
/* Much like [hooks](https://npmjs.org/package/hooks), kareem lets you define
|
||||
* pre and post hooks: pre hooks are called before a given function executes.
|
||||
* Unlike hooks, kareem stores hooks and other internal state in a separate
|
||||
* object, rather than relying on inheritance. Furthermore, kareem exposes
|
||||
* an `execPre()` function that allows you to execute your pre hooks when
|
||||
* appropriate, giving you more fine-grained control over your function hooks.
|
||||
*/
|
||||
describe('pre hooks', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('runs without any hooks specified', function(done) {
|
||||
hooks.execPre('cook', null, function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/* pre hook functions take one parameter, a "done" function that you execute
|
||||
* when your pre hook is finished.
|
||||
*/
|
||||
it('runs basic serial pre hooks', function(done) {
|
||||
var count = 0;
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can run multipe pre hooks', function(done) {
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count1;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
++count2;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function() {
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/* If your pre hook function takes no parameters, its assumed to be
|
||||
* fully synchronous.
|
||||
*/
|
||||
it('can run fully synchronous pre hooks', function(done) {
|
||||
var count1 = 0;
|
||||
var count2 = 0;
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
++count1;
|
||||
});
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
++count2;
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(1, count1);
|
||||
assert.equal(1, count2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/* Pre save hook functions are bound to the second parameter to `execPre()`
|
||||
*/
|
||||
it('properly attaches context to pre hooks', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
this.bacon = 3;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
this.eggs = 4;
|
||||
done();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
// In the pre hooks, `this` will refer to `obj`
|
||||
hooks.execPre('cook', obj, function(error) {
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
/* Like the hooks module, you can declare "async" pre hooks - these take two
|
||||
* parameters, the functions `next()` and `done()`. `next()` passes control to
|
||||
* the next pre hook, but the underlying function won't be called until all
|
||||
* async pre hooks have called `done()`.
|
||||
*/
|
||||
it('can execute parallel (async) pre hooks', function(done) {
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
hooks.execPre('cook', obj, function() {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('post hooks', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('runs without any hooks specified', function(done) {
|
||||
hooks.execPost('cook', null, [1], function(error, eggs) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('executes with parameters passed in', function(done) {
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can use synchronous post hooks', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.post('cook', function(eggs, bacon) {
|
||||
execed.first = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
});
|
||||
|
||||
hooks.post('cook', function(eggs, bacon, callback) {
|
||||
execed.second = true;
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
callback();
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [1, 2], function(error, eggs, bacon) {
|
||||
assert.ifError(error);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
assert.equal(1, eggs);
|
||||
assert.equal(2, bacon);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('wrap()', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('wraps pre and post calls into one call', function(done) {
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(null, error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createWrapper()', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('wraps wrap() into a callable function', function(done) {
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
this.bacon = 3;
|
||||
next();
|
||||
setTimeout(function() {
|
||||
done();
|
||||
}, 5);
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
next();
|
||||
var _this = this;
|
||||
setTimeout(function() {
|
||||
_this.eggs = 4;
|
||||
done();
|
||||
}, 10);
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
this.waffles = false;
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var cook = hooks.createWrapper(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
callback(null, o);
|
||||
},
|
||||
obj);
|
||||
|
||||
cook(obj, function(error, result) {
|
||||
assert.ifError(error);
|
||||
assert.equal(3, obj.bacon);
|
||||
assert.equal(4, obj.eggs);
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
|
||||
assert.equal(obj, result);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('clone()', function() {
|
||||
it('clones a Kareem object', function() {
|
||||
var k1 = new Kareem();
|
||||
k1.pre('cook', function() {});
|
||||
k1.post('cook', function() {});
|
||||
|
||||
var k2 = k1.clone();
|
||||
assert.deepEqual(['cook'], Object.keys(k2._pres));
|
||||
assert.deepEqual(['cook'], Object.keys(k2._posts));
|
||||
});
|
||||
});
|
||||
46
node_modules/kareem/test/post.test.js
generated
vendored
Normal file
46
node_modules/kareem/test/post.test.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
var assert = require('assert');
|
||||
var Kareem = require('../');
|
||||
|
||||
describe('execPost', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('handles errors', function(done) {
|
||||
hooks.post('cook', function(eggs, callback) {
|
||||
callback('error!');
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [4], function(error, eggs) {
|
||||
assert.equal('error!', error);
|
||||
assert.ok(!eggs);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('multiple posts', function(done) {
|
||||
hooks.post('cook', function(eggs, callback) {
|
||||
setTimeout(
|
||||
function() {
|
||||
callback();
|
||||
},
|
||||
5);
|
||||
});
|
||||
|
||||
hooks.post('cook', function(eggs, callback) {
|
||||
setTimeout(
|
||||
function() {
|
||||
callback();
|
||||
},
|
||||
5);
|
||||
});
|
||||
|
||||
hooks.execPost('cook', null, [4], function(error, eggs) {
|
||||
assert.ifError(error);
|
||||
assert.equal(4, eggs);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
226
node_modules/kareem/test/pre.test.js
generated
vendored
Normal file
226
node_modules/kareem/test/pre.test.js
generated
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
var assert = require('assert');
|
||||
var Kareem = require('../');
|
||||
|
||||
describe('execPre', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('handles errors with multiple pres', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
execed.first = true;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
execed.second = true;
|
||||
done('error!');
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(done) {
|
||||
execed.third = true;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.equal('error!', err);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles async errors', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.first = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
done('error!');
|
||||
},
|
||||
5);
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.second = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
done('other error!');
|
||||
},
|
||||
10);
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.equal('error!', err);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles async errors in next()', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.first = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
done('other error!');
|
||||
},
|
||||
15);
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.second = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
next('error!');
|
||||
done('another error!');
|
||||
},
|
||||
5);
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.equal('error!', err);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('handles async errors in next() when already done', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.first = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
done('other error!');
|
||||
},
|
||||
5);
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.second = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
next('error!');
|
||||
done('another error!');
|
||||
},
|
||||
25);
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.equal('other error!', err);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('returns correct error when async pre errors', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.first = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
done('other error!');
|
||||
},
|
||||
5);
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
execed.second = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
next('error!');
|
||||
},
|
||||
15);
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.equal('other error!', err);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('lets async pres run when fully sync pres are done', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', true, function(next, done) {
|
||||
execed.first = true;
|
||||
setTimeout(
|
||||
function() {
|
||||
done();
|
||||
},
|
||||
5);
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function() {
|
||||
execed.second = true;
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.ifError(err);
|
||||
assert.equal(2, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('allows passing arguments to the next pre', function(done) {
|
||||
var execed = {};
|
||||
|
||||
hooks.pre('cook', function(next) {
|
||||
execed.first = true;
|
||||
next(null, 'test');
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next, p) {
|
||||
execed.second = true;
|
||||
assert.equal(p, 'test');
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.pre('cook', function(next, p) {
|
||||
execed.third = true;
|
||||
assert.ok(!p);
|
||||
next();
|
||||
});
|
||||
|
||||
hooks.execPre('cook', null, function(err) {
|
||||
assert.ifError(err);
|
||||
assert.equal(3, Object.keys(execed).length);
|
||||
assert.ok(execed.first);
|
||||
assert.ok(execed.second);
|
||||
assert.ok(execed.third);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
277
node_modules/kareem/test/wrap.test.js
generated
vendored
Normal file
277
node_modules/kareem/test/wrap.test.js
generated
vendored
Normal file
@@ -0,0 +1,277 @@
|
||||
var assert = require('assert');
|
||||
var Kareem = require('../');
|
||||
|
||||
describe('wrap()', function() {
|
||||
var hooks;
|
||||
|
||||
beforeEach(function() {
|
||||
hooks = new Kareem();
|
||||
});
|
||||
|
||||
it('handles pre errors', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
done('error!');
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.equal('error!', error);
|
||||
assert.ok(!result);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
// Should never get called
|
||||
assert.ok(false);
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
});
|
||||
|
||||
it('handles pre errors when no callback defined', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
done('error!');
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
// Should never get called
|
||||
assert.ok(false);
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
done();
|
||||
},
|
||||
25);
|
||||
});
|
||||
|
||||
it('handles errors in wrapped function', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj) {
|
||||
obj.tofu = 'no';
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.equal('error!', error);
|
||||
assert.ok(!result);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
callback('error!');
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
});
|
||||
|
||||
it('handles errors in post', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(obj, callback) {
|
||||
obj.tofu = 'no';
|
||||
callback('error!');
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [obj];
|
||||
args.push(function(error, result) {
|
||||
assert.equal('error!', error);
|
||||
assert.ok(!result);
|
||||
assert.equal('no', obj.tofu);
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(o, callback) {
|
||||
callback(null, o);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
});
|
||||
|
||||
it('works with no args', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(callback) {
|
||||
obj.tofu = 'no';
|
||||
callback();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [];
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(callback) {
|
||||
callback(null);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
assert.equal('no', obj.tofu);
|
||||
done();
|
||||
},
|
||||
25);
|
||||
});
|
||||
|
||||
it('handles pre errors with no args', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
done('error!');
|
||||
});
|
||||
|
||||
hooks.post('cook', function(callback) {
|
||||
obj.tofu = 'no';
|
||||
callback();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [];
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(callback) {
|
||||
callback(null);
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
assert.equal(undefined, obj.tofu);
|
||||
done();
|
||||
},
|
||||
25);
|
||||
});
|
||||
|
||||
it('handles wrapped function errors with no args', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
obj.waffles = false;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(callback) {
|
||||
obj.tofu = 'no';
|
||||
callback();
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [];
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(callback) {
|
||||
callback('error!');
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal(undefined, obj.tofu);
|
||||
done();
|
||||
},
|
||||
25);
|
||||
});
|
||||
|
||||
it('handles post errors with no args', function(done) {
|
||||
hooks.pre('cook', function(done) {
|
||||
obj.waffles = false;
|
||||
done();
|
||||
});
|
||||
|
||||
hooks.post('cook', function(callback) {
|
||||
obj.tofu = 'no';
|
||||
callback('error!');
|
||||
});
|
||||
|
||||
var obj = { bacon: 0, eggs: 0 };
|
||||
|
||||
var args = [];
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(callback) {
|
||||
callback();
|
||||
},
|
||||
obj,
|
||||
args);
|
||||
|
||||
setTimeout(
|
||||
function() {
|
||||
assert.equal(false, obj.waffles);
|
||||
assert.equal('no', obj.tofu);
|
||||
done();
|
||||
},
|
||||
25);
|
||||
});
|
||||
|
||||
it('can use legacy post behavior', function(done) {
|
||||
var called = 0;
|
||||
hooks.post('cook', function(callback) {
|
||||
++called;
|
||||
callback();
|
||||
});
|
||||
|
||||
var args = [function(error) {
|
||||
assert.equal(called, 0);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(called, 1);
|
||||
done();
|
||||
}, 0);
|
||||
}];
|
||||
|
||||
hooks.wrap(
|
||||
'cook',
|
||||
function(callback) {
|
||||
callback();
|
||||
},
|
||||
null,
|
||||
args,
|
||||
true);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user