| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 2 年前 | ||
| 11 个月前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 11 个月前 | ||
| 1 年前 | ||
| 11 个月前 | ||
| 11 个月前 | ||
| 11 个月前 | ||
| 1 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 | ||
| 2 年前 |
entities
简介
entities 快速地编码和解码HTML和XML实体
下载安装
ohpm install entities
OpenHarmony ohpm环境配置等更多内容,请参考 如何安装OpenHarmony ohpm包 。
使用说明
- 引入文件及代码依赖
import {
decode,
decodeHTML,
decodeHTMLStrict,
decodeXML,
encode,
encodeHTML,
encodeNonAsciiHTML,
encodeXML,
EntityLevel,
escapeUTF8,
decodeHTMLAttribute
} from 'entities';
encode("& ü", EntityLevel.HTML)
encode("& ü")
encodeXML("& ü")
encodeHTML("& ü")
encodeNonAsciiHTML("& ü")
decode("asdf & ÿ ü '", EntityLevel.HTML)
decodeHTMLAttribute("asdf & ÿ ü '")
decode("asdf & ÿ ü '")
decodeXML("asdf & ÿ ü '")
decodeHTML("asdf & ÿ ü '")
decodeHTMLStrict("asdf & ÿ")
escapeUTF8("(&>)")
escapeAttribute("(&>)")
escapeText("(&>)")
接口说明
-
解码HTML
decodeHTML(str: string, mode = DecodingMode.Legacy): string -
解码XML
decodeXML(str: string): string -
对HTML字符串进行解码,要求所有实体均以分号结束。
decodeHTMLStrict(str: string): string -
编码HTML
encodeHTML(data: string): string -
对所有非ASCII字符以及在HTML文档中无效的字符进行编码
encodeNonAsciiHTML(data: string): string -
编码XML
encodeXML(str: string): string -
解码带有实体的字符串
decode(data: string, options: DecodingOptions | EntityLevel = EntityLevel.XML): string -
编码带有实体的字符串
encode(data: string, options: EncodingOptions | EntityLevel = EntityLevel.XML): string -
解码HTML属性
decodeHTMLAttribute(str: string): string -
转义xml中UTF-8编码的转义字符
escapeUTF8: (data: string) => string -
转义HTML属性中需要转义的字符
escapeAttribute: (data: string) => string -
转义HTML文本中需要转义的字符
escapeText: (data: string) => string
约束与限制
在下述版本验证通过:
-
DevEco Studio 版本:4.1 Canary(4.1.3.317),OpenHarmony SDK:API11 (4.1.0.36)
-
DevEco Studio 版本:DevEco Studio 5.1.0 Canary1(5.1.0.229),OpenHarmony SDK:5.1.0.229 API16(5.1.0.46)。
目录结构
|---- entities
| |---- entry # 示例代码文件夹
| |---- src
| |---- ohosTest
| |---- ets
| |---- test
| |---- Ability.test.ets # 单元测试
| |---- README.md # 安装使用方法
| |---- README.OpenSource # 开源说明
| |---- CHANGELOG.md # 更新日志
贡献代码
使用过程中发现任何问题都可以提 Issue给我们,当然,我们也非常欢迎你给我们发 PR 。
开源协议
本项目基于 BSD License,请自由地享受和参与开源。