@tejaskedare/search-highlight-pipe 1.0.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/README.md +63 -0
- package/fesm2022/tejaskedare-search-highlight-pipe.mjs +67 -0
- package/fesm2022/tejaskedare-search-highlight-pipe.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/pipes/search-highlight.pipe.d.ts +10 -0
- package/lib/text-utils.component.d.ts +5 -0
- package/lib/text-utils.service.d.ts +6 -0
- package/package.json +34 -0
- package/public-api.d.ts +3 -0
package/README.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# TextUtils
|
|
2
|
+
|
|
3
|
+
This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.0.
|
|
4
|
+
|
|
5
|
+
## Code scaffolding
|
|
6
|
+
|
|
7
|
+
Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
ng generate component component-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
ng generate --help
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Building
|
|
20
|
+
|
|
21
|
+
To build the library, run:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
ng build text-utils
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
|
|
28
|
+
|
|
29
|
+
### Publishing the Library
|
|
30
|
+
|
|
31
|
+
Once the project is built, you can publish your library by following these steps:
|
|
32
|
+
|
|
33
|
+
1. Navigate to the `dist` directory:
|
|
34
|
+
```bash
|
|
35
|
+
cd dist/text-utils
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
2. Run the `npm publish` command to publish your library to the npm registry:
|
|
39
|
+
```bash
|
|
40
|
+
npm publish
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Running unit tests
|
|
44
|
+
|
|
45
|
+
To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ng test
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Running end-to-end tests
|
|
52
|
+
|
|
53
|
+
For end-to-end (e2e) testing, run:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
ng e2e
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
|
|
60
|
+
|
|
61
|
+
## Additional Resources
|
|
62
|
+
|
|
63
|
+
For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Component, Pipe } from '@angular/core';
|
|
3
|
+
import * as i1 from '@angular/platform-browser';
|
|
4
|
+
|
|
5
|
+
class TextUtilsService {
|
|
6
|
+
constructor() { }
|
|
7
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: TextUtilsService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
8
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: TextUtilsService, providedIn: 'root' });
|
|
9
|
+
}
|
|
10
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: TextUtilsService, decorators: [{
|
|
11
|
+
type: Injectable,
|
|
12
|
+
args: [{
|
|
13
|
+
providedIn: 'root'
|
|
14
|
+
}]
|
|
15
|
+
}], ctorParameters: () => [] });
|
|
16
|
+
|
|
17
|
+
class TextUtilsComponent {
|
|
18
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: TextUtilsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
19
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.20", type: TextUtilsComponent, isStandalone: true, selector: "lib-text-utils", ngImport: i0, template: `
|
|
20
|
+
<p>
|
|
21
|
+
text-utils works!
|
|
22
|
+
</p>
|
|
23
|
+
`, isInline: true, styles: [""] });
|
|
24
|
+
}
|
|
25
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: TextUtilsComponent, decorators: [{
|
|
26
|
+
type: Component,
|
|
27
|
+
args: [{ selector: 'lib-text-utils', imports: [], template: `
|
|
28
|
+
<p>
|
|
29
|
+
text-utils works!
|
|
30
|
+
</p>
|
|
31
|
+
` }]
|
|
32
|
+
}] });
|
|
33
|
+
|
|
34
|
+
class SearchHighlightPipe {
|
|
35
|
+
sanitizer;
|
|
36
|
+
constructor(sanitizer) {
|
|
37
|
+
this.sanitizer = sanitizer;
|
|
38
|
+
}
|
|
39
|
+
transform(value, searchText, className = 'highlight') {
|
|
40
|
+
if (!value || !searchText)
|
|
41
|
+
return value;
|
|
42
|
+
const escapedSearch = searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
43
|
+
const regex = new RegExp(`(${escapedSearch})`, 'gi');
|
|
44
|
+
const highlighted = value.replace(regex, `<span class="${className}">$1</span>`);
|
|
45
|
+
return this.sanitizer.bypassSecurityTrustHtml(highlighted);
|
|
46
|
+
}
|
|
47
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: SearchHighlightPipe, deps: [{ token: i1.DomSanitizer }], target: i0.ɵɵFactoryTarget.Pipe });
|
|
48
|
+
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.20", ngImport: i0, type: SearchHighlightPipe, isStandalone: true, name: "searchHighlight" });
|
|
49
|
+
}
|
|
50
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.20", ngImport: i0, type: SearchHighlightPipe, decorators: [{
|
|
51
|
+
type: Pipe,
|
|
52
|
+
args: [{
|
|
53
|
+
name: 'searchHighlight',
|
|
54
|
+
standalone: true
|
|
55
|
+
}]
|
|
56
|
+
}], ctorParameters: () => [{ type: i1.DomSanitizer }] });
|
|
57
|
+
|
|
58
|
+
/*
|
|
59
|
+
* Public API Surface of text-utils
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Generated bundle index. Do not edit.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
export { SearchHighlightPipe, TextUtilsComponent, TextUtilsService };
|
|
67
|
+
//# sourceMappingURL=tejaskedare-search-highlight-pipe.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tejaskedare-search-highlight-pipe.mjs","sources":["../../../projects/text-utils/src/lib/text-utils.service.ts","../../../projects/text-utils/src/lib/text-utils.component.ts","../../../projects/text-utils/src/lib/pipes/search-highlight.pipe.ts","../../../projects/text-utils/src/public-api.ts","../../../projects/text-utils/src/tejaskedare-search-highlight-pipe.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\r\n\r\n@Injectable({\r\n providedIn: 'root'\r\n})\r\nexport class TextUtilsService {\r\n\r\n constructor() { }\r\n}\r\n","import { Component } from '@angular/core';\r\n\r\n@Component({\r\n selector: 'lib-text-utils',\r\n imports: [],\r\n template: `\r\n <p>\r\n text-utils works!\r\n </p>\r\n `,\r\n styles: ``\r\n})\r\nexport class TextUtilsComponent {\r\n\r\n}\r\n","import { Pipe, PipeTransform } from '@angular/core';\r\nimport { DomSanitizer, SafeHtml } from '@angular/platform-browser';\r\n\r\n@Pipe({\r\n name: 'searchHighlight',\r\n standalone: true\r\n})\r\nexport class SearchHighlightPipe implements PipeTransform {\r\n\r\n constructor(private sanitizer: DomSanitizer) {}\r\n\r\n transform(\r\n value: string,\r\n searchText: string,\r\n className: string = 'highlight'\r\n ): SafeHtml {\r\n\r\n if (!value || !searchText) return value;\r\n\r\n const escapedSearch = searchText.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&');\r\n\r\n const regex = new RegExp(`(${escapedSearch})`, 'gi');\r\n\r\n const highlighted = value.replace(\r\n regex,\r\n `<span class=\"${className}\">$1</span>`\r\n );\r\n\r\n return this.sanitizer.bypassSecurityTrustHtml(highlighted);\r\n }\r\n}","/*\r\n * Public API Surface of text-utils\r\n */\r\n\r\nexport * from './lib/text-utils.service';\r\nexport * from './lib/text-utils.component';\r\nexport * from './lib/pipes/search-highlight.pipe';","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;MAKa,gBAAgB,CAAA;AAE3B,IAAA,WAAA,GAAA,EAAgB;wGAFL,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAhB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,gBAAgB,cAFf,MAAM,EAAA,CAAA;;4FAEP,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAH5B,UAAU;AAAC,YAAA,IAAA,EAAA,CAAA;AACV,oBAAA,UAAU,EAAE;AACb,iBAAA;;;MCQY,kBAAkB,CAAA;wGAAlB,kBAAkB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;AAAlB,IAAA,OAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,SAAA,EAAA,IAAA,EAAA,kBAAkB,EAAA,YAAA,EAAA,IAAA,EAAA,QA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AAA,EAAA,CAAA;AACJ,oBAAA,IAAI,EAAE,iBAAiB;AACvB,oBAAA,UAAU,EAAE;AACb,iBAAA;;;ACND;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PipeTransform } from '@angular/core';
|
|
2
|
+
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export declare class SearchHighlightPipe implements PipeTransform {
|
|
5
|
+
private sanitizer;
|
|
6
|
+
constructor(sanitizer: DomSanitizer);
|
|
7
|
+
transform(value: string, searchText: string, className?: string): SafeHtml;
|
|
8
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SearchHighlightPipe, never>;
|
|
9
|
+
static ɵpipe: i0.ɵɵPipeDeclaration<SearchHighlightPipe, "searchHighlight", true>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export declare class TextUtilsComponent {
|
|
3
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TextUtilsComponent, never>;
|
|
4
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<TextUtilsComponent, "lib-text-utils", never, {}, {}, never, never, true, never>;
|
|
5
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tejaskedare/search-highlight-pipe",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Reusable Angular pipes like search highlight, truncate, mask",
|
|
5
|
+
"author": "Tejas Kedare",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@angular/common": "^19.2.0",
|
|
9
|
+
"@angular/core": "^19.2.0"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"angular",
|
|
13
|
+
"highlight pipe",
|
|
14
|
+
"search highlight",
|
|
15
|
+
"angular pipe highlight",
|
|
16
|
+
"text highlight angular",
|
|
17
|
+
"ngx highlight"
|
|
18
|
+
],
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"tslib": "^2.3.0"
|
|
21
|
+
},
|
|
22
|
+
"sideEffects": false,
|
|
23
|
+
"module": "fesm2022/tejaskedare-search-highlight-pipe.mjs",
|
|
24
|
+
"typings": "index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
"./package.json": {
|
|
27
|
+
"default": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./index.d.ts",
|
|
31
|
+
"default": "./fesm2022/tejaskedare-search-highlight-pipe.mjs"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
package/public-api.d.ts
ADDED