mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add ensure string helper for nodes.
This commit is contained in:
@@ -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
31
red/utils.js
Normal 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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user