-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpw.js
More file actions
40 lines (31 loc) · 900 Bytes
/
pw.js
File metadata and controls
40 lines (31 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//특수문자인지 check
function containsSpecialChars(str) {
const specialChars = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
return specialChars.test(str);
}
//특수문자를 hex로 변환
String.prototype.hexEncode = function () {
var hex, i;
var result = "";
for (i = 0; i < this.length; i++) {
hex = this.charCodeAt(i).toString(16);
result += hex;
}
return '%' + result
}
//특정 인덱스 문자 변환
String.prototype.replaceAt = function (index, replacement) {
return this.substring(0, index) + replacement + this.substring(index + replacement.length);
}
function transSpecialToHex(str) {
for (i = 0; i < str.length; i++) {
if (containsSpecialChars(str[i])) {
str = str.replaceAt(i, str[i].hexEncode())
}
}
return str;
}
module.exports = {
transSpecialToHex,
containsSpecialChars,
}