@ditojs/utils 2.73.0 → 2.75.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.73.0",
3
+ "version": "2.75.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": "0afe5ac938419c584db685cddcbd8974ee000d7e"
42
+ "gitHead": "cfc4ee21dc3f5808b5a78a3b1fab83500c05907a"
43
43
  }
@@ -4,8 +4,10 @@ export function stripHtml(html) {
4
4
  return html != null
5
5
  ? html
6
6
  .toString()
7
- .replace(/<br\/?>/gi, '\n')
7
+ .replace(/<br\s*\/?>/gi, '\n')
8
+ .replace(/<\/p>/gi, '\n')
8
9
  .replace(/<[^>]+>/g, '')
10
+ .trim()
9
11
  : ''
10
12
  }
11
13
 
@@ -20,5 +20,18 @@ describe('stripHtml()', () => {
20
20
  it('should convert <br> tags to line-breaks', () => {
21
21
  expect(stripHtml('hello<br>world')).toBe('hello\nworld')
22
22
  expect(stripHtml('hello<br/>world')).toBe('hello\nworld')
23
+ expect(stripHtml('hello<br />world')).toBe('hello\nworld')
24
+ })
25
+
26
+ it('should convert <p> tags to line-breaks', () => {
27
+ expect(stripHtml('<p>First paragraph</p><p>Second paragraph</p>'))
28
+ .toBe('First paragraph\nSecond paragraph')
29
+ expect(stripHtml('<p>Only paragraph</p>'))
30
+ .toBe('Only paragraph')
31
+ })
32
+
33
+ it('should trim leading and trailing whitespace', () => {
34
+ expect(stripHtml(' <p>text</p> ')).toBe('text')
35
+ expect(stripHtml('<p> text </p>')).toBe('text')
23
36
  })
24
37
  })