🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

add-nbsp

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-nbsp - npm Package Compare versions

Comparing version

to
0.1.0

2

lib/index.d.ts
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 [![npm](https://img.shields.io/npm/v/add-nbsp.svg)](https://www.npmjs.com/package/add-nbsp) ![npm type definitions](https://img.shields.io/npm/types/add-nbsp.svg)

```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?')
```