@markuplint/shared 4.3.1 → 4.4.1
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/CHANGELOG.md +10 -0
- package/lib/functions.d.ts +11 -0
- package/lib/functions.js +26 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,16 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [4.4.1](https://github.com/markuplint/markuplint/compare/@markuplint/shared@4.4.0...@markuplint/shared@4.4.1) (2024-05-28)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @markuplint/shared
|
|
9
|
+
|
|
10
|
+
# [4.4.0](https://github.com/markuplint/markuplint/compare/@markuplint/shared@4.3.1...@markuplint/shared@4.4.0) (2024-05-12)
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
- **shared:** add `regexParser` function ([d8baa3d](https://github.com/markuplint/markuplint/commit/d8baa3d3ce33eb5e647d8353fd3065ba2926fd9f))
|
|
15
|
+
|
|
6
16
|
## [4.3.1](https://github.com/markuplint/markuplint/compare/@markuplint/shared@4.3.1-alpha.0...@markuplint/shared@4.3.1) (2024-05-04)
|
|
7
17
|
|
|
8
18
|
**Note:** Version bump only for package @markuplint/shared
|
package/lib/functions.d.ts
CHANGED
|
@@ -76,3 +76,14 @@ export declare function decodeHref(href: string): string;
|
|
|
76
76
|
* @returns The array of patterns generated from the branches.
|
|
77
77
|
*/
|
|
78
78
|
export declare function branchesToPatterns<T>(branches: ReadonlyArray<Nullable<T> | ReadonlyArray<Nullable<T>>>): T[][];
|
|
79
|
+
/**
|
|
80
|
+
* Parses a regular expression pattern in the form of `/pattern/flags`.
|
|
81
|
+
* The pattern is parsed using the `RegExp` constructor.
|
|
82
|
+
* If the pattern is invalid, `null` is returned.
|
|
83
|
+
* The pattern must be a valid regular expression pattern.
|
|
84
|
+
* Throws an error if the pattern or flags are invalid.
|
|
85
|
+
*
|
|
86
|
+
* @param regexpLikeString - The regular expression pattern to parse.
|
|
87
|
+
* @returns - The parsed regular expression or null if the pattern is invalid.
|
|
88
|
+
*/
|
|
89
|
+
export declare function regexParser(regexpLikeString: string): RegExp | null;
|
package/lib/functions.js
CHANGED
|
@@ -110,3 +110,29 @@ export function branchesToPatterns(branches) {
|
|
|
110
110
|
return accumulator.map(pattern => [...pattern, current].filter(nonNullableFilter));
|
|
111
111
|
}, [[]]);
|
|
112
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Parses a regular expression pattern in the form of `/pattern/flags`.
|
|
115
|
+
* The pattern is parsed using the `RegExp` constructor.
|
|
116
|
+
* If the pattern is invalid, `null` is returned.
|
|
117
|
+
* The pattern must be a valid regular expression pattern.
|
|
118
|
+
* Throws an error if the pattern or flags are invalid.
|
|
119
|
+
*
|
|
120
|
+
* @param regexpLikeString - The regular expression pattern to parse.
|
|
121
|
+
* @returns - The parsed regular expression or null if the pattern is invalid.
|
|
122
|
+
*/
|
|
123
|
+
export function regexParser(regexpLikeString) {
|
|
124
|
+
if (!regexpLikeString.startsWith('/')) {
|
|
125
|
+
// Early return if the string does not start with a slash.
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const match = regexpLikeString.match(/^\/(?<pattern>.+)\/(?<flags>[dgimsuvy]*)$/); // cspell: disable-line
|
|
129
|
+
if (!match) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
const { pattern, flags } = match.groups;
|
|
133
|
+
if (!pattern) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
// Throws an error if `pattern` or `flags` is invalid.
|
|
137
|
+
return new RegExp(pattern, flags);
|
|
138
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/shared",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.1",
|
|
4
4
|
"description": "Shared functions for Markuplint",
|
|
5
5
|
"repository": "git@github.com:markuplint/markuplint.git",
|
|
6
6
|
"author": "Yusuke Hirao <yusukehirao@me.com>",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"html-entities": "2.5.2"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "bf70c41b1d2497e85b73c9ecd5551eb522e6bdfc"
|
|
30
30
|
}
|