How to use the wordwrap.hard function in wordwrap

To help you get started, we’ve selected a few wordwrap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NCBI-Hackathons / deSRA / web / app / node_modules / cliui / index.js View on Github external
row.forEach(function (col, c) {
    // leave room for left and right padding.
    col.width = widths[c]
    if (_this.wrap) wrapped = wrap.hard(_this._negatePadding(col))(col.text).split('\n')
    else wrapped = col.text.split('\n')

    // add top and bottom padding.
    if (col.padding) {
      for (i = 0; i < (col.padding[top] || 0); i++) wrapped.unshift('')
      for (i = 0; i < (col.padding[bottom] || 0); i++) wrapped.push('')
    }

    wrapped.forEach(function (str, r) {
      if (!rrows[r]) rrows.push([])

      rrow = rrows[r]

      for (var i = 0; i < c; i++) {
        if (rrow[i] === undefined) rrow.push('')
      }
github Azure / azure-xplat-cli / lib / util / utilsCore.js View on Github external
// 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.
//

var _ = require('underscore');
var fs = require('fs');
var path = require('path');
var read = require('read');
var wrap = require('wordwrap').hard(0, 75);
var util = require('util');
var Constants = require('./constants');
var userHome = require('user-home');

exports.camelcase = function (flag) {
  return flag.split('-').reduce(function (str, word) {
    return str + word[0].toUpperCase() + word.slice(1);
  });
};

exports.ignoreCaseEquals = function (a, b) {
  return a === b ||
    (a !== null && a !== undefined &&
    b !== null && b !== undefined &&
    (a.toLowerCase() === b.toLowerCase())) === true;
};
github node-gh / gh / src / logger.ts View on Github external
import * as fs from 'fs'
import * as handlebars from 'handlebars'
import * as moment from 'moment'
import * as path from 'path'
import * as wordwrap from 'wordwrap'
import * as S from 'sanctuary'

const testing = process.env.NODE_ENV === 'testing'

if (testing || process.env.COLOR === 'false') {
    color.disable()
}

export const colors = color

const wrap = wordwrap.hard(0, 80)

function stripHandlebarsNewLine(str) {
    return str.replace(/[\s\t\r\n](\{\{[#\/])/g, '$1')
}

export function debug(...args) {
    if (!process.env.GH_VERBOSE) {
        return
    }

    if (typeof args[0] === 'string') {
        args[0] = `DEBUG: ${args[0]}`
        console.log(...args)
        return
    }
github timwis / vizwit / src / components / WrappingText.vue View on Github external
lines () {
      if (!this.text) return []

      return wrap.hard(0, this.charactersPerLine)(this.text).split('\n')
    }
  }
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / commands.js View on Github external
display.session._message = function (message) {
  var text = wordwrap.hard(0, padded)(message.plain)
  var address = message.senderAddr.toString()
  var txId = colors.grey(message.txId)
  if (message.origin === 'remote') {
    address = wordwrap.hard(padded - address.length, padded)(address)
    txId = colors.grey(wordwrap.hard(padded - message.txId.length, padded)(message.txId))
    if (text.length < padded) {
      text = wordwrap.hard(padded - text.length, padded)(text)
    }
  }
  address = colors.red(address)
  return [[address], [txId], [text]]
}
github Azure / azure-xplat-cli / lib / util / logging.js View on Github external
reportFormat.forEach(function (item) {
    var title = item[0] + ':';
    var field = item[1];
    var formatter = item[2] || defaultFormat;

    var value = getProperty(data, field);
    if (formatter instanceof Array) {
      outfn(spaces(indentation) + toWidth(title, headerWidth));
      doReport(indentation + headerWidth, formatter, value, outfn);
    } else {
      var leftIndentation = 'verbose: '.length + indentation + headerWidth;
      var formatted = wrap.hard(leftIndentation, maxWidth)(formatter(value));
      formatted = spaces(indentation) + toWidth(title, headerWidth) +
        formatted.slice(leftIndentation);
      outfn(formatted);
    }
  });
}
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / commands.js View on Github external
display.session = function (session, addr) {
  var table = new Table({
    head: ['Chat ' + session.txId],
    colWidths: [columns],
    truncate: false
  })
  var senderAddr = session.senderAddr.toString()
  var isSender = senderAddr === addr.toString()
  var sender = isSender ? session.receiverAddr.toString() : senderAddr
  var initAddr = session.init.senderAddr
  var isInit = initAddr.toString() === addr.toString()
  var theirAuth = session.getTheirAuth()
  theirAuth = theirAuth ? theirAuth.txId : 'Not accepted'
  theirAuth = wordwrap.hard(padded - theirAuth.length, padded)(theirAuth)
  theirAuth = colors.grey(theirAuth)
  var ourAuth = session.getOurAuth()
  ourAuth = ourAuth ? colors.grey(ourAuth.txId) : colors.red('Accept?')
  var firstAuth = isInit ? ourAuth : theirAuth
  var secondAuth = isInit ? theirAuth : ourAuth
  var messages = session.messages.length + ' Message'
  messages += session.messages.length !== 1 ? 's' : ''
  var newMessages = session.unreadMessages ? session.unreadMessages + ' New / ' : ''
  var info = colors.green(newMessages) + colors.grey(messages)
  var infoWidth = sender.length + messages.length + newMessages.length
  var right = wordwrap.hard(padded - infoWidth, padded)
  table.push([firstAuth], [secondAuth], [sender + right(info)])
  process.stderr.cursorTo(0)
  process.stderr.write(table.toString())
  display.newLine()
}
github microsoft / appcenter-cli / src / util / interaction / out.ts View on Github external
reportFormat.forEach(function (item) {
    const title = item[0] + ":";
    const field = item[1];
    const formatter = item[2] || defaultFormat;

    const value = getProperty(data, field);
    if (formatter instanceof Array) {
      outfn(spaces(indentation) + toWidth(title, headerWidth));
      doReport(indentation + headerWidth, formatter, value, outfn);
    } else {
      const leftIndentation = "verbose: ".length + indentation + headerWidth;
      let formatted = wrap.hard(leftIndentation, maxWidth)(formatter(value));
      formatted = spaces(indentation) + toWidth(title, headerWidth) +
        formatted.slice(leftIndentation);
      outfn(formatted);
    }
  });
}
github 17Q4MX2hmktmpuUKHFuoRmS5MfB5XPbhod / dropzone-lib / lib / commands.js View on Github external
var initAddr = session.init.senderAddr
  var isInit = initAddr.toString() === addr.toString()
  var theirAuth = session.getTheirAuth()
  theirAuth = theirAuth ? theirAuth.txId : 'Not accepted'
  theirAuth = wordwrap.hard(padded - theirAuth.length, padded)(theirAuth)
  theirAuth = colors.grey(theirAuth)
  var ourAuth = session.getOurAuth()
  ourAuth = ourAuth ? colors.grey(ourAuth.txId) : colors.red('Accept?')
  var firstAuth = isInit ? ourAuth : theirAuth
  var secondAuth = isInit ? theirAuth : ourAuth
  var messages = session.messages.length + ' Message'
  messages += session.messages.length !== 1 ? 's' : ''
  var newMessages = session.unreadMessages ? session.unreadMessages + ' New / ' : ''
  var info = colors.green(newMessages) + colors.grey(messages)
  var infoWidth = sender.length + messages.length + newMessages.length
  var right = wordwrap.hard(padded - infoWidth, padded)
  table.push([firstAuth], [secondAuth], [sender + right(info)])
  process.stderr.cursorTo(0)
  process.stderr.write(table.toString())
  display.newLine()
}

wordwrap

Wrap those words. Show them at what columns to start and stop.

MIT
Latest version published 9 years ago

Package Health Score

65 / 100
Full package analysis

Popular wordwrap functions