Skip to content

Commit

Permalink
feat: add unicode en/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
geminate committed Nov 9, 2018
1 parent 6cc3aae commit e5ae225
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d-tools",
"version": "0.1.5",
"version": "0.1.6",
"author": "liuhuihao <[email protected]>",
"description": "d-tools is a toolbox for developers.Formatter, Base64, Regex test,Host manager and so on.",
"license": "MIT",
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/pages/textTransform/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<el-radio size="mini" v-model="codeType" label="2" border>MD5</el-radio>
<el-radio size="mini" v-model="codeType" label="3" border>URI</el-radio>
<el-radio size="mini" v-model="codeType" label="4" border>URIComponent</el-radio>
<el-radio size="mini" v-model="codeType" label="5" border>Unicode</el-radio>
</div>
<div class="btn-container">
<el-button size="mini" type="success" @click="encode">{{$t('encrypt')}}</el-button>
Expand Down Expand Up @@ -118,13 +119,15 @@
this.codeType == '2' && this.md5Encode();
this.codeType == '3' && this.uriEncode();
this.codeType == '4' && this.uriComponentEncode();
this.codeType == '5' && this.unicodeEncode();
},
decode() {
this.initMessage();
this.history.push(this.text);
this.codeType == '1' && this.base64Decode();
this.codeType == '3' && this.uriDecode
this.codeType == '4' && this.uriComponentDecode();
this.codeType == '5' && this.unicodeDecode();
},
format() {
this.initMessage();
Expand Down Expand Up @@ -178,6 +181,16 @@
uriComponentDecode() {
this.text = decodeURIComponent(this.text);
this.setMessage(`URIComponent ${this.$t('decryptSuccess')}`, "success");
},
unicodeEncode() {
let result = '';
for (let i = 0; i < this.text.length; i++) {
result += "\\u" + this.text.charCodeAt(i).toString(16);
}
this.text = result;
},
unicodeDecode() {
this.text = unescape(this.text.replace(/\\u/g, '%u'));
}
}
}
Expand Down

0 comments on commit e5ae225

Please sign in to comment.