forked from locutusjs/locutus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstripslashes.js
28 lines (28 loc) · 908 Bytes
/
stripslashes.js
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
function stripslashes (str) {
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Ates Goral (http://magnetiq.com)
// + fixed by: Mick@el
// + improved by: marrtins
// + bugfixed by: Onno Marsman
// + improved by: rezna
// + input by: Rick Waldron
// + reimplemented by: Brett Zamir (http://brett-zamir.me)
// + input by: Brant Messenger (http://www.brantmessenger.com/)
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// * example 1: stripslashes('Kevin\'s code');
// * returns 1: "Kevin's code"
// * example 2: stripslashes('Kevin\\\'s code');
// * returns 2: "Kevin\'s code"
return (str + '').replace(/\\(.?)/g, function (s, n1) {
switch (n1) {
case '\\':
return '\\';
case '0':
return '\u0000';
case '':
return '';
default:
return n1;
}
});
}