Explorar o código

feat[utils]: stripHtmlTags

chenlei hai 6 meses
pai
achega
6dbe468bcb

+ 9 - 0
packages/backend-cli/template/CHANGELOG.md

@@ -1,5 +1,14 @@
 # @dage/backend-template
 
+## 1.0.16
+
+### Patch Changes
+
+- Updated dependencies
+  - @dage/utils@1.1.1
+  - @dage/pc-components@1.3.5
+  - @dage/service@1.0.5
+
 ## 1.0.15
 
 ### Patch Changes

+ 1 - 1
packages/backend-cli/template/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@dage/backend-template",
-  "version": "1.0.15",
+  "version": "1.0.16",
   "private": true,
   "dependencies": {
     "@ant-design/icons": "^5.1.4",

+ 8 - 0
packages/docs/docs/log/PC-COMPONENTS_CHANGELOG.md

@@ -1,5 +1,13 @@
 # @dage/pc-components
 
+## 1.3.5
+
+### Patch Changes
+
+- Updated dependencies
+  - @dage/utils@1.1.1
+  - @dage/service@1.0.5
+
 ## 1.3.4
 
 ### Patch Changes

+ 7 - 0
packages/docs/docs/log/SERVICE_CHANGELOG.md

@@ -1,5 +1,12 @@
 # @dage/service
 
+## 1.0.5
+
+### Patch Changes
+
+- Updated dependencies
+  - @dage/utils@1.1.1
+
 ## 1.0.4
 
 ### Patch Changes

+ 6 - 0
packages/docs/docs/log/UTILS_CHANGELOG.md

@@ -1,5 +1,11 @@
 # @dage/utils
 
+## 1.1.1
+
+### Patch Changes
+
+- 新增 stripHtmlTags 方法
+
 ## 1.1.0
 
 ### Minor Changes

+ 50 - 35
packages/docs/docs/utils/string.md

@@ -1,35 +1,50 @@
-## 方法
-
-### addTrailingSlash 字符串`末尾`添加`/`
-
-```typescript
-addTrailingSlash("http://localhost:8000");
-// => http://localhost:8000/
-```
-
-| Name | Description | Type      | Default      |
-| ---- | ----------- | --------- | ------------ |
-| path | `--`        | `string ` | `(required)` |
-
-### removeHeadingString 删除特定`开头`的`字符串`
-
-```typescript
-removeHeadingString("/api/example", "/api");
-// => /example
-```
-
-| Name    | Description | Type      | Default      |
-| ------- | ----------- | --------- | ------------ |
-| path    | `--`        | `string ` | `(required)` |
-| heading | `--`        | `string ` | `(required)` |
-
-### removeHeadingSlash 删除字符串`开头`的`/`
-
-```typescript
-removeHeadingSlash("/api/example");
-// => api/example
-```
-
-| Name | Description | Type      | Default      |
-| ---- | ----------- | --------- | ------------ |
-| path | `--`        | `string ` | `(required)` |
+## 方法
+
+### addTrailingSlash 字符串`末尾`添加`/`
+
+```typescript
+addTrailingSlash("http://localhost:8000");
+// => http://localhost:8000/
+```
+
+| Name | Description | Type      | Default      |
+| ---- | ----------- | --------- | ------------ |
+| path | `--`        | `string ` | `(required)` |
+
+### removeHeadingString 删除特定`开头`的`字符串`
+
+```typescript
+removeHeadingString("/api/example", "/api");
+// => /example
+```
+
+| Name    | Description | Type      | Default      |
+| ------- | ----------- | --------- | ------------ |
+| path    | `--`        | `string ` | `(required)` |
+| heading | `--`        | `string ` | `(required)` |
+
+### removeHeadingSlash 删除字符串`开头`的`/`
+
+```typescript
+removeHeadingSlash("/api/example");
+// => api/example
+```
+
+| Name | Description | Type      | Default      |
+| ---- | ----------- | --------- | ------------ |
+| path | `--`        | `string ` | `(required)` |
+
+### 去除字符串中的 HTML 标签
+
+```typescript
+stripHtmlTags(
+  '<p>This is a <b>sample</b> text with <a href="#">HTML tags</a>.</p>',
+  20
+);
+// => This is a sample text..
+```
+
+| Name      | Description | Type      | Default      |
+| --------- | ----------- | --------- | ------------ |
+| input     | `文本`      | `string ` | `(required)` |
+| maxLength | `最大长度`  | `string ` | `(required)` |

+ 8 - 0
packages/pc-components/CHANGELOG.md

@@ -1,5 +1,13 @@
 # @dage/pc-components
 
+## 1.3.5
+
+### Patch Changes
+
+- Updated dependencies
+  - @dage/utils@1.1.1
+  - @dage/service@1.0.5
+
 ## 1.3.4
 
 ### Patch Changes

+ 1 - 1
packages/pc-components/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@dage/pc-components",
-  "version": "1.3.4",
+  "version": "1.3.5",
   "description": "PC 端组件库",
   "module": "dist/index.js",
   "main": "dist/index.js",

+ 7 - 0
packages/service/CHANGELOG.md

@@ -1,5 +1,12 @@
 # @dage/service
 
+## 1.0.5
+
+### Patch Changes
+
+- Updated dependencies
+  - @dage/utils@1.1.1
+
 ## 1.0.4
 
 ### Patch Changes

+ 1 - 1
packages/service/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@dage/service",
-  "version": "1.0.4",
+  "version": "1.0.5",
   "description": "接口请求工具",
   "module": "dist/index.js",
   "main": "dist/index.js",

+ 6 - 0
packages/utils/CHANGELOG.md

@@ -1,5 +1,11 @@
 # @dage/utils
 
+## 1.1.1
+
+### Patch Changes
+
+- 新增 stripHtmlTags 方法
+
 ## 1.1.0
 
 ### Minor Changes

+ 1 - 1
packages/utils/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@dage/utils",
-  "version": "1.1.0",
+  "version": "1.1.1",
   "description": "工具类",
   "sideEffects": false,
   "module": "dist/index.js",

+ 33 - 20
packages/utils/src/string.ts

@@ -1,20 +1,33 @@
-/**
- * 字符串`末尾`添加`/`
- */
-export function addTrailingSlash(path: string) {
-  return path.endsWith("/") ? path : path + "/";
-}
-
-/**
- * 删除特定`开头`的`字符串`
- */
-export function removeHeadingString(path: string, heading: string) {
-  return path.startsWith(heading) ? path.slice(heading.length) : path;
-}
-
-/**
- * 删除字符串`开头`的`/`
- */
-export function removeHeadingSlash(path: string) {
-  return removeHeadingString(path, "/");
-}
+/**
+ * 字符串`末尾`添加`/`
+ */
+export function addTrailingSlash(path: string) {
+  return path.endsWith("/") ? path : path + "/";
+}
+
+/**
+ * 删除特定`开头`的`字符串`
+ */
+export function removeHeadingString(path: string, heading: string) {
+  return path.startsWith(heading) ? path.slice(heading.length) : path;
+}
+
+/**
+ * 删除字符串`开头`的`/`
+ */
+export function removeHeadingSlash(path: string) {
+  return removeHeadingString(path, "/");
+}
+
+/**
+ * 去除字符串中的 HTML 标签
+ */
+export function stripHtmlTags(input: string, maxLength: number): string {
+  const strippedText = input.replace(/<[^>]*>/g, "");
+
+  if (strippedText.length > maxLength) {
+    return strippedText.substring(0, maxLength) + "...";
+  }
+
+  return strippedText;
+}