Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

181 righe
5.3 KiB

3 anni fa
  1. # word-wrap [![NPM version](https://img.shields.io/npm/v/word-wrap.svg?style=flat)](https://www.npmjs.com/package/word-wrap) [![NPM monthly downloads](https://img.shields.io/npm/dm/word-wrap.svg?style=flat)](https://npmjs.org/package/word-wrap) [![NPM total downloads](https://img.shields.io/npm/dt/word-wrap.svg?style=flat)](https://npmjs.org/package/word-wrap) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/word-wrap.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/word-wrap)
  2. > Wrap words to a specified length.
  3. ## Install
  4. Install with [npm](https://www.npmjs.com/):
  5. ```sh
  6. $ npm install --save word-wrap
  7. ```
  8. ## Usage
  9. ```js
  10. var wrap = require('word-wrap');
  11. 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.');
  12. ```
  13. Results in:
  14. ```
  15. Lorem ipsum dolor sit amet, consectetur adipiscing
  16. elit, sed do eiusmod tempor incididunt ut labore
  17. et dolore magna aliqua. Ut enim ad minim veniam,
  18. quis nostrud exercitation ullamco laboris nisi ut
  19. aliquip ex ea commodo consequat.
  20. ```
  21. ## Options
  22. ![image](https://cloud.githubusercontent.com/assets/383994/6543728/7a381c08-c4f6-11e4-8b7d-b6ba197569c9.png)
  23. ### options.width
  24. Type: `Number`
  25. Default: `50`
  26. The width of the text before wrapping to a new line.
  27. **Example:**
  28. ```js
  29. wrap(str, {width: 60});
  30. ```
  31. ### options.indent
  32. Type: `String`
  33. Default: `` (two spaces)
  34. The string to use at the beginning of each line.
  35. **Example:**
  36. ```js
  37. wrap(str, {indent: ' '});
  38. ```
  39. ### options.newline
  40. Type: `String`
  41. Default: `\n`
  42. The string to use at the end of each line.
  43. **Example:**
  44. ```js
  45. wrap(str, {newline: '\n\n'});
  46. ```
  47. ### options.escape
  48. Type: `function`
  49. Default: `function(str){return str;}`
  50. An escape function to run on each line after splitting them.
  51. **Example:**
  52. ```js
  53. var xmlescape = require('xml-escape');
  54. wrap(str, {
  55. escape: function(string){
  56. return xmlescape(string);
  57. }
  58. });
  59. ```
  60. ### options.trim
  61. Type: `Boolean`
  62. Default: `false`
  63. Trim trailing whitespace from the returned string. This option is included since `.trim()` would also strip the leading indentation from the first line.
  64. **Example:**
  65. ```js
  66. wrap(str, {trim: true});
  67. ```
  68. ### options.cut
  69. Type: `Boolean`
  70. Default: `false`
  71. Break a word between any two letters when the word is longer than the specified width.
  72. **Example:**
  73. ```js
  74. wrap(str, {cut: true});
  75. ```
  76. ## About
  77. ### Related projects
  78. * [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.")
  79. * [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.")
  80. * [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.")
  81. * [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.")
  82. ### Contributing
  83. Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
  84. ### Contributors
  85. | **Commits** | **Contributor** |
  86. | --- | --- |
  87. | 43 | [jonschlinkert](https://github.com/jonschlinkert) |
  88. | 2 | [lordvlad](https://github.com/lordvlad) |
  89. | 2 | [hildjj](https://github.com/hildjj) |
  90. | 1 | [danilosampaio](https://github.com/danilosampaio) |
  91. | 1 | [2fd](https://github.com/2fd) |
  92. | 1 | [toddself](https://github.com/toddself) |
  93. | 1 | [wolfgang42](https://github.com/wolfgang42) |
  94. | 1 | [zachhale](https://github.com/zachhale) |
  95. ### Building docs
  96. _(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.)_
  97. To generate the readme, run the following command:
  98. ```sh
  99. $ npm install -g verbose/verb#dev verb-generate-readme && verb
  100. ```
  101. ### Running tests
  102. 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:
  103. ```sh
  104. $ npm install && npm test
  105. ```
  106. ### Author
  107. **Jon Schlinkert**
  108. * [github/jonschlinkert](https://github.com/jonschlinkert)
  109. * [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
  110. ### License
  111. Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
  112. Released under the [MIT License](LICENSE).
  113. ***
  114. _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on June 02, 2017._