@mkven/regexps 1.0.0
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/README.md +67 -0
- package/dist/cjs/index.js +30 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +27 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @mkven/regexps
|
|
2
|
+
|
|
3
|
+
Shared regular expression constants for text normalization and validation.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @mkven/regexps
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { whitespace, nonDigit, leadingQuote, trailingQuote } from "@mkven/regexps";
|
|
15
|
+
|
|
16
|
+
"hello world".replaceAll(whitespace, "_"); // "hello_world"
|
|
17
|
+
"abc123".replaceAll(nonDigit, ""); // "123"
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Constants
|
|
21
|
+
|
|
22
|
+
### Text normalization
|
|
23
|
+
|
|
24
|
+
| Constant | Pattern | Flags | Description |
|
|
25
|
+
|---|---|---|---|
|
|
26
|
+
| `whitespace` | `\s` | `gu` | Any whitespace character |
|
|
27
|
+
| `spacesAndNewlines` | `(\s\|\n)` | `gu` | Whitespace or newline |
|
|
28
|
+
| `whitespaceAndNbsp` | `(?:\s\| )+` | `gu` | Whitespace or HTML nbsp entity |
|
|
29
|
+
| `tabNewlineCarriageReturn` | `[\t\n\r]` | `gu` | Tab, newline, carriage return |
|
|
30
|
+
| `invisibleControlChars` | `[\u0002\u0003\u200B\u202A\u202B]` | `gu` | STX, ETX, zero-width space, BiDi markers |
|
|
31
|
+
|
|
32
|
+
### Digit / phone patterns
|
|
33
|
+
|
|
34
|
+
| Constant | Pattern | Flags | Description |
|
|
35
|
+
|---|---|---|---|
|
|
36
|
+
| `digits` | `\d` | `gu` | Any digit |
|
|
37
|
+
| `nonDigit` | `\D` | `gu` | Any non-digit |
|
|
38
|
+
| `nonPlusNonDigit` | `[^\d+]` | `gu` | Any character except digit or plus |
|
|
39
|
+
| `russianPhone` | `^(\+?7\|8)(\d{10})$` | `u` | Russian phone number capture |
|
|
40
|
+
|
|
41
|
+
### Character class validation
|
|
42
|
+
|
|
43
|
+
| Constant | Pattern | Flags | Description |
|
|
44
|
+
|---|---|---|---|
|
|
45
|
+
| `latinOnly` | `^[A-Za-z]*$` | `u` | Only Latin letters |
|
|
46
|
+
| `latinCyrillicNumbersHyphen` | `^[\dA-Za-zЁА-яё-]*$` | `u` | Latin, Cyrillic, digits, hyphen |
|
|
47
|
+
| `cyrillicDashQuotation` | `^['\`ЁА-яё-]*$` | `u` | Cyrillic, dash, quotes |
|
|
48
|
+
| `latinDashQuotation` | `^['A-Z\`a-z-]*$` | `u` | Latin, dash, quotes |
|
|
49
|
+
| `uppercaseLatinLetters` | `[A-Z]` | `gu` | Uppercase Latin letters |
|
|
50
|
+
| `latinNumbersDotUnderscoreHyphenPlus` | `^[\w+.-]*$` | `u` | Latin, digits, dot, underscore, hyphen, plus |
|
|
51
|
+
|
|
52
|
+
### Boundary / edge patterns
|
|
53
|
+
|
|
54
|
+
| Constant | Pattern | Flags | Description |
|
|
55
|
+
|---|---|---|---|
|
|
56
|
+
| `leadingOrTrailingDotHyphenPlus` | `^[+.-]\|[+.-]$` | `u` | Leading or trailing dot/hyphen/plus |
|
|
57
|
+
| `leadingOrTrailingDash` | `^-\|-$` | `u` | Leading or trailing dash |
|
|
58
|
+
| `leadingQuote` | `^"` | `gu` | Leading double quote |
|
|
59
|
+
| `trailingQuote` | `"$` | `gu` | Trailing double quote |
|
|
60
|
+
|
|
61
|
+
### File extensions
|
|
62
|
+
|
|
63
|
+
| Constant | Pattern | Flags | Description |
|
|
64
|
+
|---|---|---|---|
|
|
65
|
+
| `gzExtension` | `\.gz$` | `gu` | .gz file extension |
|
|
66
|
+
| `encExtension` | `\.enc$` | `gu` | .enc file extension |
|
|
67
|
+
| `gzEncExtension` | `\.gz\.enc$` | `gu` | .gz.enc file extension |
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.gzEncExtension = exports.encExtension = exports.gzExtension = exports.trailingQuote = exports.leadingQuote = exports.leadingOrTrailingDash = exports.leadingOrTrailingDotHyphenPlus = exports.latinNumbersDotUnderscoreHyphenPlus = exports.uppercaseLatinLetters = exports.latinDashQuotation = exports.cyrillicDashQuotation = exports.latinCyrillicNumbersHyphen = exports.latinOnly = exports.russianPhone = exports.nonPlusNonDigit = exports.nonDigit = exports.digits = exports.invisibleControlChars = exports.tabNewlineCarriageReturn = exports.whitespaceAndNbsp = exports.spacesAndNewlines = exports.whitespace = void 0;
|
|
4
|
+
// Text normalization
|
|
5
|
+
exports.whitespace = /\s/gu;
|
|
6
|
+
exports.spacesAndNewlines = /(\s|\n)/gu;
|
|
7
|
+
exports.whitespaceAndNbsp = /(?:\s| )+/gu;
|
|
8
|
+
exports.tabNewlineCarriageReturn = /[\t\n\r]/gu;
|
|
9
|
+
exports.invisibleControlChars = /[\u0002\u0003\u200B\u202A\u202B]/gu;
|
|
10
|
+
// Digit / phone patterns
|
|
11
|
+
exports.digits = /\d/gu;
|
|
12
|
+
exports.nonDigit = /\D/gu;
|
|
13
|
+
exports.nonPlusNonDigit = /[^\d+]/gu;
|
|
14
|
+
exports.russianPhone = /^(\+?7|8)(\d{10})$/u;
|
|
15
|
+
// Character class validation
|
|
16
|
+
exports.latinOnly = /^[A-Za-z]*$/u;
|
|
17
|
+
exports.latinCyrillicNumbersHyphen = /^[\dA-Za-zЁА-яё-]*$/u;
|
|
18
|
+
exports.cyrillicDashQuotation = /^['`ЁА-яё-]*$/u;
|
|
19
|
+
exports.latinDashQuotation = /^['A-Z`a-z-]*$/u;
|
|
20
|
+
exports.uppercaseLatinLetters = /[A-Z]/gu;
|
|
21
|
+
exports.latinNumbersDotUnderscoreHyphenPlus = /^[\w+.-]*$/u;
|
|
22
|
+
// Boundary / edge patterns
|
|
23
|
+
exports.leadingOrTrailingDotHyphenPlus = /^[+.-]|[+.-]$/u;
|
|
24
|
+
exports.leadingOrTrailingDash = /^-|-$/u;
|
|
25
|
+
exports.leadingQuote = /^"/gu;
|
|
26
|
+
exports.trailingQuote = /"$/gu;
|
|
27
|
+
// File extensions
|
|
28
|
+
exports.gzExtension = /\.gz$/gu;
|
|
29
|
+
exports.encExtension = /\.enc$/gu;
|
|
30
|
+
exports.gzEncExtension = /\.gz\.enc$/gu;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const whitespace: RegExp;
|
|
2
|
+
export declare const spacesAndNewlines: RegExp;
|
|
3
|
+
export declare const whitespaceAndNbsp: RegExp;
|
|
4
|
+
export declare const tabNewlineCarriageReturn: RegExp;
|
|
5
|
+
export declare const invisibleControlChars: RegExp;
|
|
6
|
+
export declare const digits: RegExp;
|
|
7
|
+
export declare const nonDigit: RegExp;
|
|
8
|
+
export declare const nonPlusNonDigit: RegExp;
|
|
9
|
+
export declare const russianPhone: RegExp;
|
|
10
|
+
export declare const latinOnly: RegExp;
|
|
11
|
+
export declare const latinCyrillicNumbersHyphen: RegExp;
|
|
12
|
+
export declare const cyrillicDashQuotation: RegExp;
|
|
13
|
+
export declare const latinDashQuotation: RegExp;
|
|
14
|
+
export declare const uppercaseLatinLetters: RegExp;
|
|
15
|
+
export declare const latinNumbersDotUnderscoreHyphenPlus: RegExp;
|
|
16
|
+
export declare const leadingOrTrailingDotHyphenPlus: RegExp;
|
|
17
|
+
export declare const leadingOrTrailingDash: RegExp;
|
|
18
|
+
export declare const leadingQuote: RegExp;
|
|
19
|
+
export declare const trailingQuote: RegExp;
|
|
20
|
+
export declare const gzExtension: RegExp;
|
|
21
|
+
export declare const encExtension: RegExp;
|
|
22
|
+
export declare const gzEncExtension: RegExp;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Text normalization
|
|
2
|
+
export const whitespace = /\s/gu;
|
|
3
|
+
export const spacesAndNewlines = /(\s|\n)/gu;
|
|
4
|
+
export const whitespaceAndNbsp = /(?:\s| )+/gu;
|
|
5
|
+
export const tabNewlineCarriageReturn = /[\t\n\r]/gu;
|
|
6
|
+
export const invisibleControlChars = /[\u0002\u0003\u200B\u202A\u202B]/gu;
|
|
7
|
+
// Digit / phone patterns
|
|
8
|
+
export const digits = /\d/gu;
|
|
9
|
+
export const nonDigit = /\D/gu;
|
|
10
|
+
export const nonPlusNonDigit = /[^\d+]/gu;
|
|
11
|
+
export const russianPhone = /^(\+?7|8)(\d{10})$/u;
|
|
12
|
+
// Character class validation
|
|
13
|
+
export const latinOnly = /^[A-Za-z]*$/u;
|
|
14
|
+
export const latinCyrillicNumbersHyphen = /^[\dA-Za-zЁА-яё-]*$/u;
|
|
15
|
+
export const cyrillicDashQuotation = /^['`ЁА-яё-]*$/u;
|
|
16
|
+
export const latinDashQuotation = /^['A-Z`a-z-]*$/u;
|
|
17
|
+
export const uppercaseLatinLetters = /[A-Z]/gu;
|
|
18
|
+
export const latinNumbersDotUnderscoreHyphenPlus = /^[\w+.-]*$/u;
|
|
19
|
+
// Boundary / edge patterns
|
|
20
|
+
export const leadingOrTrailingDotHyphenPlus = /^[+.-]|[+.-]$/u;
|
|
21
|
+
export const leadingOrTrailingDash = /^-|-$/u;
|
|
22
|
+
export const leadingQuote = /^"/gu;
|
|
23
|
+
export const trailingQuote = /"$/gu;
|
|
24
|
+
// File extensions
|
|
25
|
+
export const gzExtension = /\.gz$/gu;
|
|
26
|
+
export const encExtension = /\.enc$/gu;
|
|
27
|
+
export const gzEncExtension = /\.gz\.enc$/gu;
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mkven/regexps",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Shared regular expression constants for text normalization and validation",
|
|
5
|
+
"author": "Damir Manapov",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/cjs/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@biomejs/biome": "^2.4.2",
|
|
25
|
+
"@release-it/conventional-changelog": "^10.0.0",
|
|
26
|
+
"release-it": "^19.0.3",
|
|
27
|
+
"typescript": "^5.8.3",
|
|
28
|
+
"vitest": "^4.0.18"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsc && tsc -p tsconfig.cjs.json",
|
|
32
|
+
"lint": "biome check --write .",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"release": "release-it",
|
|
36
|
+
"release:dry": "release-it --dry-run"
|
|
37
|
+
}
|
|
38
|
+
}
|