-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kit): fix pr comments: add tuiToRegexp pipe, optimize highlights…
… logic, fix intersected ranges
- Loading branch information
Showing
11 changed files
with
117 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export function tuiToArray<T>(value: T | readonly T[]): readonly T[] { | ||
import {TuiArrayOrValue} from '@taiga-ui/cdk/types'; | ||
|
||
export function tuiToArray<T>(value: TuiArrayOrValue<T>): readonly T[] { | ||
return Array.isArray(value) ? value : [value]; | ||
} |
2 changes: 1 addition & 1 deletion
2
projects/demo/src/modules/directives/highlight/examples/4/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './to-regexp.module'; | ||
export * from './to-regexp.pipe'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"lib": { | ||
"entryFile": "index.ts" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {TuiToRegexpPipe} from './to-regexp.pipe'; | ||
|
||
@NgModule({ | ||
declarations: [TuiToRegexpPipe], | ||
exports: [TuiToRegexpPipe], | ||
}) | ||
export class TuiToRegexpModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Pipe, PipeTransform} from '@angular/core'; | ||
import {TuiArrayOrValue, tuiIsString, tuiToArray} from '@taiga-ui/cdk'; | ||
|
||
/** | ||
* Transforms a string or an array of strings into RegExp instances. | ||
*/ | ||
@Pipe({ | ||
name: `tuiToRegexp`, | ||
}) | ||
export class TuiToRegexpPipe implements PipeTransform { | ||
/** | ||
* Transforms a string into a RegExp instance. | ||
* @param {string} value - The string to transform into a RegExp. | ||
* @param {string} [flags] - Optional flags to be applied to the RegExp. | ||
* @returns {RegExp} The transformed RegExp instance. | ||
*/ | ||
transform(value: string, flags?: string): RegExp; | ||
/** | ||
* Transforms an array of strings into an array of RegExp instances. | ||
* @param {readonly string[]} value - The array of strings to transform into RegExp instances. | ||
* @param {string} [flags] - Optional flags to be applied to the RegExp instances. | ||
* @returns {readonly RegExp[]} The transformed array of RegExp instances. | ||
*/ | ||
transform(value: readonly string[], flags?: string): readonly RegExp[]; | ||
transform( | ||
value: TuiArrayOrValue<string>, | ||
flags: string = ``, | ||
): TuiArrayOrValue<RegExp> { | ||
if (tuiIsString(value)) { | ||
return new RegExp(value, flags); | ||
} | ||
|
||
return tuiToArray(value).map(item => new RegExp(item, flags)); | ||
} | ||
} |