
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
wordwrapjs
Advanced tools
Word wrapping for plain text.
Wrap some text in a 20 character column.
import wordwrap from 'wordwrapjs'
const text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
const result = wordwrap.wrap(text, { width: 20 })
result now looks like this:
Lorem ipsum dolor
sit amet,
consectetur
adipiscing elit, sed
do eiusmod tempor
incididunt ut labore
et dolore magna
aliqua.
Force long words to wrap by setting the break flag.
Welcome to Node.js v16.6.2.
> wrap = require('wordwrapjs')
> url = 'https://github.com/75lb/wordwrapjs'
> wrap.lines(url, { width: 18 })
[ 'https://github.com/75lb/wordwrapjs' ]
> wrap.lines(url, { width: 18, break: true })
[ 'https://github.com', '/75lb/wordwrapjs' ]
This library is compatible with Node.js, the Web and any style of module loader. It can be loaded anywhere, natively without transpilation.
Node.js:
const wordwrap = require('wordwrapjs')
Within Node.js with ECMAScript Module support enabled:
import wordwrap from 'wordwrapjs'
Within an modern browser ECMAScript Module:
import wordwrap from './node_modules/wordwrapjs/dist/index.mjs'
Old browser (adds window.wordwrapjs):
<script nomodule src="./node_modules/wordwrapjs/dist/index.js"></script>
booleanArray.<string>Object| Param | Type | Description |
|---|---|---|
| text | string | The input text to wrap. |
| [options] | WordwrapOptions |
Kind: static method of Wordwrap
| Param | Type | Description |
|---|---|---|
| text | string | the input text to wrap |
| [options] | WordwrapOptions |
Wraps the input text, returning an array of strings (lines).
Kind: static method of Wordwrap
| Param | Type | Description |
|---|---|---|
| text | string | input text |
| [options] | WordwrapOptions |
booleanReturns true if the input text would be wrapped if passed into .wrap().
Kind: static method of Wordwrap
| Param | Type | Description |
|---|---|---|
| text | string | input text |
Array.<string>Splits the input text into an array of words and whitespace.
Kind: static method of Wordwrap
| Param | Type | Description |
|---|---|---|
| text | string | input text |
ObjectWordwrap options.
Kind: inner typedef of Wordwrap
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [width] | number | 30 | The max column width in characters. |
| [break] | boolean | false | If true, words exceeding the specified width will be forcefully broken |
| [noTrim] | boolean | false | By default, each line output is trimmed. If noTrim is set, no line-trimming occurs - all whitespace from the input text is left in. |
| [eol] | string | "'\n'" | The end of line character to use. Defaults to \n. |
© 2015-25 Lloyd Brookes <opensource@75lb.com>. Documented by jsdoc-to-markdown.
The 'word-wrap' package provides similar functionality to 'wordwrapjs' with a focus on wrapping plain text with indentation, prefix, and cut options. It's a simple and lightweight solution for text wrapping needs.
The 'wrap-ansi' package is designed to wrap text with ANSI escape codes, which is useful for colored CLI text. It handles wrapping text containing ANSI escape codes without breaking the color sequences.
FAQs
Word-wrapping for javascript.
The npm package wordwrapjs receives a total of 3,615,473 weekly downloads. As such, wordwrapjs popularity was classified as popular.
We found that wordwrapjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.