@ditojs/utils
Advanced tools
| import { deprecate } from '../function/deprecate.js' | ||
| export function stripHtml(html) { | ||
| return html != null | ||
| ? html | ||
| .toString() | ||
| .replace(/<br\/?>/gi, '\n') | ||
| .replace(/<[^>]+>/g, '') | ||
| : '' | ||
| } | ||
| /** | ||
| * @deprecated Use stripHtml() instead | ||
| */ | ||
| export function stripTags(html) { | ||
| deprecate( | ||
| 'The `stripTags` function is deprecated in favour of `stripHtml`. ' + | ||
| 'Update your code to use `stripHtml` instead.' | ||
| ) | ||
| return stripHtml(html) | ||
| } |
| import { stripHtml } from './stripHtml.js' | ||
| describe('stripHtml()', () => { | ||
| it('should remove html tags from strings', () => { | ||
| expect(stripHtml('<p><b>this</b> is a marked-up string</p>')) | ||
| .toBe('this is a marked-up string') | ||
| }) | ||
| it('should return an empty string if nothing can be processed', () => { | ||
| expect(stripHtml()).toBe('') | ||
| expect(stripHtml(null)).toBe('') | ||
| expect(stripHtml('')).toBe('') | ||
| }) | ||
| it('should handle falsy values correctly', () => { | ||
| expect(stripHtml(0)).toBe('0') | ||
| expect(stripHtml(false)).toBe('false') | ||
| }) | ||
| it('should convert <br> tags to line-breaks', () => { | ||
| expect(stripHtml('hello<br>world')).toBe('hello\nworld') | ||
| expect(stripHtml('hello<br/>world')).toBe('hello\nworld') | ||
| }) | ||
| }) |
+2
-2
| { | ||
| "name": "@ditojs/utils", | ||
| "version": "2.69.0", | ||
| "version": "2.70.0", | ||
| "type": "module", | ||
@@ -42,3 +42,3 @@ "description": "Dito.js Utility Functions – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js", | ||
| }, | ||
| "gitHead": "a2b28ad175cd3280ceadd394c74ba67e12da03af" | ||
| "gitHead": "2010c0695b5a7296e10c2b6bf2539d552c576fd9" | ||
| } |
| export * from './escapeHtml.js' | ||
| export * from './stripTags.js' | ||
| export * from './stripHtml.js' |
+8
-0
@@ -705,2 +705,10 @@ // Type definitions for Dito.js utils | ||
| */ | ||
| export function stripHtml(html: string): string | ||
| /** | ||
| * Strips HTML tags from the string. | ||
| * @param html The string to strip. | ||
| * @returns The newly stripped string. | ||
| * @deprecated Use stripHtml() instead | ||
| */ | ||
| export function stripTags(html: string): string | ||
@@ -707,0 +715,0 @@ |
| // TODO: Rename to stripHtml() | ||
| export function stripTags(html) { | ||
| return html != null | ||
| ? html | ||
| .toString() | ||
| .replace(/<br\/?>/gi, '\n') | ||
| .replace(/<[^>]+>/g, '') | ||
| : '' | ||
| } |
| import { stripTags } from './stripTags.js' | ||
| describe('stripTags()', () => { | ||
| it('should remove html tags from strings', () => { | ||
| expect(stripTags('<p><b>this</b> is a marked-up string</p>')) | ||
| .toBe('this is a marked-up string') | ||
| }) | ||
| it('should return an empty string if nothing can be processed', () => { | ||
| expect(stripTags()).toBe('') | ||
| expect(stripTags(null)).toBe('') | ||
| expect(stripTags('')).toBe('') | ||
| }) | ||
| it('should handle falsy values correctly', () => { | ||
| expect(stripTags(0)).toBe('0') | ||
| expect(stripTags(false)).toBe('false') | ||
| }) | ||
| it('should convert <br> tags to line-breaks', () => { | ||
| expect(stripTags('hello<br>world')).toBe('hello\nworld') | ||
| expect(stripTags('hello<br/>world')).toBe('hello\nworld') | ||
| }) | ||
| }) |
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
160087
0.32%6002
0.28%