1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Rename RED.utils to RED.util. Fixes #364.

This commit is contained in:
Mark Hindess 2014-09-03 13:18:26 +01:00
parent 8e78df09da
commit 0a009e2a15
6 changed files with 11 additions and 11 deletions

View File

@ -160,7 +160,7 @@ module.exports = function(RED) {
delete msg._session; delete msg._session;
payload = JSON.stringify(msg); payload = JSON.stringify(msg);
} else { } else {
payload = RED.utils.ensureString(msg.payload); payload = RED.util.ensureString(msg.payload);
} }
if (msg._session && msg._session.type == "websocket") { if (msg._session && msg._session.type == "websocket") {
node.serverConfig.send(msg._session.id,payload); node.serverConfig.send(msg._session.id,payload);

View File

@ -73,7 +73,7 @@ module.exports = function(RED) {
if (msg != null) { if (msg != null) {
if (smtpTransport) { if (smtpTransport) {
node.status({fill:"blue",shape:"dot",text:"sending"}); node.status({fill:"blue",shape:"dot",text:"sending"});
var payload = RED.utils.ensureString(msg.payload); var payload = RED.util.ensureString(msg.payload);
smtpTransport.sendMail({ smtpTransport.sendMail({
from: node.userid, // sender address from: node.userid, // sender address

View File

@ -83,7 +83,7 @@ module.exports = function(RED) {
var k = this.key || msg.topic; var k = this.key || msg.topic;
if (k) { if (k) {
if (this.structtype == "string") { if (this.structtype == "string") {
this.client.set(k,RED.utils.ensureString(msg.payload)); this.client.set(k,RED.util.ensureString(msg.payload));
} else if (this.structtype == "hash") { } else if (this.structtype == "hash") {
var r = hashFieldRE.exec(msg.payload); var r = hashFieldRE.exec(msg.payload);
if (r) { if (r) {

View File

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

View File

@ -14,25 +14,25 @@
* limitations under the License. * limitations under the License.
**/ **/
var should = require("should"); var should = require("should");
var utils = require("../../red/utils"); var util = require("../../red/util");
describe("red/utils", function() { describe("red/util", function() {
describe('ensureString', function() { describe('ensureString', function() {
it('strings are preserved', function() { it('strings are preserved', function() {
utils.ensureString('string').should.equal('string'); util.ensureString('string').should.equal('string');
}); });
it('Buffer is converted', function() { it('Buffer is converted', function() {
var s = utils.ensureString(new Buffer('foo')); var s = util.ensureString(new Buffer('foo'));
s.should.equal('foo'); s.should.equal('foo');
(typeof s).should.equal('string'); (typeof s).should.equal('string');
}); });
it('Object is converted to JSON', function() { it('Object is converted to JSON', function() {
var s = utils.ensureString({foo: "bar"}); var s = util.ensureString({foo: "bar"});
(typeof s).should.equal('string'); (typeof s).should.equal('string');
should.deepEqual(JSON.parse(s), {foo:"bar"}); should.deepEqual(JSON.parse(s), {foo:"bar"});
}); });
it('stringifies other things', function() { it('stringifies other things', function() {
var s = utils.ensureString(123); var s = util.ensureString(123);
(typeof s).should.equal('string'); (typeof s).should.equal('string');
s.should.equal('123'); s.should.equal('123');
}); });