@markuplint/shared
Advanced tools
Comparing version 4.3.1 to 4.4.0
@@ -6,2 +6,8 @@ # Change Log | ||
# [4.4.0](https://github.com/markuplint/markuplint/compare/@markuplint/shared@4.3.1...@markuplint/shared@4.4.0) (2024-05-12) | ||
### Features | ||
- **shared:** add `regexParser` function ([d8baa3d](https://github.com/markuplint/markuplint/commit/d8baa3d3ce33eb5e647d8353fd3065ba2926fd9f)) | ||
## [4.3.1](https://github.com/markuplint/markuplint/compare/@markuplint/shared@4.3.1-alpha.0...@markuplint/shared@4.3.1) (2024-05-04) | ||
@@ -8,0 +14,0 @@ |
@@ -79,1 +79,12 @@ import type { Nullable } from './types.js'; | ||
export declare function branchesToPatterns<T>(branches: ReadonlyArray<Nullable<T> | ReadonlyArray<Nullable<T>>>): T[][]; | ||
/** | ||
* Parses a regular expression pattern in the form of `/pattern/flags`. | ||
* The pattern is parsed using the `RegExp` constructor. | ||
* If the pattern is invalid, `null` is returned. | ||
* The pattern must be a valid regular expression pattern. | ||
* Throws an error if the pattern or flags are invalid. | ||
* | ||
* @param regexpLikeString - The regular expression pattern to parse. | ||
* @returns - The parsed regular expression or null if the pattern is invalid. | ||
*/ | ||
export declare function regexParser(regexpLikeString: string): RegExp | null; |
@@ -113,1 +113,27 @@ import { decode as decodeHtmlEntities } from 'html-entities'; | ||
} | ||
/** | ||
* Parses a regular expression pattern in the form of `/pattern/flags`. | ||
* The pattern is parsed using the `RegExp` constructor. | ||
* If the pattern is invalid, `null` is returned. | ||
* The pattern must be a valid regular expression pattern. | ||
* Throws an error if the pattern or flags are invalid. | ||
* | ||
* @param regexpLikeString - The regular expression pattern to parse. | ||
* @returns - The parsed regular expression or null if the pattern is invalid. | ||
*/ | ||
export function regexParser(regexpLikeString) { | ||
if (!regexpLikeString.startsWith('/')) { | ||
// Early return if the string does not start with a slash. | ||
return null; | ||
} | ||
const match = regexpLikeString.match(/^\/(?<pattern>.+)\/(?<flags>[dgimsuvy]*)$/); // cspell: disable-line | ||
if (!match) { | ||
return null; | ||
} | ||
const { pattern, flags } = match.groups; | ||
if (!pattern) { | ||
return null; | ||
} | ||
// Throws an error if `pattern` or `flags` is invalid. | ||
return new RegExp(pattern, flags); | ||
} |
{ | ||
"name": "@markuplint/shared", | ||
"version": "4.3.1", | ||
"version": "4.4.0", | ||
"description": "Shared functions for Markuplint", | ||
@@ -29,3 +29,3 @@ "repository": "git@github.com:markuplint/markuplint.git", | ||
}, | ||
"gitHead": "7a5967fce14fdf66f0d8eae9d93ae5b350648d3d" | ||
"gitHead": "ca7dc6bf40eac4f2813e492878f889eb77751a70" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11994
233