@ditojs/utils 2.69.0 → 2.70.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.69.0",
3
+ "version": "2.70.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": "a2b28ad175cd3280ceadd394c74ba67e12da03af"
42
+ "gitHead": "2010c0695b5a7296e10c2b6bf2539d552c576fd9"
43
43
  }
@@ -78,6 +78,7 @@ exports[`index > exports all symbols 1`] = `
78
78
  "setDataPathEntries": [Function],
79
79
  "setValueAtDataPath": [Function],
80
80
  "shuffle": [Function],
81
+ "stripHtml": [Function],
81
82
  "stripTags": [Function],
82
83
  "toAsync": [Function],
83
84
  "toCallback": [Function],
package/src/html/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from './escapeHtml.js'
2
- export * from './stripTags.js'
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 -------------------------- */
@@ -1,10 +0,0 @@
1
- // TODO: Rename to stripHtml()
2
-
3
- export function stripTags(html) {
4
- return html != null
5
- ? html
6
- .toString()
7
- .replace(/<br\/?>/gi, '\n')
8
- .replace(/<[^>]+>/g, '')
9
- : ''
10
- }
@@ -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
- })