Skip to content

Commit f4ed6fe

Browse files
yolopunklovell
andcommitted
Apply suggestions from code review
fix: text.wrap property should be word-char be based on libvip Co-authored-by: Lovell Fuller <[email protected]>
1 parent d8f7d77 commit f4ed6fe

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

docs/api-constructor.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages`
6666
| [options.text.dpi] | <code>number</code> | <code>72</code> | the resolution (size) at which to render the text. Does not take effect if `height` is specified. |
6767
| [options.text.rgba] | <code>boolean</code> | <code>false</code> | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`. |
6868
| [options.text.spacing] | <code>number</code> | <code>0</code> | text line height in points. Will use the font line height if none is specified. |
69-
| [options.text.wrap] | <code>string</code> | <code>&quot;&#x27;word&#x27;&quot;</code> | word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none'. |
69+
| [options.text.wrap] | <code>string</code> | <code>&quot;&#x27;word&#x27;&quot;</code> | word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'. |
7070

7171
**Example**
7272
```js

lib/constructor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ const debuglog = util.debuglog('sharp');
166166
* @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified.
167167
* @param {boolean} [options.text.rgba=false] - set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `<span foreground="red">Red!</span>`.
168168
* @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified.
169-
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none'.
169+
* @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'.
170170
* @returns {Sharp}
171171
* @throws {Error} Invalid parameters
172172
*/

lib/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ declare namespace sharp {
10171017
rgba?: boolean;
10181018
/** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */
10191019
spacing?: number;
1020-
/** Word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none' */
1020+
/** Word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none' */
10211021
wrap?: TextWrap;
10221022
}
10231023

@@ -1613,7 +1613,7 @@ declare namespace sharp {
16131613

16141614
type TextAlign = 'left' | 'centre' | 'center' | 'right';
16151615

1616-
type TextWrap = 'word' | 'char' | 'wordChar' | 'none';
1616+
type TextWrap = 'word' | 'char' | 'word-char' | 'none';
16171617

16181618
type TileContainer = 'fs' | 'zip';
16191619

lib/input.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) {
345345
}
346346
}
347347
if (is.defined(inputOptions.text.wrap)) {
348-
if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'wordChar', 'none'])) {
348+
if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'word-char', 'none'])) {
349349
inputDescriptor.textWrap = inputOptions.text.wrap;
350350
} else {
351-
throw is.invalidParameterError('text.wrap', 'one of: word, char, wordChar, none', inputOptions.text.wrap);
351+
throw is.invalidParameterError('text.wrap', 'one of: word, char, word-char, none', inputOptions.text.wrap);
352352
}
353353
}
354354
delete inputDescriptor.buffer;

test/types/sharp.test-d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ sharp({
595595
rgba: true,
596596
justify: true,
597597
spacing: 10,
598-
wrap: 'wordChar',
598+
wrap: 'word-char',
599599
},
600600
})
601601
.png()

test/unit/text.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,21 @@ describe('Text to image', function () {
319319

320320
it('valid wrap throws', () => {
321321
assert.doesNotThrow(() => sharp({ text: { text: 'text', wrap: 'none' } }));
322-
assert.doesNotThrow(() => sharp({ text: { text: 'text', wrap: 'wordChar' } }));
322+
assert.doesNotThrow(() => sharp({ text: { text: 'text', wrap: 'word-char' } }));
323323
});
324324

325325
it('invalid wrap throws', () => {
326326
assert.throws(
327327
() => sharp({ text: { text: 'text', wrap: 1 } }),
328-
/Expected one of: word, char, wordChar, none for text\.wrap but received 1 of type number/
328+
/Expected one of: word, char, word-char, none for text\.wrap but received 1 of type number/
329329
);
330330
assert.throws(
331331
() => sharp({ text: { text: 'text', wrap: false } }),
332-
/Expected one of: word, char, wordChar, none for text\.wrap but received false of type boolean/
332+
/Expected one of: word, char, word-char, none for text\.wrap but received false of type boolean/
333333
);
334334
assert.throws(
335335
() => sharp({ text: { text: 'text', wrap: 'invalid' } }),
336-
/Expected one of: word, char, wordChar, none for text\.wrap but received invalid of type string/
336+
/Expected one of: word, char, word-char, none for text\.wrap but received invalid of type string/
337337
);
338338
});
339339
});

0 commit comments

Comments
 (0)