Fix: CSP unsafe-inline #13

This commit is contained in:
surunzi
2017-09-30 17:35:38 +08:00
parent f869424b61
commit 53af28c142
3 changed files with 172 additions and 52 deletions

View File

@@ -566,6 +566,24 @@ module.exports = (function ()
return exports;
})();
/* ------------------------------ isBrowser ------------------------------ */
var isBrowser = _.isBrowser = (function (exports)
{
/* Check if running in a browser.
*
* ```javascript
* console.log(isBrowser); // -> true if running in a browser
* ```
*/
exports = typeof window === 'object' &&
typeof document === 'object' &&
document.nodeType === 9;
return exports;
})({});
/* ------------------------------ optimizeCb ------------------------------ */
var optimizeCb = _.optimizeCb = (function ()
@@ -1091,6 +1109,12 @@ module.exports = (function ()
* |------|-------|-------------------------------------|
* |value |* |Value to check |
* |return|boolean|True if value is correctly classified|
*
* ```javascript
* isNum(5); // -> true
* isNum(5.1); // -> true
* isNum({}); // -> false
* ```
*/
/* dependencies
@@ -1609,24 +1633,6 @@ module.exports = (function ()
return exports;
})();
/* ------------------------------ isBrowser ------------------------------ */
var isBrowser = _.isBrowser = (function (exports)
{
/* Check if running in a browser.
*
* ```javascript
* console.log(isBrowser); // -> true if running in a browser
* ```
*/
exports = typeof window === 'object' &&
typeof document === 'object' &&
document.nodeType === 9;
return exports;
})({});
/* ------------------------------ isCrossOrig ------------------------------ */
_.isCrossOrig = (function ()
@@ -4382,6 +4388,128 @@ module.exports = (function ()
return exports;
})();
/* ------------------------------ toInt ------------------------------ */
var toInt = _.toInt = (function ()
{
/* Convert value to an integer.
*
* |Name |Type |Desc |
* |------|------|-----------------|
* |val |* |Value to convert |
* |return|number|Converted integer|
*
* ```javascript
* toInt(1.1); // -> 1
* toInt(undefined); // -> 0
* ```
*/
/* dependencies
* toNum
*/
function exports(val)
{
if (!val) return val === 0 ? val : 0;
val = toNum(val);
return val - val % 1;
}
return exports;
})();
/* ------------------------------ detectBrowser ------------------------------ */
_.detectBrowser = (function ()
{
/* Detect browser info using ua.
*
* |Name |Type |Desc |
* |------------------------|------|----------------------------------|
* |[ua=navigator.userAgent]|string|Browser userAgent |
* |return |object|Object containing name and version|
*
* Browsers supported: ie, chrome, edge, firefox, opera, safari, ios(mobile safari), android(android browser)
*
* ```javascript
* var browser = detectBrowser();
* if (browser.name === 'ie' && browser.version < 9)
* {
* // Do something about old IE...
* }
* ```
*/
/* dependencies
* isBrowser toInt keys
*/
function exports(ua)
{
ua = ua || (isBrowser ? navigator.userAgent : '');
ua = ua.toLowerCase();
var ieVer = getVer(ua, 'msie ');
if (ieVer) return {
version: ieVer,
name: 'ie'
};
if (regIe11.test(ua)) return {
version: 11,
name: 'ie'
};
for (var i = 0, len = browsers.length; i < len; i++)
{
var name = browsers[i],
match = ua.match(regBrowsers[name]);
if (match == null) continue;
var version = toInt(match[1].split('.')[0]);
if (name === 'opera') version = getVer(ua, 'version/') || version;
return {
name: name,
version: version
};
}
return {
name: 'unknown',
version: -1
};
}
var regBrowsers = {
'edge': /edge\/([0-9._]+)/,
'firefox': /firefox\/([0-9.]+)(?:\s|$)/,
'opera': /opera\/([0-9.]+)(?:\s|$)/,
'android': /android\s([0-9.]+)/,
'ios': /version\/([0-9._]+).*mobile.*safari.*/,
'safari': /version\/([0-9._]+).*safari/,
'chrome': /(?!chrom.*opr)chrom(?:e|ium)\/([0-9.]+)(:?\s|$)/
};
var regIe11 = /trident\/7\./,
browsers = keys(regBrowsers);
function getVer(ua, mark)
{
var idx = ua.indexOf(mark);
if (idx > -1) return toInt(ua.substring(idx + mark.length, ua.indexOf('.', idx)));
}
return exports;
})();
/* ------------------------------ rtrim ------------------------------ */
var rtrim = _.rtrim = (function ()
@@ -5039,39 +5167,6 @@ module.exports = (function ()
return exports;
})();
/* ------------------------------ toInt ------------------------------ */
_.toInt = (function ()
{
/* Convert value to an integer.
*
* |Name |Type |Desc |
* |------|------|-----------------|
* |val |* |Value to convert |
* |return|number|Converted integer|
*
* ```javascript
* toInt(1.1); // -> 1
* toInt(undefined); // -> 0
* ```
*/
/* dependencies
* toNum
*/
function exports(val)
{
if (!val) return val === 0 ? val : 0;
val = toNum(val);
return val - val % 1;
}
return exports;
})();
/* ------------------------------ uniqId ------------------------------ */
_.uniqId = (function ()