-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
660 lines (543 loc) · 25.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
var async = require('async');
var mysql = require('mysql');
var _ = require('underscore');
var noop = function(){};
var logPrefix = '[nodebb-plugin-import-vanilla]';
(function(Exporter) {
Exporter.setup = function(config, callback) {
Exporter.log('setup');
// mysql db only config
// extract them from the configs passed by the nodebb-plugin-import adapter
var _config = {
host: config.dbhost || config.host || 'localhost',
user: config.dbuser || config.user || 'root',
password: config.dbpass || config.pass || config.password || '',
port: config.dbport || config.port || 3306,
database: config.dbname || config.name || config.database || 'vanilla'
};
Exporter.config(_config);
Exporter.config('prefix', config.prefix || config.tablePrefix || 'GDN_');
if (config.custom && typeof config.custom === 'string') {
try {
config.custom = JSON.parse(config.custom)
} catch (e) {
config.custom = null
}
}
Exporter.config('custom', config.custom || {
'kudosEnabled': false
});
Exporter.connection = mysql.createConnection(_config);
Exporter.connection.connect();
callback(null, Exporter.config());
};
Exporter.getUsers = function(callback) {
return Exporter.getPaginatedUsers(0, -1, callback);
};
Exporter.getPaginatedUsers = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var err;
var prefix = Exporter.config('prefix');
var startms = +new Date();
var query = 'SELECT '
+ 'tblUser.UserID AS _uid, '
+ 'tblUser.Name AS _username, '
// + 'tblUser.USER_DISPLAY_NAME AS _alternativeUsername, '
+ 'tblUser.Email AS _registrationEmail, '
+ 'if (tblUser.Admin = 1, "administrator", "") AS _level, '
+ 'UNIX_TIMESTAMP(tblUser.DateFirstVisit) AS _joindate, '
+ 'tblUser.Banned AS _banned, '
+ 'tblUser.Email AS _email, '
// + prefix + 'USER_PROFILE.USER_SIGNATURE AS _signature, '
// + prefix + 'USER_PROFILE.USER_HOMEPAGE AS _website, '
// + prefix + 'USER_PROFILE.USER_OCCUPATION AS _occupation, '
// + prefix + 'USER_PROFILE.USER_LOCATION AS _location, '
+ 'CONCAT(\'/uploads/profile/\', tblUser.Photo) AS _picture, '
// + prefix + 'USER_PROFILE.USER_TITLE AS _title, '
+ 'tblUser.ShowEmail AS _showemail, '
+ 'UNIX_TIMESTAMP(tblUser.DateLastActive) AS _lastposttime, ' // approximate
+ '(SELECT GROUP_CONCAT(d.DiscussionID) FROM ' + prefix + 'Discussion d JOIN ' + prefix + 'UserDiscussion ud ON (d.DiscussionID = ud.DiscussionID) WHERE ud.DateLastViewed >= d.dateLastComment AND ud.UserID = tblUser.UserID) as _readTids, '
// count both discussions and Comments AS posts
+ '(tblUser.CountDiscussions + tblUser.CountComments) AS _postcount, '
+ 'DATE_FORMAT(tblUser.DateOfBirth, "%m/%d/%Y") AS _birthday ' // format: mm/dd/yyyy
+ 'FROM ' + prefix + 'User AS tblUser ' //+ prefix + 'USER_PROFILE '
+ 'WHERE tblUser.Deleted = 0 '
// + 'WHERE ' + prefix + 'USERS.USER_ID = ' + prefix + 'USER_PROFILE.USER_ID '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// console.log ('Users query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize here
var map = {};
rows.forEach(function(row) {
// nbb forces signatures to be less than 150 chars
// keeping it HTML see https://github.com/akhoury/nodebb-plugin-import#markdown-note
row._signature = Exporter.truncateStr(row._signature || '', 150);
// from unix timestamp (s) to JS timestamp (ms)
row._joindate = ((row._joindate || 0) * 1000) || startms;
// lower case the email for consistency
row._email = (row._email || '').toLowerCase();
row._picture = getActualProfilePath(row._picture);
row._website = Exporter.validateUrl(row._website);
row._readTids = row._readTids ? row._readTids.split(',').map(function(tidStr){ return parseInt(tidStr); }) : [];
map[row._uid] = row;
});
callback(null, map);
});
};
// Vanilla does this annoying thing where they change the filename based on the context. This uses
// the smallest version (prepended with an 'n', since I found that one to be most consistent.
// Resolution might suffer
var getActualProfilePath = function(path) {
// return empty string if e.g. GDN_User.Photo is NULL
if (!path)
return "";
// probably won't work on windows
var lastSlash = path.lastIndexOf('/') + 1;
return path.substring(0, lastSlash) + 'n' + path.substring(lastSlash);
};
Exporter.getCategories = function(callback) {
return Exporter.getPaginatedCategories(0, -1, callback);
};
Exporter.getPaginatedCategories = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var err;
var prefix = Exporter.config('prefix');
var startms = +new Date();
var query = 'SELECT '
+ 'tblCategory.CategoryID AS _cid, '
+ 'tblCategory.Name AS _name, '
+ 'tblCategory.Description AS _description, '
+ 'UNIX_TIMESTAMP(tblCategory.DateInserted) AS _timestamp '
+ 'FROM ' + prefix + 'Category AS tblCategory '
+ 'WHERE tblCategory.CategoryID > -1 ' // GDN has a root category with id -1 we don't use
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// console.log ('Categories query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize here
var map = {};
rows.forEach(function(row) {
row._name = row._name || 'Untitled Category '
row._description = row._description || 'No description available';
row._timestamp = ((row._timestamp || 0) * 1000) || startms;
map[row._cid] = row;
});
callback(null, map);
});
};
Exporter.getRooms = function(callback) {
return Exporter.getPaginatedRooms(0, -1, callback);
};
Exporter.getPaginatedRooms = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var err;
var prefix = Exporter.config('prefix');
var startms = +new Date();
var query =
'SELECT '
+ 'tblRooms.ConversationID AS _roomId, '
+ 'tblRooms.InsertUserID AS _uid, '
+ 'tblRooms.Contributors AS _uids, '
+ 'UNIX_TIMESTAMP(tblRooms.DateInserted) AS _timestamp '
+ 'FROM ' + prefix + 'Conversation AS tblRooms '// + prefix + ', Comment AS tblPosts '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// console.log ('Topics query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize here
var map = {};
rows.forEach(function(row) {
// this is a really terrible hack and I'm not sure it will work for all communities
// the Contributors column is formatted as such: 'a:3:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:2:"10";}'
// so, contributors are denoted as 's:<some var>:"<contributor uid>"' and this is how to extract it:
row._uids = row._uids.split(';')
.filter(function(s){return s[0] === 's';}) // only return elements starting with 's'
.map(function(s){ // then split by ':', getting the third element
return parseInt(s.split(':')[2].replace('"','')); // which is a string containing quotes, and parse to int.
});
row._roomName = 'Chat Room ' + row._roomId;
row._timestamp = ((row._timestamp || 0) * 1000) || startms;
map[row._roomId] = row;
});
callback(null, map);
});
};
Exporter.getMessages = function(callback) {
return Exporter.getPaginatedMessages(0, -1, callback);
};
Exporter.getPaginatedMessages = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var err;
var prefix = Exporter.config('prefix');
var startms = +new Date();
var query =
'SELECT '
+ 'tblMessages.MessageID AS _mid, '
+ 'tblMessages.ConversationID AS _roomId, '
+ 'tblMessages.InsertUserID AS _fromuid, '
+ 'tblMessages.Body AS _content, '
+ 'UNIX_TIMESTAMP(tblMessages.DateInserted) AS _timestamp '
+ 'FROM ' + prefix + 'ConversationMessage AS tblMessages '// + prefix + ', Comment AS tblPosts '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// console.log ('Messages query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize here
var map = {};
rows.forEach(function(row) {
row._title = row._title ? row._title[0].toUpperCase() + row._title.substr(1) : 'Untitled';
row._timestamp = ((row._timestamp || 0) * 1000) || startms;
map[row._mid] = row;
});
callback(null, map);
});
};
Exporter.getTopics = function(callback) {
return Exporter.getPaginatedTopics(0, -1, callback);
};
Exporter.getPaginatedTopics = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var err;
var prefix = Exporter.config('prefix');
var custom = Exporter.config('custom');
var importAttachments = custom && custom.importAttachments;
var startms = +new Date();
var query =
'SELECT '
+ 'tblTopics.DiscussionID AS _tid, '
// aka category id, or cid
+ 'tblTopics.CategoryID AS _cid, '
// this is the 'parent-post'
// see https://github.com/akhoury/nodebb-plugin-import#important-note-on-topics-and-posts
// I don't really need it since I just do a simple join and get its content, but I will include for the reference
// remember: this post is EXCLUDED in the getPosts() function
// + 'tblTopics.POST_ID AS _pid, ' // Don't need this for Vanilla
+ 'tblTopics.InsertUserID AS _uid, '
+ 'tblTopics.CountViews AS _viewcount, '
+ 'tblTopics.Name AS _title, '
+ 'UNIX_TIMESTAMP(tblTopics.DateInserted) AS _timestamp, '
+ 'UNIX_TIMESTAMP(tblTopics.DateUpdated) AS _edited, '
// maybe use that to skip
// + 'tblTopics.TOPIC_IS_APPROVED AS _approved, '
// todo: figure out what this means,
// + 'tblTopics.TOPIC_STATUS AS _status, ' // don't need this
+ 'tblTopics.Announce AS _pinned, ';
if (importAttachments) {
query += '(SELECT GROUP_CONCAT(CONCAT("/uploads/files", media.Path)) from GDN_Media AS media WHERE media.ForeignID = tblTopics.DiscussionID AND media.Type LIKE "image%" AND media.ForeignTable = "discussion") AS _images, '
+ '(SELECT GROUP_CONCAT(CONCAT("/uploads/files", media.Path)) from GDN_Media AS media WHERE media.ForeignID = tblTopics.DiscussionID AND media.Type NOT LIKE "image%" AND media.ForeignTable = "discussion") AS _attachments, '
}
// I dont need it, but if it should be 0 per UBB logic, since this post is not replying to anything, it's the parent-post of the topic
// + 'tblPosts.POST_PARENT_ID AS _post_replying_to, '
// this should be == to the _tid on top of this query
// + 'tblPosts.DiscussionID AS _post_tid, '
query += 'tblTopics.Body AS _content '
+ 'FROM ' + prefix + 'Discussion AS tblTopics '
// see
// + 'WHERE tblTopics.TOPIC_ID = tblPosts.TOPIC_ID '
// and this one must be a parent
// + 'AND ' + 'tblPosts.POST_PARENT_ID=0 '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// Exporter.log ('Topics query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize here
var map = {};
rows.forEach(function(row) {
row._title = row._title ? row._title[0].toUpperCase() + row._title.substr(1) : 'Untitled';
row._images = row._images ? row._images.split(',') : [];
row._attachments = row._attachments ? row._attachments.split(',') : [];
row._timestamp = ((row._timestamp || 0) * 1000) || startms;
map[row._tid] = row;
});
callback(null, map);
});
};
Exporter.getPosts = function(callback) {
return Exporter.getPaginatedPosts(0, -1, callback);
};
Exporter.getPaginatedPosts = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var err;
var prefix = Exporter.config('prefix');
var custom = Exporter.config('custom');
var importAttachments = custom && custom.importAttachments;
var startms = +new Date();
var query =
'SELECT '
+ 'tblPosts.CommentID AS _pid, '
+ 'tblPosts.DiscussionID AS _post_replying_to, '
+ 'tblPosts.DiscussionID AS _tid, '
+ 'UNIX_TIMESTAMP(tblPosts.DateInserted) AS _timestamp, '
+ 'UNIX_TIMESTAMP(tblPosts.DateUpdated) AS _edited, '
// + 'tblPosts.
// not being used
// + 'tblPosts.POST_SUBJECT AS _subject, '
+ 'tblPosts.Body AS _content, '
+ 'tblPosts.InsertUserID AS _uid, ';
if (importAttachments) {
query += '(SELECT GROUP_CONCAT(CONCAT("/uploads/files", media.Path)) from ' + prefix + 'Media AS media WHERE media.ForeignID = tblPosts.CommentID AND media.Type LIKE "image%" AND media.ForeignTable = "comment") AS _images, '
+ '(SELECT GROUP_CONCAT(CONCAT("/uploads/files", media.Path)) from ' + prefix + 'Media AS media WHERE media.ForeignID = tblPosts.CommentID AND media.Type NOT LIKE "image%" AND media.ForeignTable = "comment") AS _attachments, '
}
// I couldn't tell what's the different, they're all HTML to me
query += 'tblPosts.Format AS _markup ' // TODO have to convert this one to markup?, val is "html"
// maybe use this one to skip
// + 'tblPosts.POST_IS_APPROVED AS _approved '
+ 'FROM ' + prefix + 'Comment AS tblPosts ORDER BY DateInserted '
// this post cannot be a its topic's main post, it MUST be a reply-post
// see https://github.com/akhoury/nodebb-plugin-import#important-note-on-topics-and-posts
// + 'WHERE POST_PARENT_ID > 0 '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// Exporter.log ('Posts query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize here
var map = {};
rows.forEach(function(row) {
row._content = row._content || '';
row._images = row._images ? row._images.split(',') : [];
row._attachments = row._attachments ? row._attachments.split(',') : [];
row._timestamp = ((row._timestamp || 0) * 1000) || startms;
map[row._pid] = row;
});
callback(null, map);
});
};
Exporter.getVotes = function(callback) {
return Exporter.getPaginatedVotes(0, -1, callback);
};
Exporter.getPaginatedVotes = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var custom = Exporter.config('custom');
var kudosEnabled = custom && custom.importKudos;
if (!kudosEnabled) {
Exporter.warn('skipping votes import (enable with {"importKudos":true})');
callback(null, {});
return;
}
var err;
var prefix = Exporter.config('prefix');
var startms = +new Date();
var query =
'SELECT '
+ 'CONCAT(IFNULL(tblVotes.CommentID, "N"), "_", IFNULL(tblVotes.DiscussionID, "N"), "_", tblVotes.UserID) AS _vid, ' // no unique id, so had to make a composite key
+ 'tblVotes.CommentID AS _pid, '
+ 'tblVotes.DiscussionID AS _tid, '
+ 'tblVotes.UserID AS _uid, '
+ 'IF(tblVotes.Action = 2, -1, 1) AS _action '
+ 'FROM ' + prefix + 'Kudos AS tblVotes '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// console.log('Votes query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize votes here
var map = {};
rows.forEach(function(row) {
map[row._vid] = row;
});
callback(null, map);
});
};
Exporter.getBookmarks = function(callback) {
return Exporter.getPaginatedVotes(0, -1, callback);
};
Exporter.getPaginatedBookmarks = function(start, limit, callback) {
callback = !_.isFunction(callback) ? noop : callback;
var custom = Exporter.config('custom');
var importBookmarks = custom && custom.importBookmarks;
if (!importBookmarks) {
Exporter.warn('skipping bookmarks import (enable with {"importBookmarks": true}');
callback(null, {});
return;
}
var err;
var prefix = Exporter.config('prefix');
var startms = +new Date();
var query =
'SELECT '
+ 'CONCAT(tblBookmarks.UserID, "_", tblBookmarks.DiscussionID) AS _bid, ' // no unique id, so had to make a composite key
+ 'tblBookmarks.DiscussionID AS _tid, '
+ 'tblBookmarks.UserID AS _uid, '
+ 'tblBookmarks.CountComments AS _index '
+ 'FROM ' + prefix + 'UserDiscussion AS tblBookmarks '
+ (start >= 0 && limit >= 0 ? 'LIMIT ' + start + ',' + limit : '');
// console.log('Bookmarks query is: ' + query);
if (!Exporter.connection) {
err = {error: 'MySQL connection is not setup. Run setup(config) first'};
Exporter.error(err.error);
return callback(err);
}
Exporter.connection.query(query,
function(err, rows) {
if (err) {
Exporter.error(err);
return callback(err);
}
//normalize votes here
var map = {};
rows.forEach(function(row) {
map[row._bid] = row;
});
callback(null, map);
});
};
Exporter.teardown = function(callback) {
Exporter.log('teardown');
Exporter.connection.end();
Exporter.log('Done');
callback();
};
Exporter.testrun = function(config, callback) {
async.series([
function(next) {
Exporter.setup(config, next);
},
function(next) {
Exporter.getUsers(next);
},
function(next) {
Exporter.getCategories(next);
},
function(next) {
Exporter.getTopics(next);
},
function(next) {
Exporter.getPosts(next);
},
function(next) {
Exporter.teardown(next);
}
], callback);
};
Exporter.paginatedTestrun = function(config, callback) {
async.series([
function(next) {
Exporter.setup(config, next);
},
function(next) {
Exporter.getPaginatedUsers(0, 1000, next);
},
function(next) {
Exporter.getPaginatedCategories(0, 1000, next);
},
function(next) {
Exporter.getPaginatedTopics(0, 1000, next);
},
function(next) {
Exporter.getPaginatedPosts(1001, 2000, next);
},
function(next) {
Exporter.teardown(next);
}
], callback);
};
Exporter.warn = function() {
var args = _.toArray(arguments);
args.unshift(logPrefix);
console.warn.apply(console, args);
};
Exporter.log = function() {
var args = _.toArray(arguments);
args.unshift(logPrefix);
console.log.apply(console, args);
};
Exporter.error = function() {
var args = _.toArray(arguments);
args.unshift(logPrefix);
console.error.apply(console, args);
};
Exporter.config = function(config, val) {
if (config != null) {
if (typeof config === 'object') {
Exporter._config = config;
} else if (typeof config === 'string') {
if (val != null) {
Exporter._config = Exporter._config || {};
Exporter._config[config] = val;
}
return Exporter._config[config];
}
}
return Exporter._config;
};
// from Angular https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L11
Exporter.validateUrl = function(url) {
var pattern = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
return url && url.length < 2083 && url.match(pattern) ? url : '';
};
Exporter.truncateStr = function(str, len) {
if (typeof str != 'string') return str;
len = _.isNumber(len) && len > 3 ? len : 20;
return str.length <= len ? str : str.substr(0, len - 3) + '...';
};
Exporter.whichIsFalsy = function(arr) {
for (var i = 0; i < arr.length; i++) {
if (!arr[i])
return i;
}
return null;
};
})(module.exports);