Skip to content

Commit

Permalink
Merge pull request #7 from cto-af/expose-defaults
Browse files Browse the repository at this point in the history
Expose default options
  • Loading branch information
hildjj committed Jun 11, 2023
2 parents 68c9344 + 3d8e4bc commit 58f29f3
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 57 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Wrap lines using Unicode UAX #14 line breaking rules.
npm install @cto.af/linewrap
```

## CLI

A command line interface is available: [@cto.af/linewrap-cli](https://github.com/cto-af/linewrap-cli)

## API

```js
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/search.js

Large diffs are not rendered by default.

152 changes: 116 additions & 36 deletions docs/classes/index.LineWrap.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/classes/spacebreaker.SpaceBreaker.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h4>Hierarchy</h4>
<ul class="tsd-hierarchy">
<li><span class="target">SpaceBreaker</span></li></ul></li></ul></section><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/710424a/lib/spacebreaker.js#L138">lib/spacebreaker.js:138</a></li></ul></aside>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/68c9344/lib/spacebreaker.js#L138">lib/spacebreaker.js:138</a></li></ul></aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<details class="tsd-index-content tsd-index-accordion" open><summary class="tsd-accordion-summary tsd-index-summary">
Expand Down Expand Up @@ -82,7 +82,7 @@ <h4 class="tsd-returns-title">Returns <a href="spacebreaker.SpaceBreaker.html" c
<div class="tsd-comment tsd-typography"></div><aside class="tsd-sources">
<p>Overrides Rules.constructor</p>
<ul>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/710424a/lib/spacebreaker.js#L143">lib/spacebreaker.js:143</a></li></ul></aside></li></ul></section></section>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/68c9344/lib/spacebreaker.js#L143">lib/spacebreaker.js:143</a></li></ul></aside></li></ul></section></section>
<section class="tsd-panel-group tsd-member-group">
<h2>Properties</h2>
<section class="tsd-panel tsd-member tsd-is-private tsd-is-inherited tsd-is-external"><a id="_private" class="tsd-anchor"></a>
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<li><a href="index.html">index</a></li></ul>
<h1>Module index</h1></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/710424a/lib/index.js#L1">lib/index.js:1</a></li></ul></aside>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/68c9344/lib/index.js#L1">lib/index.js:1</a></li></ul></aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<h3 class="tsd-index-heading uppercase">Index</h3>
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/spacebreaker.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<li><a href="spacebreaker.html">spacebreaker</a></li></ul>
<h1>Module spacebreaker</h1></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/710424a/lib/spacebreaker.js#L1">lib/spacebreaker.js:1</a></li></ul></aside>
<li>Defined in <a href="https://github.com/cto-af/linewrap/blob/68c9344/lib/spacebreaker.js#L1">lib/spacebreaker.js:1</a></li></ul></aside>
<section class="tsd-panel-group tsd-index-group">
<section class="tsd-panel tsd-index-panel">
<h3 class="tsd-index-heading uppercase">Index</h3>
Expand Down
42 changes: 26 additions & 16 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class LineWrap {
* @typedef {object} LineWrapOptions
* @prop {string} [ellipsis='\u{2026}'] String to use when long word is
* truncated with LineWrap.OVERFLOW_CLIP.
* @prop {boolean} [example7] Turn on the extra linebreak rules from
* Example 7 of UAX #14.
* @prop {number} [firstCol=NaN] If indentFirst is false, how many columns
* was the first line already indented? If NaN, use the indent width,
* in graphemes. If indentFirst is true, this is ignored.
Expand Down Expand Up @@ -115,6 +117,7 @@ export class LineWrap {
* @prop {LineWrap.OVERFLOW_VISIBLE| LineWrap.OVERFLOW_CLIP|
* LineWrap.OVERFLOW_ANYWHERE} [overflow=LineWrapOptions.OVERFLOW_VISIBLE]
* What to do with words that are longer than the line width?
* @prop {boolean} [verbose] Turn on verbose logging for debugging purposes.
* @prop {number} [width=80] Maximum number of graphemes per line,
* *including* indentation.
* @prop {EscapeString} [escape] Function to escape the input string. The
Expand All @@ -123,6 +126,28 @@ export class LineWrap {
* to an identity transform.
*/

/**
* @type {Required<LineWrapOptions>}
*/
static DEFAULT_OPTIONS = {
escape: noEscape,
ellipsis: '\u{2026}',
example7: false,
firstCol: NaN,
hyphen: '-',
indent: '',
indentChar: ' ',
indentEmpty: false,
indentFirst: true,
isNewline: DEFAULT_IS_NEWLINE,
locale: DEFAULT_LOCALE,
newline: '\n',
newlineReplacement: ' ',
overflow: LineWrap.OVERFLOW_VISIBLE,
verbose: false,
width: 80,
}

/**
* @param {LineWrapOptions} [opts={}]
*/
Expand All @@ -131,22 +156,7 @@ export class LineWrap {
* @type {Required<LineWrapOptions>}
*/
this.#opts = {
escape: noEscape,
ellipsis: '\u{2026}',
example7: false,
firstCol: NaN,
hyphen: '-',
indent: '',
indentChar: ' ',
indentEmpty: false,
indentFirst: true,
isNewline: DEFAULT_IS_NEWLINE,
locale: DEFAULT_LOCALE,
newline: '\n',
newlineReplacement: ' ',
overflow: LineWrap.OVERFLOW_VISIBLE,
verbose: false,
width: 80,
...LineWrap.DEFAULT_OPTIONS,
...opts,
}
this.#rules = new SpaceBreaker({
Expand Down

0 comments on commit 58f29f3

Please sign in to comment.