pixl-cli 1.0.21 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/agents/string-width/.editorconfig +12 -0
- package/agents/string-width/.gitattributes +1 -0
- package/agents/string-width/.github/security.md +3 -0
- package/agents/string-width/.github/workflows/main.yml +22 -0
- package/agents/string-width/index.d.ts +39 -0
- package/agents/string-width/index.js +207 -0
- package/agents/string-width/index.test-d.ts +7 -0
- package/agents/string-width/license +9 -0
- package/agents/string-width/package.json +65 -0
- package/agents/string-width/readme.md +66 -0
- package/agents/string-width/test.js +339 -0
- package/agents/widest-line/.editorconfig +12 -0
- package/agents/widest-line/.gitattributes +1 -0
- package/agents/widest-line/.github/security.md +3 -0
- package/agents/widest-line/.github/workflows/main.yml +21 -0
- package/agents/widest-line/index.d.ts +12 -0
- package/agents/widest-line/index.js +11 -0
- package/agents/widest-line/license +9 -0
- package/agents/widest-line/package.json +60 -0
- package/agents/widest-line/readme.md +26 -0
- package/agents/widest-line/test.js +8 -0
- package/agents/word-wrap/.editorconfig +13 -0
- package/agents/word-wrap/.eslintrc.json +122 -0
- package/agents/word-wrap/.gitattributes +10 -0
- package/agents/word-wrap/.github/workflows/publish.yml +19 -0
- package/agents/word-wrap/.travis.yml +13 -0
- package/agents/word-wrap/.verb.md +114 -0
- package/agents/word-wrap/LICENSE +21 -0
- package/agents/word-wrap/README.md +201 -0
- package/agents/word-wrap/bower.json +60 -0
- package/agents/word-wrap/index.d.ts +50 -0
- package/agents/word-wrap/index.js +61 -0
- package/agents/word-wrap/package.json +77 -0
- package/agents/word-wrap/test.js +69 -0
- package/cli.js +17 -10
- package/package.json +3 -8
- package/test.js +20 -0
- package/util.js +15 -0
- package/width.js +75 -0
- package/wrap.js +141 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: Publish Package to npmjs
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v3
|
|
10
|
+
# Setup .npmrc file to publish to npm
|
|
11
|
+
- uses: actions/setup-node@v3
|
|
12
|
+
with:
|
|
13
|
+
node-version: '18.x'
|
|
14
|
+
registry-url: 'https://registry.npmjs.org'
|
|
15
|
+
- run: npm install
|
|
16
|
+
- run: npm run test
|
|
17
|
+
- run: npm publish
|
|
18
|
+
env:
|
|
19
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
## Usage
|
|
2
|
+
|
|
3
|
+
```js
|
|
4
|
+
var wrap = require('word-wrap');
|
|
5
|
+
|
|
6
|
+
wrap('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Results in:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing
|
|
13
|
+
elit, sed do eiusmod tempor incididunt ut labore
|
|
14
|
+
et dolore magna aliqua. Ut enim ad minim veniam,
|
|
15
|
+
quis nostrud exercitation ullamco laboris nisi ut
|
|
16
|
+
aliquip ex ea commodo consequat.
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## Options
|
|
21
|
+
|
|
22
|
+

|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### options.width
|
|
26
|
+
|
|
27
|
+
Type: `Number`
|
|
28
|
+
|
|
29
|
+
Default: `50`
|
|
30
|
+
|
|
31
|
+
The width of the text before wrapping to a new line.
|
|
32
|
+
|
|
33
|
+
**Example:**
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
wrap(str, {width: 60});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### options.indent
|
|
41
|
+
|
|
42
|
+
Type: `String`
|
|
43
|
+
|
|
44
|
+
Default: ` ` (two spaces)
|
|
45
|
+
|
|
46
|
+
The string to use at the beginning of each line.
|
|
47
|
+
|
|
48
|
+
**Example:**
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
wrap(str, {indent: ' '});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
### options.newline
|
|
56
|
+
|
|
57
|
+
Type: `String`
|
|
58
|
+
|
|
59
|
+
Default: `\n`
|
|
60
|
+
|
|
61
|
+
The string to use at the end of each line.
|
|
62
|
+
|
|
63
|
+
**Example:**
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
wrap(str, {newline: '\n\n'});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### options.escape
|
|
70
|
+
|
|
71
|
+
Type: `function`
|
|
72
|
+
|
|
73
|
+
Default: `function(str){return str;}`
|
|
74
|
+
|
|
75
|
+
An escape function to run on each line after splitting them.
|
|
76
|
+
|
|
77
|
+
**Example:**
|
|
78
|
+
|
|
79
|
+
```js
|
|
80
|
+
var xmlescape = require('xml-escape');
|
|
81
|
+
wrap(str, {
|
|
82
|
+
escape: function(string){
|
|
83
|
+
return xmlescape(string);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### options.trim
|
|
89
|
+
|
|
90
|
+
Type: `Boolean`
|
|
91
|
+
|
|
92
|
+
Default: `false`
|
|
93
|
+
|
|
94
|
+
Trim trailing whitespace from the returned string. This option is included since `.trim()` would also strip the leading indentation from the first line.
|
|
95
|
+
|
|
96
|
+
**Example:**
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
wrap(str, {trim: true});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### options.cut
|
|
103
|
+
|
|
104
|
+
Type: `Boolean`
|
|
105
|
+
|
|
106
|
+
Default: `false`
|
|
107
|
+
|
|
108
|
+
Break a word between any two letters when the word is longer than the specified width.
|
|
109
|
+
|
|
110
|
+
**Example:**
|
|
111
|
+
|
|
112
|
+
```js
|
|
113
|
+
wrap(str, {cut: true});
|
|
114
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2014-2016, Jon Schlinkert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# word-wrap [](https://www.npmjs.com/package/word-wrap) [](https://npmjs.org/package/word-wrap) [](https://npmjs.org/package/word-wrap) [](https://travis-ci.org/jonschlinkert/word-wrap)
|
|
2
|
+
|
|
3
|
+
> Wrap words to a specified length.
|
|
4
|
+
|
|
5
|
+
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Install with [npm](https://www.npmjs.com/):
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
$ npm install --save word-wrap
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
var wrap = require('word-wrap');
|
|
19
|
+
|
|
20
|
+
wrap('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Results in:
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
Lorem ipsum dolor sit amet, consectetur adipiscing
|
|
27
|
+
elit, sed do eiusmod tempor incididunt ut labore
|
|
28
|
+
et dolore magna aliqua. Ut enim ad minim veniam,
|
|
29
|
+
quis nostrud exercitation ullamco laboris nisi ut
|
|
30
|
+
aliquip ex ea commodo consequat.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Options
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
### options.width
|
|
38
|
+
|
|
39
|
+
Type: `Number`
|
|
40
|
+
|
|
41
|
+
Default: `50`
|
|
42
|
+
|
|
43
|
+
The width of the text before wrapping to a new line.
|
|
44
|
+
|
|
45
|
+
**Example:**
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
wrap(str, {width: 60});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### options.indent
|
|
52
|
+
|
|
53
|
+
Type: `String`
|
|
54
|
+
|
|
55
|
+
Default: `` (two spaces)
|
|
56
|
+
|
|
57
|
+
The string to use at the beginning of each line.
|
|
58
|
+
|
|
59
|
+
**Example:**
|
|
60
|
+
|
|
61
|
+
```js
|
|
62
|
+
wrap(str, {indent: ' '});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### options.newline
|
|
66
|
+
|
|
67
|
+
Type: `String`
|
|
68
|
+
|
|
69
|
+
Default: `\n`
|
|
70
|
+
|
|
71
|
+
The string to use at the end of each line.
|
|
72
|
+
|
|
73
|
+
**Example:**
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
wrap(str, {newline: '\n\n'});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### options.escape
|
|
80
|
+
|
|
81
|
+
Type: `function`
|
|
82
|
+
|
|
83
|
+
Default: `function(str){return str;}`
|
|
84
|
+
|
|
85
|
+
An escape function to run on each line after splitting them.
|
|
86
|
+
|
|
87
|
+
**Example:**
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
var xmlescape = require('xml-escape');
|
|
91
|
+
wrap(str, {
|
|
92
|
+
escape: function(string){
|
|
93
|
+
return xmlescape(string);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### options.trim
|
|
99
|
+
|
|
100
|
+
Type: `Boolean`
|
|
101
|
+
|
|
102
|
+
Default: `false`
|
|
103
|
+
|
|
104
|
+
Trim trailing whitespace from the returned string. This option is included since `.trim()` would also strip the leading indentation from the first line.
|
|
105
|
+
|
|
106
|
+
**Example:**
|
|
107
|
+
|
|
108
|
+
```js
|
|
109
|
+
wrap(str, {trim: true});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### options.cut
|
|
113
|
+
|
|
114
|
+
Type: `Boolean`
|
|
115
|
+
|
|
116
|
+
Default: `false`
|
|
117
|
+
|
|
118
|
+
Break a word between any two letters when the word is longer than the specified width.
|
|
119
|
+
|
|
120
|
+
**Example:**
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
wrap(str, {cut: true});
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## About
|
|
127
|
+
|
|
128
|
+
<details>
|
|
129
|
+
<summary><strong>Contributing</strong></summary>
|
|
130
|
+
|
|
131
|
+
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
|
|
132
|
+
|
|
133
|
+
</details>
|
|
134
|
+
|
|
135
|
+
<details>
|
|
136
|
+
<summary><strong>Running Tests</strong></summary>
|
|
137
|
+
|
|
138
|
+
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
|
|
139
|
+
|
|
140
|
+
```sh
|
|
141
|
+
$ npm install && npm test
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
</details>
|
|
145
|
+
|
|
146
|
+
<details>
|
|
147
|
+
<summary><strong>Building docs</strong></summary>
|
|
148
|
+
|
|
149
|
+
_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
|
|
150
|
+
|
|
151
|
+
To generate the readme, run the following command:
|
|
152
|
+
|
|
153
|
+
```sh
|
|
154
|
+
$ npm install -g verbose/verb#dev verb-generate-readme && verb
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
</details>
|
|
158
|
+
|
|
159
|
+
### Related projects
|
|
160
|
+
|
|
161
|
+
You might also be interested in these projects:
|
|
162
|
+
|
|
163
|
+
* [common-words](https://www.npmjs.com/package/common-words): Updated list (JSON) of the 100 most common words in the English language. Useful for… [more](https://github.com/jonschlinkert/common-words) | [homepage](https://github.com/jonschlinkert/common-words "Updated list (JSON) of the 100 most common words in the English language. Useful for excluding these words from arrays.")
|
|
164
|
+
* [shuffle-words](https://www.npmjs.com/package/shuffle-words): Shuffle the words in a string and optionally the letters in each word using the… [more](https://github.com/jonschlinkert/shuffle-words) | [homepage](https://github.com/jonschlinkert/shuffle-words "Shuffle the words in a string and optionally the letters in each word using the Fisher-Yates algorithm. Useful for creating test fixtures, benchmarking samples, etc.")
|
|
165
|
+
* [unique-words](https://www.npmjs.com/package/unique-words): Returns an array of unique words, or the number of occurrences of each word in… [more](https://github.com/jonschlinkert/unique-words) | [homepage](https://github.com/jonschlinkert/unique-words "Returns an array of unique words, or the number of occurrences of each word in a string or list.")
|
|
166
|
+
* [wordcount](https://www.npmjs.com/package/wordcount): Count the words in a string. Support for english, CJK and Cyrillic. | [homepage](https://github.com/jonschlinkert/wordcount "Count the words in a string. Support for english, CJK and Cyrillic.")
|
|
167
|
+
|
|
168
|
+
### Contributors
|
|
169
|
+
|
|
170
|
+
| **Commits** | **Contributor** |
|
|
171
|
+
| --- | --- |
|
|
172
|
+
| 47 | [jonschlinkert](https://github.com/jonschlinkert) |
|
|
173
|
+
| 7 | [OlafConijn](https://github.com/OlafConijn) |
|
|
174
|
+
| 3 | [doowb](https://github.com/doowb) |
|
|
175
|
+
| 2 | [aashutoshrathi](https://github.com/aashutoshrathi) |
|
|
176
|
+
| 2 | [lordvlad](https://github.com/lordvlad) |
|
|
177
|
+
| 2 | [hildjj](https://github.com/hildjj) |
|
|
178
|
+
| 1 | [danilosampaio](https://github.com/danilosampaio) |
|
|
179
|
+
| 1 | [2fd](https://github.com/2fd) |
|
|
180
|
+
| 1 | [leonard-thieu](https://github.com/leonard-thieu) |
|
|
181
|
+
| 1 | [mohd-akram](https://github.com/mohd-akram) |
|
|
182
|
+
| 1 | [toddself](https://github.com/toddself) |
|
|
183
|
+
| 1 | [wolfgang42](https://github.com/wolfgang42) |
|
|
184
|
+
| 1 | [zachhale](https://github.com/zachhale) |
|
|
185
|
+
|
|
186
|
+
### Author
|
|
187
|
+
|
|
188
|
+
**Jon Schlinkert**
|
|
189
|
+
|
|
190
|
+
* [GitHub Profile](https://github.com/jonschlinkert)
|
|
191
|
+
* [Twitter Profile](https://twitter.com/jonschlinkert)
|
|
192
|
+
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
|
|
193
|
+
|
|
194
|
+
### License
|
|
195
|
+
|
|
196
|
+
Copyright © 2023, [Jon Schlinkert](https://github.com/jonschlinkert).
|
|
197
|
+
Released under the [MIT License](LICENSE).
|
|
198
|
+
|
|
199
|
+
***
|
|
200
|
+
|
|
201
|
+
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 22, 2023._
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "word-wrap",
|
|
3
|
+
"description": "Wrap words to a specified length.",
|
|
4
|
+
"repository": "jonschlinkert/word-wrap",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/jonschlinkert/word-wrap",
|
|
7
|
+
"authors": [
|
|
8
|
+
"Jon Schlinkert (https://github.com/jonschlinkert)"
|
|
9
|
+
],
|
|
10
|
+
"main": [
|
|
11
|
+
"index.js"
|
|
12
|
+
],
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"gulp-format-md": "^0.1.11",
|
|
15
|
+
"mocha": "^3.2.0"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"break",
|
|
19
|
+
"carriage",
|
|
20
|
+
"line",
|
|
21
|
+
"new-line",
|
|
22
|
+
"newline",
|
|
23
|
+
"return",
|
|
24
|
+
"soft",
|
|
25
|
+
"text",
|
|
26
|
+
"word",
|
|
27
|
+
"word-wrap",
|
|
28
|
+
"words",
|
|
29
|
+
"wrap"
|
|
30
|
+
],
|
|
31
|
+
"version": "1.2.1",
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/jonschlinkert/word-wrap/issues"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"index.js"
|
|
37
|
+
],
|
|
38
|
+
"typings": "index.d.ts",
|
|
39
|
+
"ignore": [
|
|
40
|
+
"actual",
|
|
41
|
+
"bower_components",
|
|
42
|
+
"fixtures",
|
|
43
|
+
"node_modules",
|
|
44
|
+
"temp",
|
|
45
|
+
"test",
|
|
46
|
+
"test.js",
|
|
47
|
+
"tmp"
|
|
48
|
+
],
|
|
49
|
+
"types": "index.d.ts",
|
|
50
|
+
"contributors": [
|
|
51
|
+
"Danilo Sampaio <danilo.sampaio@gmail.com> (localhost:8080)",
|
|
52
|
+
"Fede Ramirez <i@2fd.me> (https://2fd.github.io)",
|
|
53
|
+
"Joe Hildebrand <joe-github@cursive.net> (https://twitter.com/hildjj)",
|
|
54
|
+
"Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)",
|
|
55
|
+
"Todd Kennedy (https://tck.io)",
|
|
56
|
+
"Waldemar Reusch (https://github.com/lordvlad)",
|
|
57
|
+
"Wolfgang Faust (http://www.linestarve.com)",
|
|
58
|
+
"Zach Hale <zachhale@gmail.com> (http://zachhale.com)"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wrap words to a specified length.
|
|
3
|
+
*/
|
|
4
|
+
export = wrap;
|
|
5
|
+
|
|
6
|
+
declare function wrap(str: string, options?: wrap.IOptions): string;
|
|
7
|
+
|
|
8
|
+
declare namespace wrap {
|
|
9
|
+
export interface IOptions {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The width of the text before wrapping to a new line.
|
|
13
|
+
* @default ´50´
|
|
14
|
+
*/
|
|
15
|
+
width?: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The string to use at the beginning of each line.
|
|
19
|
+
* @default ´ ´ (two spaces)
|
|
20
|
+
*/
|
|
21
|
+
indent?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The string to use at the end of each line.
|
|
25
|
+
* @default ´\n´
|
|
26
|
+
*/
|
|
27
|
+
newline?: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* An escape function to run on each line after splitting them.
|
|
31
|
+
* @default (str: string) => string;
|
|
32
|
+
*/
|
|
33
|
+
escape?: (str: string) => string;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Trim trailing whitespace from the returned string.
|
|
37
|
+
* This option is included since .trim() would also strip
|
|
38
|
+
* the leading indentation from the first line.
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
trim?: boolean;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Break a word between any two letters when the word is longer
|
|
45
|
+
* than the specified width.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
cut?: boolean;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* word-wrap <https://github.com/jonschlinkert/word-wrap>
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2014-2023, Jon Schlinkert.
|
|
5
|
+
* Released under the MIT License.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function trimEnd(str) {
|
|
9
|
+
let lastCharPos = str.length - 1;
|
|
10
|
+
let lastChar = str[lastCharPos];
|
|
11
|
+
while(lastChar === ' ' || lastChar === '\t') {
|
|
12
|
+
lastChar = str[--lastCharPos];
|
|
13
|
+
}
|
|
14
|
+
return str.substring(0, lastCharPos + 1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function trimTabAndSpaces(str) {
|
|
18
|
+
const lines = str.split('\n');
|
|
19
|
+
const trimmedLines = lines.map((line) => trimEnd(line));
|
|
20
|
+
return trimmedLines.join('\n');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = function(str, options) {
|
|
24
|
+
options = options || {};
|
|
25
|
+
if (str == null) {
|
|
26
|
+
return str;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var width = options.width || 50;
|
|
30
|
+
var indent = (typeof options.indent === 'string')
|
|
31
|
+
? options.indent
|
|
32
|
+
: ' ';
|
|
33
|
+
|
|
34
|
+
var newline = options.newline || '\n' + indent;
|
|
35
|
+
var escape = typeof options.escape === 'function'
|
|
36
|
+
? options.escape
|
|
37
|
+
: identity;
|
|
38
|
+
|
|
39
|
+
var regexString = '.{1,' + width + '}';
|
|
40
|
+
if (options.cut !== true) {
|
|
41
|
+
regexString += '([\\s\u200B]+|$)|[^\\s\u200B]+?([\\s\u200B]+|$)';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var re = new RegExp(regexString, 'g');
|
|
45
|
+
var lines = str.match(re) || [];
|
|
46
|
+
var result = indent + lines.map(function(line) {
|
|
47
|
+
if (line.slice(-1) === '\n') {
|
|
48
|
+
line = line.slice(0, line.length - 1);
|
|
49
|
+
}
|
|
50
|
+
return escape(line);
|
|
51
|
+
}).join(newline);
|
|
52
|
+
|
|
53
|
+
if (options.trim === true) {
|
|
54
|
+
result = trimTabAndSpaces(result);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
function identity(str) {
|
|
60
|
+
return str;
|
|
61
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "word-wrap",
|
|
3
|
+
"description": "Wrap words to a specified length.",
|
|
4
|
+
"version": "1.2.5",
|
|
5
|
+
"homepage": "https://github.com/jonschlinkert/word-wrap",
|
|
6
|
+
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
|
|
7
|
+
"contributors": [
|
|
8
|
+
"Danilo Sampaio <danilo.sampaio@gmail.com> (localhost:8080)",
|
|
9
|
+
"Fede Ramirez <i@2fd.me> (https://2fd.github.io)",
|
|
10
|
+
"Joe Hildebrand <joe-github@cursive.net> (https://twitter.com/hildjj)",
|
|
11
|
+
"Jon Schlinkert <jon.schlinkert@sellside.com> (http://twitter.com/jonschlinkert)",
|
|
12
|
+
"Todd Kennedy (https://tck.io)",
|
|
13
|
+
"Waldemar Reusch (https://github.com/lordvlad)",
|
|
14
|
+
"Wolfgang Faust (http://www.linestarve.com)",
|
|
15
|
+
"Zach Hale <zachhale@gmail.com> (http://zachhale.com)"
|
|
16
|
+
],
|
|
17
|
+
"repository": "jonschlinkert/word-wrap",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/jonschlinkert/word-wrap/issues"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"files": [
|
|
23
|
+
"index.js",
|
|
24
|
+
"index.d.ts"
|
|
25
|
+
],
|
|
26
|
+
"main": "index.js",
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=0.10.0"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"test": "mocha"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"gulp-format-md": "^0.1.11",
|
|
35
|
+
"mocha": "^3.2.0"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"break",
|
|
39
|
+
"carriage",
|
|
40
|
+
"line",
|
|
41
|
+
"new-line",
|
|
42
|
+
"newline",
|
|
43
|
+
"return",
|
|
44
|
+
"soft",
|
|
45
|
+
"text",
|
|
46
|
+
"word",
|
|
47
|
+
"word-wrap",
|
|
48
|
+
"words",
|
|
49
|
+
"wrap"
|
|
50
|
+
],
|
|
51
|
+
"typings": "index.d.ts",
|
|
52
|
+
"verb": {
|
|
53
|
+
"toc": false,
|
|
54
|
+
"layout": "default",
|
|
55
|
+
"tasks": [
|
|
56
|
+
"readme"
|
|
57
|
+
],
|
|
58
|
+
"plugins": [
|
|
59
|
+
"gulp-format-md"
|
|
60
|
+
],
|
|
61
|
+
"lint": {
|
|
62
|
+
"reflinks": true
|
|
63
|
+
},
|
|
64
|
+
"related": {
|
|
65
|
+
"list": [
|
|
66
|
+
"common-words",
|
|
67
|
+
"shuffle-words",
|
|
68
|
+
"unique-words",
|
|
69
|
+
"wordcount"
|
|
70
|
+
]
|
|
71
|
+
},
|
|
72
|
+
"reflinks": [
|
|
73
|
+
"verb",
|
|
74
|
+
"verb-generate-readme"
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('mocha');
|
|
4
|
+
var assert = require('assert');
|
|
5
|
+
var wrap = require('./');
|
|
6
|
+
|
|
7
|
+
var str = 'A project without documentation is like a project that doesn\'t exist. Verb solves this by making it dead simple to generate project documentation, using simple markdown templates, with zero configuration required. ';
|
|
8
|
+
|
|
9
|
+
describe('wrap', function () {
|
|
10
|
+
it('should use defaults to wrap words in the given string:', function () {
|
|
11
|
+
assert.equal(wrap(str), ' A project without documentation is like a project \n that doesn\'t exist. Verb solves this by making it \n dead simple to generate project documentation, \n using simple markdown templates, with zero \n configuration required. ');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('should wrap to the specified width:', function () {
|
|
15
|
+
assert.equal(wrap(str, {width: 40}), ' A project without documentation is like \n a project that doesn\'t exist. Verb \n solves this by making it dead simple to \n generate project documentation, using \n simple markdown templates, with zero \n configuration required. ');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should indent the specified amount:', function () {
|
|
19
|
+
assert.equal(wrap(str, {indent: ' '}), ' A project without documentation is like a project \n that doesn\'t exist. Verb solves this by making it \n dead simple to generate project documentation, \n using simple markdown templates, with zero \n configuration required. ');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should use the given string for newlines:', function () {
|
|
23
|
+
assert.equal(wrap(str, {newline: '\n\n-'}), ' A project without documentation is like a project \n\n-that doesn\'t exist. Verb solves this by making it \n\n-dead simple to generate project documentation, \n\n-using simple markdown templates, with zero \n\n-configuration required. ');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should run the escape function on each line', function () {
|
|
27
|
+
assert.equal(
|
|
28
|
+
wrap(str, {escape: function(e) {return e.replace('\'', '\\\'')}}),
|
|
29
|
+
' A project without documentation is like a project \n that doesn\\\'t exist. Verb solves this by making it \n dead simple to generate project documentation, \n using simple markdown templates, with zero \n configuration required. '
|
|
30
|
+
)
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should trim trailing whitespace:', function () {
|
|
34
|
+
assert.equal(wrap(str, {trim: true}), ' A project without documentation is like a project\n that doesn\'t exist. Verb solves this by making it\n dead simple to generate project documentation,\n using simple markdown templates, with zero\n configuration required.');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should trim trailing whitespace (even for empty lines):', function () {
|
|
38
|
+
assert.equal(wrap("a \n\nb \n \nc\t", {trim: true}), ' a\n\n b\n\n c');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('should handle strings with just newlines', function () {
|
|
42
|
+
assert.equal(wrap('\r\n', {indent: '\r\n', width: 18}), '\r\n');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('should handle newlines that occur at the same position as `options.width`', function () {
|
|
46
|
+
assert.equal(wrap('asdfg\nqwert', {width:5}), ' asdfg\n qwert');
|
|
47
|
+
assert.equal(wrap('aaaaaa\nbbbbbb\ncccccc', {width:6}), ' aaaaaa\n bbbbbb\n cccccc');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('should handle strings that break where there are multiple spaces', function() {
|
|
51
|
+
assert.equal(wrap('foo foo. bar', {width:8}), ' foo foo. \n bar');
|
|
52
|
+
assert.equal(wrap('foo foo. bar', {width:8, trim: true}), ' foo foo.\n bar');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should cut one long word', function() {
|
|
56
|
+
assert.equal(wrap('Supercalifragilisticexpialidocious', {width:24, cut:true}), ' Supercalifragilisticexpi\n alidocious');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should cut long words', function() {
|
|
60
|
+
assert.equal(wrap('Supercalifragilisticexpialidocious and Supercalifragilisticexpialidocious', {width:24, cut:true}), ' Supercalifragilisticexpi\n alidocious and Supercali\n fragilisticexpialidociou\n s');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should wrap on zero space characters', function () {
|
|
64
|
+
assert.equal(
|
|
65
|
+
wrap('Supercalifragilistic\u200Bexpialidocious', {width: 24}),
|
|
66
|
+
' Supercalifragilistic\u200B\n expialidocious'
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
});
|