Get rid of formatLongString in favor of _.chop

This commit is contained in:
Juan Cruz Viotti 2014-12-09 14:35:45 -04:00
parent 95e3e7b8b7
commit 37797f3416
3 changed files with 2 additions and 36 deletions

View File

@ -1,4 +1,5 @@
_ = require('lodash')
_.str = require('underscore.string')
resin = require('../resin')
helpers = require('../helpers/helpers')
cli = require('../cli/cli')
@ -24,7 +25,7 @@ exports.info = (id) ->
if not key?
resin.errors.handle(new resin.errors.NotFound("key #{id}"))
key.public_key = '\n' + helpers.formatLongString(key.public_key, resin.settings.get('sshKeyWidth'))
key.public_key = '\n' + _.chop(key.public_key, resin.settings.get('sshKeyWidth')).join('\n')
resin.log.out(ui.widgets.table.vertical(key, _.identity, [ 'ID', 'Title', 'Public Key' ]))
exports.remove = (id) ->

View File

@ -1,14 +1,6 @@
url = require('url')
_ = require('lodash')
resin = require('../resin')
# TODO: Use _.chop from underscore.string
exports.formatLongString = (string, n) ->
return string if not n?
splitRegexp = new RegExp(".{1,#{n}}", 'g')
splittedString = string.match(splitRegexp)
return splittedString.join('\n')
exports.isDeviceUUIDValid = (uuid, callback) ->
resin.models.device.getAll (error, devices) ->
return callback?(error) if error?

View File

@ -6,33 +6,6 @@ resin = require('../resin')
describe 'Helpers:', ->
describe '#formatLongString()', ->
it 'should format a string', ->
result = helpers.formatLongString('1234567812345678', 4)
expect(result).to.equal('1234\n5678\n1234\n5678')
it 'should return the same string if n is null/undefined', ->
for value in [ undefined, null ]
result = helpers.formatLongString('1234567890', value)
expect(result).to.equal('1234567890')
it 'should throw an error if input is not a string', ->
for value in [
undefined
null
[]
{}
123
]
fn = _.partial(helpers.formatLongString, value, 4)
expect(fn).to.throw
it 'should return the same string if n > string.length', ->
string = '1234567812345678'
result = helpers.formatLongString(string, string.length + 1)
expect(result).to.equal(string)
describe '#isDeviceUUIDValid()', ->
devices = [