-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from vinitkumar/cleanup
Cleanup
- Loading branch information
Showing
10 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/* | ||
npm-debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
if (comment && comment.user) | ||
.comment | ||
a(href="/users/"+ comment.user) #{comment.user} | ||
a(href="/users/"+ comment.user)= comment.user | ||
| : | ||
!= comment.body | ||
.date= formatDate(tweet.createdAt, "%b %d, %Y at %I:%M %p") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* Formats mongoose errors into proper array | ||
* | ||
* @param {Array} errors | ||
* @return {Array} | ||
* @api public | ||
*/ | ||
|
||
exports.errors = function (errors) { | ||
var keys = Object.keys(errors) | ||
var errs = [] | ||
|
||
// if there is no validation error, just display a generic error | ||
if (!keys) { | ||
return ['Oops! There was an error'] | ||
} | ||
|
||
keys.forEach(function (key) { | ||
errs.push(errors[key].message) | ||
}) | ||
|
||
return errs | ||
} | ||
|
||
/** | ||
* Index of object within an array | ||
* | ||
* @param {Array} arr | ||
* @param {Object} obj | ||
* @return {Number} | ||
* @api public | ||
*/ | ||
|
||
exports.indexof = function (arr, obj) { | ||
var index = -1; // not found initially | ||
var keys = Object.keys(obj); | ||
// filter the collection with the given criterias | ||
var result = arr.filter(function (doc, idx) { | ||
// keep a counter of matched key/value pairs | ||
var matched = 0; | ||
|
||
// loop over criteria | ||
for (var i = keys.length - 1; i >= 0; i--) { | ||
if (doc[keys[i]] === obj[keys[i]]) { | ||
matched++; | ||
|
||
// check if all the criterias are matched | ||
if (matched === keys.length) { | ||
index = idx; | ||
return idx; | ||
} | ||
} | ||
}; | ||
}); | ||
return index; | ||
} | ||
|
||
/** | ||
* Find object in an array of objects that matches a condition | ||
* | ||
* @param {Array} arr | ||
* @param {Object} obj | ||
* @param {Function} cb - optional | ||
* @return {Object} | ||
* @api public | ||
*/ | ||
|
||
exports.findByParam = function (arr, obj, cb) { | ||
var index = exports.indexof(arr, obj) | ||
if (~index && typeof cb === 'function') { | ||
return cb(undefined, arr[index]) | ||
} else if (~index && !cb) { | ||
return arr[index] | ||
} else if (!~index && typeof cb === 'function') { | ||
return cb('not found') | ||
} | ||
// else undefined is returned | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"name": "nwitter", | ||
"description": "A twitter demo app in nodejs", | ||
"version": "0.0.1-49", | ||
"version": "0.0.1-54", | ||
"repository": "https://github.com/vinitcool76/node-twitter", | ||
"private": false, | ||
"author": "Vinit Kumar <[email protected]> (http://vinitkumar.me)", | ||
|