npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wordwrapjs

v5.1.0

Published

Word-wrapping for javascript.

Downloads

5,838,505

Readme

view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style

wordwrapjs

Word wrapping for plain text.

Synopsis

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

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:

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>

API Reference

Wordwrap ⏏

Kind: Exported class

new Wordwrap(text, [options])

| Param | Type | Description | | --- | --- | --- | | text | string | The input text to wrap. | | [options] | WordwrapOptions | |

Wordwrap.wrap(text, [options])

Kind: static method of Wordwrap

| Param | Type | Description | | --- | --- | --- | | text | string | the input text to wrap | | [options] | WordwrapOptions | |

Wordwrap.lines(text, [options])

Wraps the input text, returning an array of strings (lines).

Kind: static method of Wordwrap

| Param | Type | Description | | --- | --- | --- | | text | string | input text | | [options] | WordwrapOptions | |

Wordwrap.isWrappable(text) ⇒ 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 |

Wordwrap.getChunks(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 |

Wordwrap~WordwrapOptions : Object

Wordwrap 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-21 Lloyd Brookes <[email protected]>. Documented by jsdoc-to-markdown.