forked from inexorabletash/polyfill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
41 lines (37 loc) · 1.18 KB
/
js.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
29
30
31
32
33
34
35
36
37
38
39
40
41
//----------------------------------------------------------------------
//
// Non-standard JavaScript (Mozilla) functions
//
//----------------------------------------------------------------------
(function () {
'use strict';
// JavaScript 1.8.1
String.prototype.trimLeft = String.prototype.trimLeft || function () {
return String(this).replace(/^\s+/, '');
};
// JavaScript 1.8.1
String.prototype.trimRight = String.prototype.trimRight || function () {
return String(this).replace(/\s+$/, '');
};
// JavaScript 1.?
var ESCAPES = {
//'\x00': '\\0', Special case in FF3.6, removed by FF10
'\b': '\\b',
'\t': '\\t',
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'"' : '\\"',
'\\': '\\\\'
};
String.prototype.quote = String.prototype.quote || function() {
return '"' + String(this).replace(/[\x00-\x1F"\\\x7F-\uFFFF]/g, function(c) {
if (Object.prototype.hasOwnProperty.call(ESCAPES, c))
return ESCAPES[c];
var cc = c.charCodeAt(0);
if (cc <= 0xFF)
return '\\x' + ('00' + cc.toString(16).toUpperCase()).slice(-2);
return '\\u' + ('0000' + cc.toString(16).toUpperCase()).slice(-4);
}) + '"';
};
}());