diff --git a/jest.config.ts b/jest.config.ts index 840fb9e..02ef1fd 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -32,8 +32,8 @@ const config: Config = { coverageReporters: ['html', 'lcov', 'json', 'text', 'lcov'], moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: `/${compilerOptions.baseUrl}/` - .replace(/\.\//g, '/') - .replace(/\/\/+/g, '/'), + .replaceAll('./', '/') + .replaceAll(/\/\/+/g, '/'), }), verbose: true, }; diff --git a/package-lock.json b/package-lock.json index 808a177..719dee5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,10 +32,10 @@ "@nguniversal/express-engine": "15.2.1", "@taiga-ui/browserslist-config": "0.5.0", "@taiga-ui/commitlint-config": "0.5.6", - "@taiga-ui/eslint-plugin-experience": "0.54.1", - "@taiga-ui/prettier-config": "0.8.3", + "@taiga-ui/eslint-plugin-experience": "0.58.0", + "@taiga-ui/prettier-config": "0.8.4", "@taiga-ui/stylelint-config": "0.16.0", - "@taiga-ui/tsconfig": "0.15.0", + "@taiga-ui/tsconfig": "0.16.0", "@types/dompurify": "3.0.5", "@types/eslint": "8.56.3", "@types/express": "4.17.21", @@ -5667,9 +5667,9 @@ } }, "node_modules/@taiga-ui/eslint-plugin-experience": { - "version": "0.54.1", - "resolved": "https://registry.npmjs.org/@taiga-ui/eslint-plugin-experience/-/eslint-plugin-experience-0.54.1.tgz", - "integrity": "sha512-itOMu7MNN4OezXpMCymB7fmIf9NzC7vTMiDOAASM8DrQMVXGTHvm6icwAXqoa078HPzfanx34Tk52O5Sk5OBKQ==", + "version": "0.58.0", + "resolved": "https://registry.npmjs.org/@taiga-ui/eslint-plugin-experience/-/eslint-plugin-experience-0.58.0.tgz", + "integrity": "sha512-FjZ09qhI7V3rPqsf14SFUp1BSr8tyhU9eJXjuMFzP905A/SR9rxVSCqpBKRktVLz4/Q295TOT6r6PCcPNYRg3w==", "dev": true, "dependencies": { "@angular-eslint/eslint-plugin": "17.2.1", @@ -5692,7 +5692,7 @@ "eslint-plugin-decorator-position": "5.0.2", "eslint-plugin-eslint-comments": "3.2.0", "eslint-plugin-file-progress": "1.3.0", - "eslint-plugin-functional": "6.0.0", + "eslint-plugin-functional": "6.0.1", "eslint-plugin-html": "7.1.0", "eslint-plugin-import": "2.29.1", "eslint-plugin-jest": "27.9.0", @@ -5727,7 +5727,7 @@ "eslint-plugin-decorator-position": "5.0.2", "eslint-plugin-eslint-comments": "3.2.0", "eslint-plugin-file-progress": "1.3.0", - "eslint-plugin-functional": "6.0.0", + "eslint-plugin-functional": "6.0.1", "eslint-plugin-html": "8.0.0", "eslint-plugin-import": "2.29.1", "eslint-plugin-jest": "27.9.0", @@ -5755,15 +5755,15 @@ } }, "node_modules/@taiga-ui/prettier-config": { - "version": "0.8.3", - "resolved": "https://registry.npmjs.org/@taiga-ui/prettier-config/-/prettier-config-0.8.3.tgz", - "integrity": "sha512-AAwlK48BijwC4hGEaUGsOs/9TfjulUiKKUzeqf2NHcbkaiDPumYnAKeOC3ED2o+M9kplTM7q9Uxql9M5no+jmQ==", + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/@taiga-ui/prettier-config/-/prettier-config-0.8.4.tgz", + "integrity": "sha512-vtKmW5cVKDcfoi/oD1ufUPjhk9phM6kn0za+M1PRmjo9pQsjzf85jvSSyu7pge6p4T/yLCRtvpKKuBRVCkECDA==", "dev": true, "dependencies": { "@prettier/plugin-xml": "3.3.1", "prettier-package-json": "2.8.0", "prettier-plugin-organize-attributes": "1.0.0", - "sort-package-json": "2.7.0" + "sort-package-json": "2.8.0" } }, "node_modules/@taiga-ui/stylelint-config": { @@ -5815,9 +5815,9 @@ } }, "node_modules/@taiga-ui/tsconfig": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/@taiga-ui/tsconfig/-/tsconfig-0.15.0.tgz", - "integrity": "sha512-a0mmPCnnAQqun2LxZekQlYlFSss+OF2SVstR+Srswo9wzPkDlUEu77L0Ga1QDHEd1FJ3w03cxFZn6zKoEhafjw==", + "version": "0.16.0", + "resolved": "https://registry.npmjs.org/@taiga-ui/tsconfig/-/tsconfig-0.16.0.tgz", + "integrity": "sha512-uccxubC1Q796EaAqJ8vXZGZ9+xfd4IqtBXqHShKMBmqMiVcU25AfhSibpWkbfHe00WnurOFhMK17AvyYQYcR3w==", "dev": true }, "node_modules/@tinkoff/ng-dompurify": { @@ -12023,9 +12023,9 @@ } }, "node_modules/eslint-plugin-functional": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-functional/-/eslint-plugin-functional-6.0.0.tgz", - "integrity": "sha512-jOUHUMA9cN2CIpgPj93fW1vTI3c95ZYUHMPJxEJL4KAtFkJDcT/9/YlfyrLOBxHkAcwBhJ29HSmeC/CUnN0k3g==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-functional/-/eslint-plugin-functional-6.0.1.tgz", + "integrity": "sha512-FDsPbSa3RKRh3i9re8ASmjN6iUfnSjyo++pfedL3S410/F4h0PwxBeNo+C2+qstHfW2XL4Gml8D4l6KMoQkJKg==", "dev": true, "funding": [ { @@ -23179,9 +23179,9 @@ "dev": true }, "node_modules/sort-package-json": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-2.7.0.tgz", - "integrity": "sha512-6AayF8bp6L+WROgpbhTMUtB9JSFmpGHjmW7DyaNPS1HwlTw2oSVlUUtlkHSEZmg5o89F3zvLBZNvMeZ1T4fjQg==", + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/sort-package-json/-/sort-package-json-2.8.0.tgz", + "integrity": "sha512-PxeNg93bTJWmDGnu0HADDucoxfFiKkIr73Kv85EBThlI1YQPdc0XovBgg2llD0iABZbu2SlKo8ntGmOP9wOj/g==", "dev": true, "dependencies": { "detect-indent": "^7.0.1", diff --git a/package.json b/package.json index 8343f28..3138e53 100644 --- a/package.json +++ b/package.json @@ -101,10 +101,10 @@ "@nguniversal/express-engine": "15.2.1", "@taiga-ui/browserslist-config": "0.5.0", "@taiga-ui/commitlint-config": "0.5.6", - "@taiga-ui/eslint-plugin-experience": "0.54.1", - "@taiga-ui/prettier-config": "0.8.3", + "@taiga-ui/eslint-plugin-experience": "0.58.0", + "@taiga-ui/prettier-config": "0.8.4", "@taiga-ui/stylelint-config": "0.16.0", - "@taiga-ui/tsconfig": "0.15.0", + "@taiga-ui/tsconfig": "0.16.0", "@types/dompurify": "3.0.5", "@types/eslint": "8.56.3", "@types/express": "4.17.21", diff --git a/projects/demo/src/app/app.component.ts b/projects/demo/src/app/app.component.ts index de26975..9488178 100644 --- a/projects/demo/src/app/app.component.ts +++ b/projects/demo/src/app/app.component.ts @@ -1,4 +1,4 @@ -import {ChangeDetectionStrategy, Component, Inject, SecurityContext} from '@angular/core'; +import {ChangeDetectionStrategy, Component, inject, SecurityContext} from '@angular/core'; import {DomSanitizer, SafeValue} from '@angular/platform-browser'; const dirtyHtml = @@ -13,11 +13,11 @@ const svg = ` changeDetection: ChangeDetectionStrategy.OnPush, }) export class AppComponent { + private readonly sanitizer = inject(DomSanitizer); + value = dirtyHtml; domValue = svg; - constructor(@Inject(DomSanitizer) private readonly sanitizer: DomSanitizer) {} - unwrap(value: SafeValue | null): string { return this.sanitizer.sanitize(SecurityContext.HTML, value) || ''; } diff --git a/projects/ng-dompurify/lib/ng-dompurify.pipe.ts b/projects/ng-dompurify/lib/ng-dompurify.pipe.ts index 4ee67a3..1cc8e34 100644 --- a/projects/ng-dompurify/lib/ng-dompurify.pipe.ts +++ b/projects/ng-dompurify/lib/ng-dompurify.pipe.ts @@ -1,4 +1,4 @@ -import {Inject, Pipe, PipeTransform, SecurityContext} from '@angular/core'; +import {inject, Pipe, PipeTransform, SecurityContext} from '@angular/core'; import {DomSanitizer, SafeValue} from '@angular/platform-browser'; import {NgDompurifySanitizer} from './ng-dompurify.service'; @@ -12,10 +12,8 @@ import {NgDompurifyConfig} from './types/ng-dompurify-config'; name: 'dompurify', }) export class NgDompurifyPipe implements PipeTransform { - constructor( - @Inject(NgDompurifySanitizer) private readonly sanitizer: NgDompurifySanitizer, - @Inject(DomSanitizer) private readonly domSanitizer: DomSanitizer, - ) {} + private readonly sanitizer = inject(NgDompurifySanitizer); + private readonly domSanitizer = inject(DomSanitizer); transform( value: Record | string | null, diff --git a/projects/ng-dompurify/lib/ng-dompurify.service.ts b/projects/ng-dompurify/lib/ng-dompurify.service.ts index 73ef15b..66e6059 100644 --- a/projects/ng-dompurify/lib/ng-dompurify.service.ts +++ b/projects/ng-dompurify/lib/ng-dompurify.service.ts @@ -1,13 +1,11 @@ import {DOCUMENT} from '@angular/common'; -import {Inject, Injectable, Sanitizer, SecurityContext} from '@angular/core'; +import {inject, Injectable, Sanitizer, SecurityContext} from '@angular/core'; import dompurify, {DOMPurifyI} from 'dompurify'; import {DOMPURIFY_CONFIG} from './tokens/dompurify-config'; import {DOMPURIFY_HOOKS} from './tokens/dompurify-hooks'; import {SANITIZE_STYLE} from './tokens/sanitize-style'; import {NgDompurifyConfig} from './types/ng-dompurify-config'; -import {NgDompurifyHook} from './types/ng-dompurify-hook'; -import {SanitizeStyle} from './types/sanitize-style'; const createDOMPurify = dompurify; @@ -25,20 +23,14 @@ const createDOMPurify = dompurify; providedIn: 'root', }) export class NgDompurifySanitizer implements Sanitizer { + private readonly config = inject(DOMPURIFY_CONFIG); + private readonly sanitizeStyle = inject(SANITIZE_STYLE); private readonly domPurify: DOMPurifyI; - constructor( - @Inject(DOMPURIFY_CONFIG) - private readonly config: NgDompurifyConfig, - @Inject(SANITIZE_STYLE) - private readonly sanitizeStyle: SanitizeStyle, - @Inject(DOCUMENT) {defaultView}: Document, - @Inject(DOMPURIFY_HOOKS) - hooks: readonly NgDompurifyHook[], - ) { - this.domPurify = createDOMPurify(defaultView as Window); + constructor() { + this.domPurify = createDOMPurify(inject(DOCUMENT).defaultView as Window); - hooks.forEach(({name, hook}) => { + inject(DOMPURIFY_HOOKS).forEach(({name, hook}) => { this.domPurify.addHook(name, hook); }); }