Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aashutoshrathi authored Dec 2, 2023
2 parents b04aa64 + 207044e commit 09faf9d
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 45 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Publish Package to npmjs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm install
- run: npm run test
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ wrap(str, {width: 60});

Type: `String`

Default: `` (none)
Default: ` ` (two spaces)

The string to use at the beginning of each line.

Expand Down
77 changes: 48 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

> Wrap words to a specified length.
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

Install with [npm](https://www.npmjs.com/):
Expand Down Expand Up @@ -77,7 +79,7 @@ wrap(str, {width: 60});

Type: `String`

Default: `` (none)
Default: `` (two spaces)

The string to use at the beginning of each line.

Expand Down Expand Up @@ -150,31 +152,26 @@ wrap(str, {cut: true});

## About

### Related projects
<details>
<summary><strong>Contributing</strong></summary>

* [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.")
* [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.")
* [unique-words](https://www.npmjs.com/package/unique-words): Return the unique words in a string or array. | [homepage](https://github.com/jonschlinkert/unique-words "Return the unique words in a string or array.")
* [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.")
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Contributing
</details>

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
<details>
<summary><strong>Running Tests</strong></summary>

### Contributors
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:

```sh
$ npm install && npm test
```

| **Commits** | **Contributor** |
| --- | --- |
| 43 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [lordvlad](https://github.com/lordvlad) |
| 2 | [hildjj](https://github.com/hildjj) |
| 1 | [danilosampaio](https://github.com/danilosampaio) |
| 1 | [2fd](https://github.com/2fd) |
| 1 | [toddself](https://github.com/toddself) |
| 1 | [wolfgang42](https://github.com/wolfgang42) |
| 1 | [zachhale](https://github.com/zachhale) |
</details>

### Building docs
<details>
<summary><strong>Building docs</strong></summary>

_(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.)_

Expand All @@ -184,26 +181,48 @@ To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests
</details>

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:
### Related projects

```sh
$ npm install && npm test
```
You might also be interested in these projects:

* [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.")
* [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.")
* [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.")
* [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.")

### Contributors

| **Commits** | **Contributor** |
| --- | --- |
| 47 | [jonschlinkert](https://github.com/jonschlinkert) |
| 7 | [OlafConijn](https://github.com/OlafConijn) |
| 3 | [doowb](https://github.com/doowb) |
| 2 | [aashutoshrathi](https://github.com/aashutoshrathi) |
| 2 | [lordvlad](https://github.com/lordvlad) |
| 2 | [hildjj](https://github.com/hildjj) |
| 1 | [danilosampaio](https://github.com/danilosampaio) |
| 1 | [2fd](https://github.com/2fd) |
| 1 | [leonard-thieu](https://github.com/leonard-thieu) |
| 1 | [mohd-akram](https://github.com/mohd-akram) |
| 1 | [toddself](https://github.com/toddself) |
| 1 | [wolfgang42](https://github.com/wolfgang42) |
| 1 | [zachhale](https://github.com/zachhale) |

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)
* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Copyright © 2023, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 02, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on July 22, 2023._
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ declare namespace wrap {

/**
* The string to use at the beginning of each line.
* @default ´´ (none)
* @default ´ ´ (two spaces)
*/
indent?: string;

Expand Down
13 changes: 11 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@
* Released under the MIT License.
*/

function trimEnd(str) {
let lastCharPos = str.length - 1;
let lastChar = str[lastCharPos];
while(lastChar === ' ' || lastChar === '\t') {
lastChar = str[--lastCharPos];
}
return str.substring(0, lastCharPos + 1);
}

function trimTabAndSpaces(str) {
const lines = str.split('\n');
const trimmedLines = lines.map((line) => line.trimEnd());
const trimmedLines = lines.map((line) => trimEnd(line));
return trimmedLines.join('\n');
}

Expand All @@ -20,7 +29,7 @@ module.exports = function(str, options) {
var width = options.width || 50;
var indent = (typeof options.indent === 'string')
? options.indent
: '';
: ' ';

var newline = options.newline || '\n' + indent;
var escape = typeof options.escape === 'function'
Expand Down
28 changes: 16 additions & 12 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,62 @@ var str = 'A project without documentation is like a project that doesn\'t exist

describe('wrap', function () {
it('should use defaults to wrap words in the given string:', function () {
assert.equal(wrap(str), 'A project without documentation is like a project \nthat doesn\'t exist. Verb solves this by making it \ndead simple to generate project documentation, \nusing simple markdown templates, with zero \nconfiguration required. ');
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. ');
});

it('should wrap to the specified width:', function () {
assert.equal(wrap(str, {width: 40}), 'A project without documentation is like \na project that doesn\'t exist. Verb \nsolves this by making it dead simple to \ngenerate project documentation, using \nsimple markdown templates, with zero \nconfiguration required. ');
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. ');
});

it('should indent the specified amount:', function () {
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. ');
});

it('should use the given string for newlines:', function () {
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. ');
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. ');
});

it('should run the escape function on each line', function () {
assert.equal(
wrap(str, {escape: function(e) {return e.replace('\'', '\\\'')}}),
'A project without documentation is like a project \nthat doesn\\\'t exist. Verb solves this by making it \ndead simple to generate project documentation, \nusing simple markdown templates, with zero \nconfiguration required. '
' 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. '
)
});

it('should trim trailing whitespace:', function () {
assert.equal(wrap(str, {trim: true}), 'A project without documentation is like a project\nthat doesn\'t exist. Verb solves this by making it\ndead simple to generate project documentation,\nusing simple markdown templates, with zero\nconfiguration required.');
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.');
});

it('should trim trailing whitespace (even for empty lines):', function () {
assert.equal(wrap("a \n\nb \n \nc\t", {trim: true}), ' a\n\n b\n\n c');
});

it('should handle strings with just newlines', function () {
assert.equal(wrap('\r\n', {indent: '\r\n', width: 18}), '\r\n');
});

it('should handle newlines that occur at the same position as `options.width`', function () {
assert.equal(wrap('asdfg\nqwert', {width:5}), 'asdfg\nqwert');
assert.equal(wrap('aaaaaa\nbbbbbb\ncccccc', {width:6}), 'aaaaaa\nbbbbbb\ncccccc');
assert.equal(wrap('asdfg\nqwert', {width:5}), ' asdfg\n qwert');
assert.equal(wrap('aaaaaa\nbbbbbb\ncccccc', {width:6}), ' aaaaaa\n bbbbbb\n cccccc');
});

it('should handle strings that break where there are multiple spaces', function() {
assert.equal(wrap('foo foo. bar', {width:8}), 'foo foo. \nbar');
assert.equal(wrap('foo foo. bar', {width:8, trim: true}), 'foo foo.\nbar');
assert.equal(wrap('foo foo. bar', {width:8}), ' foo foo. \n bar');
assert.equal(wrap('foo foo. bar', {width:8, trim: true}), ' foo foo.\n bar');
});

it('should cut one long word', function() {
assert.equal(wrap('Supercalifragilisticexpialidocious', {width:24, cut:true}), 'Supercalifragilisticexpi\nalidocious');
assert.equal(wrap('Supercalifragilisticexpialidocious', {width:24, cut:true}), ' Supercalifragilisticexpi\n alidocious');
});

it('should cut long words', function() {
assert.equal(wrap('Supercalifragilisticexpialidocious and Supercalifragilisticexpialidocious', {width:24, cut:true}), 'Supercalifragilisticexpi\nalidocious and Supercali\nfragilisticexpialidociou\ns');
assert.equal(wrap('Supercalifragilisticexpialidocious and Supercalifragilisticexpialidocious', {width:24, cut:true}), ' Supercalifragilisticexpi\n alidocious and Supercali\n fragilisticexpialidociou\n s');
});

it('should wrap on zero space characters', function () {
assert.equal(
wrap('Supercalifragilistic\u200Bexpialidocious', {width: 24}),
'Supercalifragilistic\u200B\nexpialidocious'
' Supercalifragilistic\u200B\n expialidocious'
);
});
});

0 comments on commit 09faf9d

Please sign in to comment.