Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b37746
commit 6c156fe
Showing
4 changed files
with
158 additions
and
13 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
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,93 @@ | ||
var helper = (function () { | ||
return { | ||
/** | ||
* Looking for a value in array | ||
* @param needle - value that we would like to find | ||
* @param haystack - array to check | ||
* @param argStrict - type of checking (=== or ==) - boolean | ||
* @returns {boolean} | ||
*/ | ||
in_array: function (needle, haystack, argStrict) { | ||
var key = '', | ||
strict = !!argStrict; | ||
|
||
if (strict) { | ||
for (key in haystack) { | ||
if (haystack[key] === needle) { | ||
return true; | ||
} | ||
} | ||
} else { | ||
for (key in haystack) { | ||
if (haystack[key] == needle) { | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
}, | ||
|
||
/** | ||
* Cloning the object/array | ||
* @param obj | ||
* @returns {*} | ||
*/ | ||
clone: function (obj) { | ||
// Handle the 3 simple types, and null or undefined | ||
if (null == obj || "object" != typeof obj) return obj; | ||
|
||
// Handle Date | ||
if (obj instanceof Date) { | ||
var copy = new Date(); | ||
copy.setTime(obj.getTime()); | ||
return copy; | ||
} | ||
|
||
// Handle Array | ||
if (obj instanceof Array) { | ||
var copy = []; | ||
for (var i = 0, len = obj.length; i < len; i++) { | ||
copy[i] = this.clone(obj[i]); | ||
} | ||
return copy; | ||
} | ||
|
||
// Handle Object | ||
if (obj instanceof Object) { | ||
var copy = {}; | ||
for (var attr in obj) { | ||
if (obj.hasOwnProperty(attr)) copy[attr] = this.clone(obj[attr]); | ||
} | ||
return copy; | ||
} | ||
|
||
throw new Error("Unable to copy obj! Its type isn't supported."); | ||
}, | ||
|
||
/** | ||
* Do the string "fdfasdf wfqw cQDASD" as "Fdfasdf Wfgq Cqdasd" | ||
* @param string | ||
* @returns {string} | ||
*/ | ||
capitalize: function (string) { | ||
// return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); | ||
// return string.replace(/\b./g, function(m){ return m.toUpperCase(); }); | ||
var strArr = string.split(" "); | ||
var newArr = []; | ||
|
||
for (var i = 0; i < strArr.length; i++) { | ||
|
||
var FirstLetter = strArr[i].charAt(0).toUpperCase(); | ||
var restOfWord = strArr[i].slice(1).toLowerCase(); | ||
|
||
newArr[i] = FirstLetter + restOfWord; | ||
|
||
} | ||
|
||
return newArr.join(' '); | ||
} | ||
} | ||
}); | ||
|
||
module.exports = helper; |
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,59 @@ | ||
var winston = require('winston'); | ||
|
||
var customLevels = { | ||
levels: { | ||
debug: 0, | ||
info: 1, | ||
warn: 2, | ||
error: 3 | ||
}, | ||
colors: { | ||
debug: 'blue', | ||
info: 'green', | ||
warn: 'yellow', | ||
error: 'red' | ||
} | ||
}; | ||
|
||
var logger = new (winston.Logger)({ | ||
level: 'debug', | ||
levels: customLevels.levels, | ||
transports: [ | ||
new winston.transports.File({ | ||
filename: __dirname+'/../logs/debug.log', | ||
|
||
maxsize: 1024 * 1024 * 10, // 10MB | ||
levels: customLevels.levels, | ||
level: 'debug', | ||
json: false | ||
}) | ||
], | ||
exceptionHandlers: [ | ||
new winston.transports.Console(), | ||
new winston.transports.File({ | ||
filename: __dirname+'/../logs/exceptions.log', | ||
json: false | ||
}) | ||
], | ||
exitOnError: false | ||
}); | ||
|
||
var accessLoger = new (winston.Logger)({ | ||
level: 'debug', | ||
levels: customLevels.levels, | ||
transports: [ | ||
new winston.transports.File({ | ||
filename: __dirname+'/../logs/access.log', | ||
|
||
maxsize: 1024 * 1024 * 10, // 10MB | ||
levels: customLevels.levels, | ||
level: 'debug', | ||
json: false | ||
}) | ||
] | ||
}); | ||
|
||
// make winston aware of your awesome colour choices | ||
winston.addColors(customLevels.colors); | ||
|
||
module.exports = { logger: logger, accessLogger: accessLoger }; |
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