Skip to content

Commit 0cc0ba3

Browse files
Expose word separator
1 parent 30b87ef commit 0cc0ba3

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

packages/nhsuk-frontend/src/nhsuk/components/character-count/character-count.mjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export class CharacterCount extends ConfigurableComponent {
2525
*/
2626
segmenter = null
2727

28+
/**
29+
* Split words between consecutive whitespace
30+
*
31+
* @type {RegExp}
32+
*/
33+
separator = /\s+/g
34+
2835
/**
2936
* @type {number | null}
3037
*/
@@ -485,7 +492,7 @@ export class CharacterCount extends ConfigurableComponent {
485492
*/
486493
words(text) {
487494
if (this.config.maxwords !== undefined) {
488-
return text.split(/\s+/g).filter(Boolean).length
495+
return text.split(this.separator).filter(Boolean).length
489496
}
490497

491498
const segments = this.segmenter

0 commit comments

Comments
 (0)