Comparing version
declare type AutoNbspOptions = { | ||
minCharInWord: number; | ||
minimumCharacterCountInWord: number; | ||
}; | ||
export declare function addNbsp(text: string, options?: AutoNbspOptions): string; | ||
export {}; |
@@ -5,9 +5,13 @@ "use strict"; | ||
function addNbsp(text, options) { | ||
var _a = (options || {}).minCharInWord, minCharInWord = _a === void 0 ? 3 : _a; | ||
return text.split(/[ ]/).reduce(function (acc, word) { | ||
if (acc === '') | ||
const { minimumCharacterCountInWord = 3 } = options ?? {}; | ||
return text.split(/[ ]/).reduce((accumulator, word) => { | ||
if (accumulator === '') { | ||
return word; | ||
return word.length <= minCharInWord ? "".concat(acc, "\u00A0").concat(word) : "".concat(acc, " ").concat(word); | ||
} | ||
const space = word.replaceAll(/[\.,\?\!\:]/g, '').length <= minimumCharacterCountInWord | ||
? ' ' | ||
: ' '; | ||
return `${accumulator}${space}${word}`; | ||
}, ''); | ||
} | ||
exports.addNbsp = addNbsp; |
{ | ||
"name": "add-nbsp", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "The package allows you to automatically wrap conjunctions, prepositions and other words up to n characters on the next line. According to the rules of typography, n = 3.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -14,5 +14,5 @@ # Add nbsp [](https://www.npmjs.com/package/add-nbsp)  | ||
```js | ||
import { addNbsp } from 'add-nbsp'; | ||
import { addNbsp } from 'add-nbsp' | ||
document.body.textContent = addNbsp('What are they doing?'); | ||
document.body.textContent = addNbsp('What are they doing?') | ||
``` |
2369
3.27%21
23.53%