Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
wordwrapjs
Advanced tools
Package description
The wordwrapjs package is a utility for wrapping words into a specified width. It's useful for formatting text output in command-line applications or anywhere where you need to control the flow of text to fit within certain boundaries.
Hard Wrapping
Hard wrapping ensures that the text is wrapped strictly at the specified width, even if it means breaking words apart.
const wordwrap = require('wordwrapjs');
let wrappedText = wordwrap.wrap('Some long text that needs to be wrapped', {width: 20});
console.log(wrappedText);
Soft Wrapping
Soft wrapping wraps text at the specified width but without breaking words. It moves the whole word to the next line if it doesn't fit.
const wordwrap = require('wordwrapjs');
let wrappedText = wordwrap.wrap('Some long text that needs to be wrapped', {width: 20, break: false});
console.log(wrappedText);
Custom Break Character
This feature allows specifying a custom break character for wrapping, which can be useful for adding hyphens or other characters when a word is split.
const wordwrap = require('wordwrapjs');
let wrappedText = wordwrap.wrap('Some long text that needs to be wrapped', {width: 20, break: true, cut: true});
console.log(wrappedText);
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.
Readme
Word wrapping, with a few features.
Wrap some text in a 20 character column.
> wordwrap = require('wordwrapjs')
> text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
> 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.
By default, long words will not break. Unless you set the break
option.
> 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' ]
string
boolean
Array.<string>
string
Kind: static method of WordWrap
Param | Type | Description |
---|---|---|
text | string | the input text to wrap |
[options] | object | optional configuration |
[options.width] | number | the max column width in characters (defaults to 30). |
[options.break] | boolean | if true, words exceeding the specified width will be forcefully broken |
[options.noTrim] | boolean | By default, each line output is trimmed. If noTrim is set, no line-trimming occurs - all whitespace from the input text is left in. |
Wraps the input text, returning an array of strings (lines).
Kind: static method of WordWrap
Param | Type | Description |
---|---|---|
text | string | input text |
options | object | Accepts same options as constructor. |
boolean
Returns 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 |
© 2015-17 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.
FAQs
Word-wrapping for javascript.
We found that wordwrapjs demonstrated a not healthy version release cadence and project activity because the last version was released 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.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).