https://github.com/75lb/wordwrapjs
Word-wrapping for javascript.
https://github.com/75lb/wordwrapjs
Last synced: about 1 year ago
JSON representation
Word-wrapping for javascript.
- Host: GitHub
- URL: https://github.com/75lb/wordwrapjs
- Owner: 75lb
- License: mit
- Created: 2015-08-26T21:37:53.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2024-11-16T12:46:44.000Z (over 1 year ago)
- Last Synced: 2025-04-12T14:16:56.195Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 262 KB
- Stars: 161
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.hbs
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.org/package/wordwrapjs)
[](https://www.npmjs.org/package/wordwrapjs)
[](https://github.com/75lb/wordwrapjs/network/dependents?dependent_type=REPOSITORY)
[](https://github.com/75lb/wordwrapjs/network/dependents?dependent_type=PACKAGE)
[](https://github.com/75lb/wordwrapjs/actions/workflows/node.js.yml)
[](https://github.com/feross/standard)
# wordwrapjs
Word wrapping for plain text.
## Synopsis
Wrap some text in a 20 character column.
```js
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' ]
```
## Load anywhere
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:
```js
const wordwrap = require('wordwrapjs')
```
Within Node.js with ECMAScript Module support enabled:
```js
import wordwrap from 'wordwrapjs'
```
Within an modern browser ECMAScript Module:
```js
import wordwrap from './node_modules/wordwrapjs/dist/index.mjs'
```
Old browser (adds `window.wordwrapjs`):
```html
```
## API Reference
{{#module name="wordwrapjs"}}
{{>body~}}
{{>member-index~}}
{{>members~}}
{{/module}}
* * *
© 2015-25 Lloyd Brookes \. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown).