Created
November 17, 2014 11:33
-
-
Save octavian-nita/2e9f82401e94c85e791c to your computer and use it in GitHub Desktop.
Node.js / JavaScript useful code snippets
This file contains hidden or 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
| 'use strict'; | |
| var log = require('./log'); | |
| exports.slug = function(name) { | |
| return name || name. | |
| replace(/^[-\s_]*[\[\(]*[\s\d]+[\]\)]*[-\s_]*/g, ''). // remove eventual leading index / number in name | |
| replace(/^[-\s_]+|[-\s_]+$/g, ''). // remove leading and trailing spaces, dashes, underscores | |
| replace(/[-\s_]+/g, config.slugSeparator); // join by defined slug separator | |
| }; | |
| exports.json = function(object) { | |
| if (object && object instanceof Error) { | |
| object = {'name': object.name, 'message': object.message}; | |
| } | |
| return JSON.stringify(object, null, config.debug.on ? config.debug.indent : 0); | |
| }; | |
| process.on('uncaughtException', function(err) { | |
| log.error(err); // at least log something, not really able to send an answer (which request?)... | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment