Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wordwrapjs

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wordwrapjs - npm Package Compare versions

Comparing version 1.1.0 to 1.1.1

35

lib/wordwrapjs.js

@@ -9,2 +9,6 @@ 'use strict'

- multilingual - wraps any language using whitespace word separation.
- force-break long words
- ignore patterns (e.g. ansi escape sequences)
@module wordwrapjs

@@ -77,3 +81,3 @@ @example

var words = text.split(/\s+/)
var words = text.match(/(\S+|\r\n?|\n)/g) || []

@@ -100,16 +104,23 @@ var lineLength = 0

/* for each word, either extend the current `line` or create a new one */
words.forEach(function (word) {
var wordLength = options.ignore
? replaceIgnored(word, options.ignore).length
: word.length
if (/^(\r\n?|\n)$/.test(word)) {
lines.push(line || '')
line = ''
lineLength = 0
} else {
var wordLength = options.ignore
? replaceIgnored(word, options.ignore).length
: word.length
lineLength += wordLength + (line ? 1 : 0)
lineLength += wordLength + (line ? 1 : 0)
if (lineLength > options.width) {
/* Can't fit word on line, cache line and create new one */
if (line) lines.push(line)
line = word
lineLength = wordLength
} else {
line += (line ? ' ' : '') + word
if (lineLength > options.width) {
/* Can't fit word on line, cache line and create new one */
if (line) lines.push(line)
line = word
lineLength = wordLength
} else {
line += (line ? ' ' : '') + word
}
}

@@ -116,0 +127,0 @@ })

{
"name": "wordwrapjs",
"author": "Lloyd Brookes <75pound@gmail.com>",
"version": "1.1.0",
"version": "1.1.1",
"description": "Word-wrapping for javascript.",

@@ -14,2 +14,3 @@ "repository": "https://github.com/75lb/wordwrapjs.git",

"word",
"line",
"wrap",

@@ -24,3 +25,2 @@ "text",

"test": "tape test/*.js",
"lint": "jshint lib/*.js bin/*.js test/*.js; echo",
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo"

@@ -27,0 +27,0 @@ },

@@ -11,2 +11,6 @@ [![view on npm](http://img.shields.io/npm/v/wordwrapjs.svg)](https://www.npmjs.org/package/wordwrapjs)

- multilingual - wraps any language using whitespace word separation.
- force-break long words
- ignore patterns (e.g. ansi escape sequences)
**Example**

@@ -13,0 +17,0 @@ Wrap some sick bars in a 20 character column.

@@ -90,1 +90,39 @@ var test = require('tape')

})
test('wrap.lines(text): respect existing linebreaks', function (t) {
t.deepEqual(
wrap.lines('one\ntwo three four', { width: 8 }),
[ 'one', 'two', 'three', 'four' ]
)
t.deepEqual(
wrap.lines('one \n \n two three four', { width: 8 }),
[ 'one', '', 'two', 'three', 'four' ]
)
t.deepEqual(
wrap.lines('one\rtwo three four', { width: 8 }),
[ 'one', 'two', 'three', 'four' ]
)
t.deepEqual(
wrap.lines('one\r\ntwo three four', { width: 8 }),
[ 'one', 'two', 'three', 'four' ]
)
t.end()
})
test('wrap.lines(text): multilingual', function (t) {
t.deepEqual(
wrap.lines('Può parlare più lentamente?', { width: 10 }),
[ 'Può', 'parlare', 'più', 'lentamente?' ]
)
t.deepEqual(
wrap.lines('один два три', { width: 4 }),
[ 'один', 'два', 'три' ]
)
t.end()
})

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc