wordwrapjs
Advanced tools
Comparing version
{ | ||
"name": "wordwrapjs", | ||
"author": "Lloyd Brookes <75pound@gmail.com>", | ||
"version": "1.2.1", | ||
"version": "2.0.0-0", | ||
"description": "Word-wrapping for javascript.", | ||
"repository": "https://github.com/75lb/wordwrapjs.git", | ||
"license": "MIT", | ||
"main": "./lib/wordwrapjs.js", | ||
"main": "index.js", | ||
"keywords": [ | ||
@@ -17,17 +17,21 @@ "word", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.12.0" | ||
}, | ||
"scripts": { | ||
"test": "test-runner test/*.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs lib/*.js > README.md; echo" | ||
"test": "node test.js", | ||
"docs": "jsdoc2md -t jsdoc2md/README.hbs src/lib/*.js > README.md; echo", | ||
"es5": "rm -rf es5 && babel --presets babel-preset-es2015 --no-comments src --out-dir es5" | ||
}, | ||
"devDependencies": { | ||
"core-assert": "^0.2.0", | ||
"jsdoc-to-markdown": "^2.0.0-alpha", | ||
"test-runner": "~0.1.9" | ||
"babel-preset-es2015": "^6.18.0", | ||
"core-assert": "^0.2.1", | ||
"jsdoc-to-markdown": "^2.0.1", | ||
"test-runner": "~0.2.5" | ||
}, | ||
"dependencies": { | ||
"array-back": "^1.0.3", | ||
"typical": "^2.5.0" | ||
"feature-detect-es6": "^1.3.1", | ||
"reduce-flatten": "^1.0.1", | ||
"typical": "^2.6.0" | ||
} | ||
} |
110
README.md
@@ -7,20 +7,20 @@ [](https://www.npmjs.org/package/wordwrapjs) | ||
<a name="module_wordwrapjs"></a> | ||
# wordwrapjs | ||
## 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 | ||
- multilingual - wraps any language that uses whitespace for word separation. | ||
**Example** | ||
Wrap some sick bars in a 20 character column. | ||
## Synopsis | ||
Wrap some text in a 20 character column. | ||
```js | ||
> wrap = require("wordwrapjs") | ||
> wordwrap = 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 }) | ||
> 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 }) | ||
``` | ||
@@ -30,12 +30,15 @@ | ||
``` | ||
I'm rapping. I'm | ||
rapping. I'm rap rap | ||
rapping. I'm rap rap | ||
rap rap rappity | ||
rapping. | ||
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 insist. | ||
By default, long words will not break. Unless you set the `break` option. | ||
```js | ||
> url = "https://github.com/75lb/wordwrapjs" | ||
> url = 'https://github.com/75lb/wordwrapjs' | ||
@@ -49,48 +52,47 @@ > wrap.lines(url, { width: 18 }) | ||
## API Reference | ||
* [wordwrapjs](#module_wordwrapjs) | ||
* [wrap(text, [options])](#exp_module_wordwrapjs--wrap) ⇒ <code>string</code> ⏏ | ||
* [.lines(text, [options])](#module_wordwrapjs--wrap.lines) ⇒ <code>Array</code> | ||
* [.isWrappable(text)](#module_wordwrapjs--wrap.isWrappable) ⇒ <code>boolean</code> | ||
* [.getWords(text)](#module_wordwrapjs--wrap.getWords) ⇒ <code>Array.<string></code> | ||
* [WordWrap](#exp_module_wordwrapjs--WordWrap) ⏏ | ||
* [.wrap(text, [options])](#module_wordwrapjs--WordWrap.wrap) ⇒ <code>string</code> | ||
* [.lines(text, options)](#module_wordwrapjs--WordWrap.lines) | ||
* [.isWrappable(text)](#module_wordwrapjs--WordWrap.isWrappable) ⇒ <code>boolean</code> | ||
* [.getChunks(text)](#module_wordwrapjs--WordWrap.getChunks) ⇒ <code>Array.<string></code> | ||
<a name="exp_module_wordwrapjs--wrap"></a> | ||
<a name="exp_module_wordwrapjs--WordWrap"></a> | ||
### wrap(text, [options]) ⇒ <code>string</code> ⏏ | ||
**Kind**: Exported function | ||
### WordWrap ⏏ | ||
**Kind**: Exported class | ||
<a name="module_wordwrapjs--WordWrap.wrap"></a> | ||
| Param | Type | Default | Description | | ||
| --- | --- | --- | --- | | ||
| text | <code>string</code> | | the input text to wrap | | ||
| [options] | <code>object</code> | | optional config | | ||
| [options.width] | <code>number</code> | <code>30</code> | the max column width in characters | | ||
| [options.ignore] | <code>RegExp</code> | <code>Array.<RegExp></code> | | 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] | <code>boolean</code> | | if true, words exceeding the specified `width` will be forcefully broken | | ||
| [options.eol] | <code>string</code> | <code>"os.EOL"</code> | the desired new line character to use, defaults to [os.EOL](https://nodejs.org/api/os.html#os_os_eol). | | ||
#### wordwrap.wrap(text, [options]) ⇒ <code>string</code> | ||
**Kind**: static method of <code>[WordWrap](#exp_module_wordwrapjs--WordWrap)</code> | ||
<a name="module_wordwrapjs--wrap.lines"></a> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| text | <code>string</code> | the input text to wrap | | ||
| [options] | <code>object</code> | optional configuration | | ||
| [options.width] | <code>number</code> | the max column width in characters (defaults to 30). | | ||
| [options.break] | <code>boolean</code> | if true, words exceeding the specified `width` will be forcefully broken | | ||
| [options.noTrim] | <code>boolean</code> | By default, each line output is trimmed. If `noTrim` is set, no line-trimming occurs - all whitespace from the input text is left in. | | ||
#### wrap.lines(text, [options]) ⇒ <code>Array</code> | ||
returns the wrapped output as an array of lines, rather than a single string | ||
<a name="module_wordwrapjs--WordWrap.lines"></a> | ||
**Kind**: static method of <code>[wrap](#exp_module_wordwrapjs--wrap)</code> | ||
#### wordwrap.lines(text, options) | ||
Wraps the input text, returning an array of strings (lines). | ||
**Kind**: static method of <code>[WordWrap](#exp_module_wordwrapjs--WordWrap)</code> | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| text | <code>string</code> | the input text to wrap | | ||
| [options] | <code>object</code> | same options as [wrap](#module_wordwrapjs) | | ||
| text | <code>string</code> | input text | | ||
| options | <code>object</code> | Accepts same options as constructor. | | ||
**Example** | ||
```js | ||
> 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." ] | ||
``` | ||
<a name="module_wordwrapjs--wrap.isWrappable"></a> | ||
<a name="module_wordwrapjs--WordWrap.isWrappable"></a> | ||
#### wrap.isWrappable(text) ⇒ <code>boolean</code> | ||
Returns true if the input text is wrappable | ||
#### wordwrap.isWrappable(text) ⇒ <code>boolean</code> | ||
Returns true if the input text would be wrapped if passed into `.wrap()`. | ||
**Kind**: static method of <code>[wrap](#exp_module_wordwrapjs--wrap)</code> | ||
**Kind**: static method of <code>[WordWrap](#exp_module_wordwrapjs--WordWrap)</code> | ||
@@ -101,8 +103,8 @@ | Param | Type | Description | | ||
<a name="module_wordwrapjs--wrap.getWords"></a> | ||
<a name="module_wordwrapjs--WordWrap.getChunks"></a> | ||
#### wrap.getWords(text) ⇒ <code>Array.<string></code> | ||
Splits the input text returning an array of words | ||
#### wordwrap.getChunks(text) ⇒ <code>Array.<string></code> | ||
Splits the input text into an array of words and whitespace. | ||
**Kind**: static method of <code>[wrap](#exp_module_wordwrapjs--wrap)</code> | ||
**Kind**: static method of <code>[WordWrap](#exp_module_wordwrapjs--WordWrap)</code> | ||
@@ -116,2 +118,2 @@ | Param | Type | Description | | ||
© 2015 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). | ||
© 2015-16 Lloyd Brookes \<75pound@gmail.com\>. Documented by [jsdoc-to-markdown](https://github.com/jsdoc2md/jsdoc-to-markdown). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
26097
62.16%14
55.56%496
53.56%115
1.77%4
100%4
33.33%2
100%1
Infinity%+ Added
+ Added
+ Added
+ Added
Updated