* Remove old dependency

* Add string-format dep.
* Convert various strUtil.format() -> String.prototype.format() based system
This commit is contained in:
Bryan Ashby 2015-08-27 16:14:56 -06:00
parent 140990811a
commit ede00f8937
7 changed files with 57 additions and 32 deletions

View File

@ -8,7 +8,6 @@ var miscUtil = require('./misc_util.js');
var database = require('./database.js');
var clientConns = require('./client_connections.js');
var iconv = require('iconv-lite');
var paths = require('path');
var async = require('async');
var util = require('util');
@ -98,7 +97,9 @@ function initialize(cb) {
process.exit();
});
iconv.extendNodeEncodings();
// Init some extensions
require('iconv-lite').extendNodeEncodings();
require('string-format').extend(String.prototype, require('./string_util.js').stringFormatExtensions);
callback(null);
},
@ -192,6 +193,7 @@ function startListening() {
clientConns.addNewClient(client);
client.on('ready', function onClientReady() {
// Go to module -- use default error handler
prepareClient(client, function onPrepared() {
require('./connect.js').connectEntry(client);

View File

@ -85,10 +85,10 @@ function prepareTerminal(term) {
function displayBanner(term) {
// :TODO: add URL(s) to banner
term.pipeWrite(util.format(
'|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 %s\n' +
term.pipeWrite(
('|33Conected to |32EN|33|01i|00|32|22GMA|32|01½|00 |33BBS version|31|01 {0}\n' +
'|00|33Copyright (c) 2014-2015 Bryan Ashby |33|01- |31|01http://l33t.codes/\n' +
'|00', packageJson.version));
'|00').format(packageJson.version));
}
function connectEntry(client) {

View File

@ -44,7 +44,8 @@ function getDateFromFtnDateTime(dateTime) {
}
function getFormattedFTNAddress(address, dimensions) {
var addr = util.format('%d:%d', address.zone, address.net);
//var addr = util.format('%d:%d', address.zone, address.net);
var addr = '{0}:{1}'.format(address.zone, address.net);
switch(dimensions) {
case 2 :
case '2D' :
@ -53,18 +54,18 @@ function getFormattedFTNAddress(address, dimensions) {
case 3 :
case '3D' :
addr += util.format('/%d', address.node);
addr += '/{0}'.format(address.node);
break;
case 4 :
case '4D':
addr += util.format('.%d', address.point || 0); // missing and 0 are equiv for point
addr += '.{0}'.format(address.point || 0); // missing and 0 are equiv for point
break;
case 5 :
case '5D' :
if(address.domain) {
addr += util.format('@%s', address.domain);
addr += '@{0}'.format(address.domain);
}
break;
}

View File

@ -87,9 +87,9 @@ function getMessageListForArea(options, areaName, cb) {
[
function fetchMessages(callback) {
msgDb.each(
'SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count '
'FROM message '
'WHERE area_name=? '
'SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count ' +
'FROM message ' +
'WHERE area_name=? ' +
'ORDER BY message_id;',
[ areaName.toLowerCase() ],
function msgRow(err, row) {

View File

@ -177,17 +177,40 @@ function debugEscapedString(s) {
return JSON.stringify(s).slice(1, -1);
}
function format(fmt) {
if (!arguments.length) {
return fmt;
}
//
// Extend String.format's object syntax with some modifiers
// e.g.: '{username!styleL33t}'.format( { username : 'Leet User' } ) -> "L33t U53r"
//
var stringFormatExtensions = {
styleUpper : function(s) {
return stylizeString(s, 'upper');
},
styleLower : function(s) {
return stylizeString(s, 'lower');
},
styleTitle : function(s) {
return stylizeString(s, 'title');
},
styleFirstLower : function(s) {
return stylizeString(s, 'first lower');
},
styleSmallVowels : function(s) {
return stylizeString(s, 'small vowels');
},
styleBigVowels : function(s) {
return stylizeString(s, 'big vowels');
},
styleSmallI : function(s) {
return stylizeString(s, 'small i');
},
styleMixed : function(s) {
return stylizeString(s, 'mixed');
},
styleL33t : function(s) {
return stylizeString(s, 'l33t');
}
var args = typeof arguments[1];
args = (("string" === args || "number" === args) ? arguments : arguments[1]);
// :TODO: Add padding/etc. modifiers.
};
for(var arg in args) {
fmt = fmt.replace(RegExp("\\{" + arg + "\\}", "gi"), args[arg]);
}
return fmt;
}
exports.stringFormatExtensions = stringFormatExtensions;

View File

@ -104,9 +104,8 @@ MessageAreaListModule.prototype.mciReady = function(mciData, cb) {
function populateAreaListView(callback) {
var areaListItems = [];
for(var i = 0; i < self.messageAreas.length; ++i) {
areaListItems.push(strUtil.format(
self.entryFormat,
{ index : i, name : self.messageAreas[i].name, desc : self.messageAreas[i].desc })
areaListItems.push(self.entryFormat.format(
{ index : i, name : self.messageAreas[i].name, desc : self.messageAreas[i].desc } )
);
}

View File

@ -13,12 +13,12 @@
"sqlite3" : "3.0.x",
"ssh2" : "0.4.x",
"strip-json-comments" : "1.0.x",
"gapbuffer" : "0.0.2",
"node-uuid" : "1.4.x",
"moment" : "2.10.x",
"gaze" : "0.5.x",
"mkdirp" : "0.5.x",
"pty.js" : "0.2.x"
"pty.js" : "0.2.x",
"string-format" : "0.5.x"
},
"engine" : "node >= 0.12.2"
}