Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

wordwrapjs

Package Overview
Dependencies
2
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    wordwrapjs

Word-wrapping for javascript.


Version published
Maintainers
1
Install size
42.6 kB
Created

Package description

What is wordwrapjs?

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.

What are wordwrapjs's main functionalities?

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);

Other packages similar to wordwrapjs

Readme

Source

view on npm npm module downloads Build Status Dependency Status js-standard-style

wordwrapjs

Word wrapping, with a few features.

  • multilingual - wraps any language using whitespace word separation.
  • force-break option
  • ignore pattern option (e.g. ansi escape sequences)
  • wraps hypenated words

Example
Wrap some sick bars in a 20 character column.

> wrap = require("wordwrapjs")

> bars = "I'm rapping. I'm rapping. I'm rap rap rapping. I'm rap rap rap rap rappity rapping."
> result = wrap(bars, { width: 20 })

result now looks like this:

I'm rapping. I'm
rapping. I'm rap rap
rapping. I'm rap rap
rap rap rappity
rapping.

By default, long words will not break. Unless you insist.

> 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' ]

wrap(text, [options]) ⇒ string

Kind: Exported function

ParamTypeDefaultDescription
textstringthe input text to wrap
[options]objectoptional config
[options.width]number30the max column width in characters
[options.ignore]RegExp | Array.<RegExp>one or more patterns to be ignored when sizing the newly wrapped lines. For example ignore: /\u001b.*?m/g will ignore unprintable ansi escape sequences.
[options.break]booleanif true, words exceeding the specified width will be forcefully broken
[options.eol]string"os.EOL"the desired new line character to use, defaults to os.EOL.

wrap.lines(text, [options]) ⇒ Array

returns the wrapped output as an array of lines, rather than a single string

Kind: static method of wrap

ParamTypeDescription
textstringthe input text to wrap
[options]objectsame options as wrap

Example

> bars = "I'm rapping. I'm rapping. I'm rap rap rapping. I'm rap rap rap rap rappity rapping."
> wrap.lines(bars)
[ "I'm rapping. I'm rapping. I'm",
  "rap rap rapping. I'm rap rap",
  "rap rap rappity rapping." ]

wrap.isWrappable(text) ⇒ boolean

Returns true if the input text is wrappable

Kind: static method of wrap

ParamTypeDescription
textstringinput text

wrap.getWords(text) ⇒ Array.<string>

Splits the input text returning an array of words

Kind: static method of wrap

ParamTypeDescription
textstringinput text

© 2015 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Keywords

FAQs

Last updated on 06 Aug 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc