From d8f7d7717fe2fea5572bd281d566610035ff26e4 Mon Sep 17 00:00:00 2001 From: Aaron Che Date: Thu, 14 Mar 2024 14:24:11 +0000 Subject: [PATCH 1/2] fix: typo error text.wrap --- docs/api-constructor.md | 2 +- lib/constructor.js | 2 +- lib/index.d.ts | 4 ++-- test/types/sharp.test-d.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api-constructor.md b/docs/api-constructor.md index 18ca29b1b..bed43fe39 100644 --- a/docs/api-constructor.md +++ b/docs/api-constructor.md @@ -66,7 +66,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages` | [options.text.dpi] | number | 72 | the resolution (size) at which to render the text. Does not take effect if `height` is specified. | | [options.text.rgba] | boolean | false | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `Red!`. | | [options.text.spacing] | number | 0 | text line height in points. Will use the font line height if none is specified. | -| [options.text.wrap] | string | "'word'" | word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'. | +| [options.text.wrap] | string | "'word'" | word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none'. | **Example** ```js diff --git a/lib/constructor.js b/lib/constructor.js index da2154304..bd09110a5 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -166,7 +166,7 @@ const debuglog = util.debuglog('sharp'); * @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified. * @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 `Red!`. * @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified. - * @param {string} [options.text.wrap='word'] - word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none'. + * @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'. * @returns {Sharp} * @throws {Error} Invalid parameters */ diff --git a/lib/index.d.ts b/lib/index.d.ts index c68c848db..4457c0cc7 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1017,7 +1017,7 @@ declare namespace sharp { rgba?: boolean; /** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */ spacing?: number; - /** Word wrapping style when width is provided, one of: 'word', 'char', 'charWord' (prefer char, fallback to word) or 'none' */ + /** Word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none' */ wrap?: TextWrap; } @@ -1613,7 +1613,7 @@ declare namespace sharp { type TextAlign = 'left' | 'centre' | 'center' | 'right'; - type TextWrap = 'word' | 'char' | 'charWord' | 'none'; + type TextWrap = 'word' | 'char' | 'wordChar' | 'none'; type TileContainer = 'fs' | 'zip'; diff --git a/test/types/sharp.test-d.ts b/test/types/sharp.test-d.ts index 9fa00e28d..be9557c9b 100644 --- a/test/types/sharp.test-d.ts +++ b/test/types/sharp.test-d.ts @@ -595,7 +595,7 @@ sharp({ rgba: true, justify: true, spacing: 10, - wrap: 'charWord', + wrap: 'wordChar', }, }) .png() From f4ed6fe347848fac7526d787f26922503ff6d2c9 Mon Sep 17 00:00:00 2001 From: Aaron Che Date: Sun, 17 Mar 2024 11:32:14 +0800 Subject: [PATCH 2/2] Apply suggestions from code review fix: text.wrap property should be word-char be based on libvip Co-authored-by: Lovell Fuller --- docs/api-constructor.md | 2 +- lib/constructor.js | 2 +- lib/index.d.ts | 4 ++-- lib/input.js | 4 ++-- test/types/sharp.test-d.ts | 2 +- test/unit/text.js | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/api-constructor.md b/docs/api-constructor.md index bed43fe39..22bab9f16 100644 --- a/docs/api-constructor.md +++ b/docs/api-constructor.md @@ -66,7 +66,7 @@ where the overall height is the `pageHeight` multiplied by the number of `pages` | [options.text.dpi] | number | 72 | the resolution (size) at which to render the text. Does not take effect if `height` is specified. | | [options.text.rgba] | boolean | false | set this to true to enable RGBA output. This is useful for colour emoji rendering, or support for pango markup features like `Red!`. | | [options.text.spacing] | number | 0 | text line height in points. Will use the font line height if none is specified. | -| [options.text.wrap] | string | "'word'" | word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none'. | +| [options.text.wrap] | string | "'word'" | word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none'. | **Example** ```js diff --git a/lib/constructor.js b/lib/constructor.js index bd09110a5..dd2c4e394 100644 --- a/lib/constructor.js +++ b/lib/constructor.js @@ -166,7 +166,7 @@ const debuglog = util.debuglog('sharp'); * @param {number} [options.text.dpi=72] - the resolution (size) at which to render the text. Does not take effect if `height` is specified. * @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 `Red!`. * @param {number} [options.text.spacing=0] - text line height in points. Will use the font line height if none is specified. - * @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'. + * @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'. * @returns {Sharp} * @throws {Error} Invalid parameters */ diff --git a/lib/index.d.ts b/lib/index.d.ts index 4457c0cc7..f73a7594b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1017,7 +1017,7 @@ declare namespace sharp { rgba?: boolean; /** Text line height in points. Will use the font line height if none is specified. (optional, default `0`) */ spacing?: number; - /** Word wrapping style when width is provided, one of: 'word', 'char', 'wordChar' (prefer char, fallback to word) or 'none' */ + /** Word wrapping style when width is provided, one of: 'word', 'char', 'word-char' (prefer word, fallback to char) or 'none' */ wrap?: TextWrap; } @@ -1613,7 +1613,7 @@ declare namespace sharp { type TextAlign = 'left' | 'centre' | 'center' | 'right'; - type TextWrap = 'word' | 'char' | 'wordChar' | 'none'; + type TextWrap = 'word' | 'char' | 'word-char' | 'none'; type TileContainer = 'fs' | 'zip'; diff --git a/lib/input.js b/lib/input.js index cafd8fd74..e212dc14e 100644 --- a/lib/input.js +++ b/lib/input.js @@ -345,10 +345,10 @@ function _createInputDescriptor (input, inputOptions, containerOptions) { } } if (is.defined(inputOptions.text.wrap)) { - if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'wordChar', 'none'])) { + if (is.string(inputOptions.text.wrap) && is.inArray(inputOptions.text.wrap, ['word', 'char', 'word-char', 'none'])) { inputDescriptor.textWrap = inputOptions.text.wrap; } else { - throw is.invalidParameterError('text.wrap', 'one of: word, char, wordChar, none', inputOptions.text.wrap); + throw is.invalidParameterError('text.wrap', 'one of: word, char, word-char, none', inputOptions.text.wrap); } } delete inputDescriptor.buffer; diff --git a/test/types/sharp.test-d.ts b/test/types/sharp.test-d.ts index be9557c9b..daf41f3f8 100644 --- a/test/types/sharp.test-d.ts +++ b/test/types/sharp.test-d.ts @@ -595,7 +595,7 @@ sharp({ rgba: true, justify: true, spacing: 10, - wrap: 'wordChar', + wrap: 'word-char', }, }) .png() diff --git a/test/unit/text.js b/test/unit/text.js index 59c40337d..d404ac8bb 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -319,21 +319,21 @@ describe('Text to image', function () { it('valid wrap throws', () => { assert.doesNotThrow(() => sharp({ text: { text: 'text', wrap: 'none' } })); - assert.doesNotThrow(() => sharp({ text: { text: 'text', wrap: 'wordChar' } })); + assert.doesNotThrow(() => sharp({ text: { text: 'text', wrap: 'word-char' } })); }); it('invalid wrap throws', () => { assert.throws( () => sharp({ text: { text: 'text', wrap: 1 } }), - /Expected one of: word, char, wordChar, none for text\.wrap but received 1 of type number/ + /Expected one of: word, char, word-char, none for text\.wrap but received 1 of type number/ ); assert.throws( () => sharp({ text: { text: 'text', wrap: false } }), - /Expected one of: word, char, wordChar, none for text\.wrap but received false of type boolean/ + /Expected one of: word, char, word-char, none for text\.wrap but received false of type boolean/ ); assert.throws( () => sharp({ text: { text: 'text', wrap: 'invalid' } }), - /Expected one of: word, char, wordChar, none for text\.wrap but received invalid of type string/ + /Expected one of: word, char, word-char, none for text\.wrap but received invalid of type string/ ); }); });