Add ensure string helper for nodes.

This commit is contained in:
Mark Hindess
2014-08-28 14:25:41 +01:00
parent e09ac859d3
commit a9e72858df
6 changed files with 77 additions and 24 deletions

View File

@@ -19,6 +19,7 @@ var nodes = require("./nodes");
var library = require("./library");
var comms = require("./comms");
var log = require("./log");
var utils = require("./utils");
var fs = require("fs");
var settings = null;
var credentials = require("./nodes/credentials");
@@ -48,6 +49,7 @@ var RED = {
events: events,
log: log,
comms: comms,
utils: utils,
version: function () {
var p = require(path.join(process.env.NODE_RED_HOME,"package.json"));
if (fs.existsSync(path.join(process.env.NODE_RED_HOME,".git"))) {

31
red/utils.js Normal file
View File

@@ -0,0 +1,31 @@
/**
* Copyright 2014 IBM Corp.
*
* 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.
**/
function ensureString(o) {
if (Buffer.isBuffer(o)) {
return o.toString();
} else if (typeof o === "object") {
return JSON.stringify(o);
} else if (typeof o === "string") {
return o;
}
return ""+o;
}
module.exports = {
ensureString: ensureString,
};