@dinvader/autonbsp 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mikhail Panichev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Auto NBSP
2
+
3
+ > TODO: write readme
@@ -0,0 +1,5 @@
1
+ import { AutoNBSPConfig } from './types';
2
+ /**
3
+ * Replaces runs of whitespace with non-breaking spaces according to configurable rules.
4
+ */
5
+ export declare const autoNBSP: (text: string, config?: AutoNBSPConfig) => string;
@@ -0,0 +1,15 @@
1
+ const l = {
2
+ html: " ",
3
+ utf: " "
4
+ }, d = function(i, n) {
5
+ const { mode: o = "utf", betweenDigits: a = !1, afterDigits: r = !1, prepositions: t } = n || {}, s = l[o];
6
+ let e = i;
7
+ if (t) {
8
+ const p = Array.isArray(t) ? t.join("|") : t, c = new RegExp(`(?<=\\s|^)(${p})\\s+`, "giu");
9
+ e = e.replace(c, (g, f) => `${f}${s}`);
10
+ }
11
+ return a && (e = e.replace(new RegExp("(?<=\\d)\\s+(?=\\d)", "giu"), s)), r && (r === "before-letter" ? e = e.replace(new RegExp("(?<=\\d)\\s+(?=\\p{L})", "giu"), s) : e = e.replace(new RegExp("(?<=\\d)\\s+(?=\\D)", "giu"), s)), e;
12
+ };
13
+ export {
14
+ d as autoNBSP
15
+ };
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './autonbsp';
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { autoNBSP as t } from "./autonbsp.js";
2
+ export {
3
+ t as autoNBSP
4
+ };
@@ -0,0 +1,3 @@
1
+ import { AutoNBSPConfig } from '../types';
2
+ declare const preset: AutoNBSPConfig;
3
+ export default preset;
@@ -0,0 +1,8 @@
1
+ const t = {
2
+ betweenDigits: !0,
3
+ afterDigits: !0,
4
+ prepositions: ["a", "an", "the", "at", "by", "for", "from", "in", "of", "on", "to", "with"]
5
+ };
6
+ export {
7
+ t as default
8
+ };
@@ -0,0 +1,3 @@
1
+ import { AutoNBSPConfig } from '../types';
2
+ declare const preset: AutoNBSPConfig;
3
+ export default preset;
@@ -0,0 +1,33 @@
1
+ const e = {
2
+ betweenDigits: !0,
3
+ afterDigits: !0,
4
+ prepositions: [
5
+ "а",
6
+ "в",
7
+ "во",
8
+ "для",
9
+ "за",
10
+ "и",
11
+ "из",
12
+ "к",
13
+ "ко",
14
+ "на",
15
+ "над",
16
+ "не",
17
+ "о",
18
+ "об",
19
+ "обо",
20
+ "от",
21
+ "по",
22
+ "под",
23
+ "при",
24
+ "про",
25
+ "с",
26
+ "со",
27
+ "у",
28
+ "через"
29
+ ]
30
+ };
31
+ export {
32
+ e as default
33
+ };
@@ -0,0 +1,45 @@
1
+ export type AutoNBSPMode = 'utf' | 'html';
2
+ export interface AutoNBSPConfig {
3
+ /**
4
+ * Defines the replacement used for matched whitespace.
5
+ *
6
+ * - `'utf'` replaces whitespace with the Unicode non-breaking space character (`'\u00A0'`)
7
+ * - `'html'` replaces whitespace with the HTML entity string (`'&nbsp;'`)
8
+ *
9
+ * @default 'utf'
10
+ */
11
+ mode?: AutoNBSPMode;
12
+ /**
13
+ * Replace runs of whitespace that occur between two adjacent digits.
14
+ *
15
+ * Examples:
16
+ * - `"123 456"` → `"123\u00A0456"`
17
+ * - `"1\t 2"` → `"1\u00A02"`
18
+ *
19
+ * @default false
20
+ */
21
+ betweenDigits?: boolean;
22
+ /**
23
+ * Replace runs of whitespace that occur immediately after a digit.
24
+ *
25
+ * - `true` replaces whitespace when followed by any non-digit character
26
+ * - `'before-letter'` replaces whitespace only when followed by a Unicode letter (`\p{L}`)
27
+ *
28
+ * Examples:
29
+ * - `"2 pieces"` → `"2\u00A0pieces"`
30
+ * - `"5 %"` → `"5\u00A0%"`
31
+ *
32
+ * @default false
33
+ */
34
+ afterDigits?: boolean | 'before-letter';
35
+ /**
36
+ * Replace runs of whitespace that occur after specified whole-word prepositions.
37
+ *
38
+ * Prepositions may be provided as:
39
+ * - an array of strings (e.g. `['a', 'in', 'for']`)
40
+ * - a pipe-separated regular expression pattern (e.g. `'a|in|for'`)
41
+ *
42
+ * Matching is case-insensitive and respects word boundaries.
43
+ */
44
+ prepositions?: string | string[];
45
+ }
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@dinvader/autonbsp",
3
+ "private": false,
4
+ "version": "0.1.2",
5
+ "license": "MIT",
6
+ "author": "Mikhail Panichev <denis.invader@gmail.com>",
7
+ "repository": "github:denisinvader/autonbsp",
8
+ "bugs": {
9
+ "url": "https://github.com/denisinvader/autonbsp/issues"
10
+ },
11
+ "type": "module",
12
+ "types": "dist/index.d.ts",
13
+ "files": [
14
+ "dist/**/*"
15
+ ],
16
+ "exports": {
17
+ ".": "./dist/index.js",
18
+ "./presets/*": "./dist/presets/*.js"
19
+ },
20
+ "scripts": {
21
+ "build": "rm -rf dist && tsc -b && vite build",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest",
24
+ "prepublishOnly": "tsc -b && vitest run && rm -rf dist && vite build"
25
+ },
26
+ "devDependencies": {
27
+ "@types/node": "^25.1.0",
28
+ "prettier": "^3.8.1",
29
+ "typescript": "^5.9.3",
30
+ "vite": "^7.3.1",
31
+ "vite-plugin-dts": "^4.5.4",
32
+ "vitest": "^4.0.18"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ }
37
+ }