Browse Source

增加html编码解码工具函数

ming 2 years ago
parent
commit
07ae5e0fc1
2 changed files with 13 additions and 1 deletions
  1. 1 1
      package.json
  2. 12 0
      utils/utils.js

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "fs-uni",
-  "version": "2.5.1",
+  "version": "2.5.2",
   "description": "",
   "main": "main.js",
   "dependencies": {

+ 12 - 0
utils/utils.js

@@ -4,6 +4,18 @@ export default {
 	isHttp(path) {
 		return path.startsWith('http') || path.startsWith('https')
 	},
+	escapeHTML(a) {
+		a = "" + a;  
+		return a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&apos;")
+	},  
+	/** 
+	 * @function unescapeHTML 还原html脚本 < > & " ' 
+	 * @param a - 字符串 
+	 */  
+	unescapeHTML(a){  
+		a = "" + a;  
+		return a.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(/&apos;/g, "'")
+	},
 	uuid(len = 16) {
 		const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
 		const uuid = []