@ditojs/utils 2.69.0 → 2.71.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ditojs/utils",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.71.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Dito.js Utility Functions – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
|
|
6
6
|
"repository": "https://github.com/ditojs/dito/tree/master/packages/utils",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"typescript": "^5.9.3"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e5a095c7c44de8b6c84994d744612f0fce19eae2"
|
|
43
43
|
}
|
package/src/html/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './escapeHtml.js'
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './stripHtml.js'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { deprecate } from '../function/deprecate.js'
|
|
2
|
+
|
|
3
|
+
export function stripHtml(html) {
|
|
4
|
+
return html != null
|
|
5
|
+
? html
|
|
6
|
+
.toString()
|
|
7
|
+
.replace(/<br\/?>/gi, '\n')
|
|
8
|
+
.replace(/<[^>]+>/g, '')
|
|
9
|
+
: ''
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @deprecated Use stripHtml() instead
|
|
14
|
+
*/
|
|
15
|
+
export function stripTags(html) {
|
|
16
|
+
deprecate(
|
|
17
|
+
'The `stripTags` function is deprecated in favour of `stripHtml`. ' +
|
|
18
|
+
'Update your code to use `stripHtml` instead.'
|
|
19
|
+
)
|
|
20
|
+
return stripHtml(html)
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { stripHtml } from './stripHtml.js'
|
|
2
|
+
|
|
3
|
+
describe('stripHtml()', () => {
|
|
4
|
+
it('should remove html tags from strings', () => {
|
|
5
|
+
expect(stripHtml('<p><b>this</b> is a marked-up string</p>'))
|
|
6
|
+
.toBe('this is a marked-up string')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('should return an empty string if nothing can be processed', () => {
|
|
10
|
+
expect(stripHtml()).toBe('')
|
|
11
|
+
expect(stripHtml(null)).toBe('')
|
|
12
|
+
expect(stripHtml('')).toBe('')
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should handle falsy values correctly', () => {
|
|
16
|
+
expect(stripHtml(0)).toBe('0')
|
|
17
|
+
expect(stripHtml(false)).toBe('false')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('should convert <br> tags to line-breaks', () => {
|
|
21
|
+
expect(stripHtml('hello<br>world')).toBe('hello\nworld')
|
|
22
|
+
expect(stripHtml('hello<br/>world')).toBe('hello\nworld')
|
|
23
|
+
})
|
|
24
|
+
})
|
package/types/index.d.ts
CHANGED
|
@@ -702,6 +702,14 @@ export function escapeHtml(html: string): string
|
|
|
702
702
|
* @param html The string to strip.
|
|
703
703
|
* @returns The newly stripped string.
|
|
704
704
|
*/
|
|
705
|
+
export function stripHtml(html: string): string
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Strips HTML tags from the string.
|
|
709
|
+
* @param html The string to strip.
|
|
710
|
+
* @returns The newly stripped string.
|
|
711
|
+
* @deprecated Use stripHtml() instead
|
|
712
|
+
*/
|
|
705
713
|
export function stripTags(html: string): string
|
|
706
714
|
|
|
707
715
|
/* -------------------------- typescript utilities -------------------------- */
|
package/src/html/stripTags.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { stripTags } from './stripTags.js'
|
|
2
|
-
|
|
3
|
-
describe('stripTags()', () => {
|
|
4
|
-
it('should remove html tags from strings', () => {
|
|
5
|
-
expect(stripTags('<p><b>this</b> is a marked-up string</p>'))
|
|
6
|
-
.toBe('this is a marked-up string')
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
it('should return an empty string if nothing can be processed', () => {
|
|
10
|
-
expect(stripTags()).toBe('')
|
|
11
|
-
expect(stripTags(null)).toBe('')
|
|
12
|
-
expect(stripTags('')).toBe('')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should handle falsy values correctly', () => {
|
|
16
|
-
expect(stripTags(0)).toBe('0')
|
|
17
|
-
expect(stripTags(false)).toBe('false')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('should convert <br> tags to line-breaks', () => {
|
|
21
|
-
expect(stripTags('hello<br>world')).toBe('hello\nworld')
|
|
22
|
-
expect(stripTags('hello<br/>world')).toBe('hello\nworld')
|
|
23
|
-
})
|
|
24
|
-
})
|