From eb693f1741b10bbd8ce66155092d56689f15a029 Mon Sep 17 00:00:00 2001 From: Hengkiardo Date: Sat, 6 Sep 2014 01:03:03 +0700 Subject: [PATCH] missing add utils helper --- app/helper/utils.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 app/helper/utils.js diff --git a/app/helper/utils.js b/app/helper/utils.js new file mode 100644 index 0000000..5a6b17e --- /dev/null +++ b/app/helper/utils.js @@ -0,0 +1,24 @@ + +exports.randomString = function (length) { + var chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHUJKLMNOPQRSTUVWXYZ'; + var result = ''; + for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))]; + return result; +} + +exports.prettyJSON = function(data) { + return require("prettyjson").render(data); +} + +exports.responses = function(res, status, obj) { + var resultPrint = {} + if (status == 200) { + resultPrint.data = obj + } else { + resultPrint = obj + } + resultPrint.id = require('node-uuid').v4() + resultPrint.status = status + + return res.status(status).json(resultPrint ) +}