mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 06:54:11 +08:00
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
const { dataConv } = require("./utils");
|
|
|
|
const encoder = {
|
|
// base64 编码
|
|
base64Encode: function (text) {
|
|
return dataConv(text, "utf8", "base64");
|
|
},
|
|
// base64 解码
|
|
base64Decode: function (text) {
|
|
return dataConv(text, "base64", "utf8");
|
|
},
|
|
// URL 编码
|
|
urlEncode: function (text) {
|
|
return encodeURIComponent(text);
|
|
},
|
|
// URL 解码
|
|
urlDecode: function (text) {
|
|
return decodeURIComponent(text);
|
|
},
|
|
// html 编码
|
|
htmlEncode: function (text) {
|
|
return text
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
},
|
|
// html 解码
|
|
htmlDecode: function (text) {
|
|
return text
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, "'");
|
|
},
|
|
// 十六进制
|
|
hexEncode: function (text) {
|
|
return dataConv(text, "utf8", "hex");
|
|
},
|
|
// 十六进制解码
|
|
hexDecode: function (text) {
|
|
return dataConv(text, "hex", "utf8");
|
|
},
|
|
};
|
|
|
|
module.exports = encoder;
|