@ulu/utils
Advanced tools
Comparing version 0.0.15 to 0.0.16
# Change Log | ||
## 0.0.16 | ||
- (Added) String > extractMatchDetails() Provides details about regex match for string for replacement/usage | ||
## 0.0.14 | ||
@@ -4,0 +9,0 @@ |
@@ -140,2 +140,26 @@ /** | ||
}); | ||
} | ||
/** | ||
* Function that matches regex against string and returns details helpful for replacing/using/highlighting a single match within a string | ||
* @param {String} string The string to extract from | ||
* @param {Regex} regex The regular expression to match against | ||
* @returns {Object|Null} If match return object with { matched, startIndex, endIndex, before, after }, when no match is found this return null | ||
*/ | ||
export function extractMatchDetails(string, regex) { | ||
const match = string.match(regex); | ||
if (match) { | ||
const matched = match[0]; | ||
const startIndex = match.index; | ||
const endIndex = matchIndex + matched.length; | ||
return { | ||
matched, | ||
startIndex, | ||
endIndex, | ||
before: str.slice(0, startIndex), | ||
after: str.slice(endIndex) | ||
}; | ||
} else { | ||
return null; | ||
} | ||
} |
{ | ||
"name": "@ulu/utils", | ||
"version": "0.0.15", | ||
"description": "Low level utility library", | ||
"version": "0.0.16", | ||
"description": "A collection of helpful utility functions for common JavaScript development and browser DOM manipulation tasks", | ||
"keywords": [ | ||
"array", | ||
"Utilities" | ||
"utility", | ||
"utilities", | ||
"helper", | ||
"function", | ||
"tool", | ||
"library", | ||
"utils", | ||
"library", | ||
"Javascript", | ||
"string", | ||
"dom", | ||
"number", | ||
"random", | ||
"regex" | ||
], | ||
@@ -9,0 +22,0 @@ "author": "Joseph Scherben <jscherbe@gmail.com>", |
@@ -73,2 +73,9 @@ /** | ||
export function titleCase(string: string, exceptions?: any[], defaults?: any[]): string; | ||
/** | ||
* Function that matches regex against string and returns details helpful for replacing/using/highlighting a single match within a string | ||
* @param {String} string The string to extract from | ||
* @param {Regex} regex The regular expression to match against | ||
* @returns {Object|Null} If match return object with { matched, startIndex, endIndex, before, after }, when no match is found this return null | ||
*/ | ||
export function extractMatchDetails(string: string, regex: Regex): any | null; | ||
//# sourceMappingURL=string.d.ts.map |
Sorry, the diff of this file is not supported yet
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
41500
43
1046