Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xjbieke
axios
提交
f28a4a82
A
axios
项目概览
xjbieke
/
axios
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
axios
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f28a4a82
编写于
12月 14, 2015
作者:
M
Matt Zabriskie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Using more strict eslint rules
上级
2b147fb0
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
231 addition
and
94 deletion
+231
-94
.eslintrc
.eslintrc
+136
-1
lib/adapters/http.js
lib/adapters/http.js
+19
-19
lib/adapters/xhr.js
lib/adapters/xhr.js
+10
-11
lib/axios.js
lib/axios.js
+14
-21
lib/core/InterceptorManager.js
lib/core/InterceptorManager.js
+5
-5
lib/core/dispatchRequest.js
lib/core/dispatchRequest.js
+4
-5
lib/defaults.js
lib/defaults.js
+5
-4
lib/helpers/btoa.js
lib/helpers/btoa.js
+5
-4
lib/helpers/buildURL.js
lib/helpers/buildURL.js
+5
-6
lib/helpers/cookies.js
lib/helpers/cookies.js
+2
-2
lib/helpers/deprecatedMethod.js
lib/helpers/deprecatedMethod.js
+2
-0
lib/helpers/isURLSameOrigin.js
lib/helpers/isURLSameOrigin.js
+2
-2
lib/helpers/parseHeaders.js
lib/helpers/parseHeaders.js
+5
-2
lib/helpers/spread.js
lib/helpers/spread.js
+1
-1
lib/helpers/transformData.js
lib/helpers/transformData.js
+2
-1
lib/utils.js
lib/utils.js
+14
-10
未找到文件。
.eslintrc
浏览文件 @
f28a4a82
...
...
@@ -9,6 +9,141 @@
"node": true
},
"rules": {
"quotes": [2, "single"]
/**
* Strict mode
*/
"strict": [2, "global"], // http://eslint.org/docs/rules/strict
/**
* Variables
*/
"no-shadow": 2, // http://eslint.org/docs/rules/no-shadow
"no-shadow-restricted-names": 2, // http://eslint.org/docs/rules/no-shadow-restricted-names
"no-unused-vars": [2, { // http://eslint.org/docs/rules/no-unused-vars
"vars": "local",
"args": "after-used"
}],
"no-use-before-define": 2, // http://eslint.org/docs/rules/no-use-before-define
/**
* Possible errors
*/
"comma-dangle": [2, "never"], // http://eslint.org/docs/rules/comma-dangle
"no-cond-assign": [2, "except-parens"], // http://eslint.org/docs/rules/no-cond-assign
"no-console": 1, // http://eslint.org/docs/rules/no-console
"no-debugger": 1, // http://eslint.org/docs/rules/no-debugger
"no-alert": 1, // http://eslint.org/docs/rules/no-alert
"no-constant-condition": 1, // http://eslint.org/docs/rules/no-constant-condition
"no-dupe-keys": 2, // http://eslint.org/docs/rules/no-dupe-keys
"no-duplicate-case": 2, // http://eslint.org/docs/rules/no-duplicate-case
"no-empty": 2, // http://eslint.org/docs/rules/no-empty
"no-ex-assign": 2, // http://eslint.org/docs/rules/no-ex-assign
"no-extra-boolean-cast": 0, // http://eslint.org/docs/rules/no-extra-boolean-cast
"no-extra-semi": 2, // http://eslint.org/docs/rules/no-extra-semi
"no-func-assign": 2, // http://eslint.org/docs/rules/no-func-assign
"no-inner-declarations": 2, // http://eslint.org/docs/rules/no-inner-declarations
"no-invalid-regexp": 2, // http://eslint.org/docs/rules/no-invalid-regexp
"no-irregular-whitespace": 2, // http://eslint.org/docs/rules/no-irregular-whitespace
"no-obj-calls": 2, // http://eslint.org/docs/rules/no-obj-calls
"no-sparse-arrays": 2, // http://eslint.org/docs/rules/no-sparse-arrays
"no-unreachable": 2, // http://eslint.org/docs/rules/no-unreachable
"use-isnan": 2, // http://eslint.org/docs/rules/use-isnan
"block-scoped-var": 2, // http://eslint.org/docs/rules/block-scoped-var
/**
* Best practices
*/
"consistent-return": 2, // http://eslint.org/docs/rules/consistent-return
"curly": [2, "multi-line"], // http://eslint.org/docs/rules/curly
"default-case": 2, // http://eslint.org/docs/rules/default-case
"dot-notation": [2, { // http://eslint.org/docs/rules/dot-notation
"allowKeywords": true
}],
"eqeqeq": 2, // http://eslint.org/docs/rules/eqeqeq
"guard-for-in": 2, // http://eslint.org/docs/rules/guard-for-in
"no-caller": 2, // http://eslint.org/docs/rules/no-caller
"no-else-return": 2, // http://eslint.org/docs/rules/no-else-return
"no-eq-null": 2, // http://eslint.org/docs/rules/no-eq-null
"no-eval": 2, // http://eslint.org/docs/rules/no-eval
"no-extend-native": 2, // http://eslint.org/docs/rules/no-extend-native
"no-extra-bind": 2, // http://eslint.org/docs/rules/no-extra-bind
"no-fallthrough": 2, // http://eslint.org/docs/rules/no-fallthrough
"no-floating-decimal": 2, // http://eslint.org/docs/rules/no-floating-decimal
"no-implied-eval": 2, // http://eslint.org/docs/rules/no-implied-eval
"no-lone-blocks": 2, // http://eslint.org/docs/rules/no-lone-blocks
"no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func
"no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str
"no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign
"no-new": 2, // http://eslint.org/docs/rules/no-new
"no-new-func": 2, // http://eslint.org/docs/rules/no-new-func
"no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers
"no-octal": 2, // http://eslint.org/docs/rules/no-octal
"no-octal-escape": 2, // http://eslint.org/docs/rules/no-octal-escape
"no-param-reassign": 2, // http://eslint.org/docs/rules/no-param-reassign
"no-proto": 2, // http://eslint.org/docs/rules/no-proto
"no-redeclare": 2, // http://eslint.org/docs/rules/no-redeclare
"no-return-assign": 2, // http://eslint.org/docs/rules/no-return-assign
"no-script-url": 2, // http://eslint.org/docs/rules/no-script-url
"no-self-compare": 2, // http://eslint.org/docs/rules/no-self-compare
"no-sequences": 2, // http://eslint.org/docs/rules/no-sequences
"no-throw-literal": 2, // http://eslint.org/docs/rules/no-throw-literal
"no-with": 2, // http://eslint.org/docs/rules/no-with
"radix": 2, // http://eslint.org/docs/rules/radix
"vars-on-top": 0, // http://eslint.org/docs/rules/vars-on-top
"wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife
"yoda": 2, // http://eslint.org/docs/rules/yoda
/**
* Style
*/
"indent": [2, 2], // http://eslint.org/docs/rules/indent
"brace-style": [2, // http://eslint.org/docs/rules/brace-style
"1tbs", {
"allowSingleLine": true
}],
"quotes": [
2, "single", "avoid-escape" // http://eslint.org/docs/rules/quotes
],
"camelcase": [2, { // http://eslint.org/docs/rules/camelcase
"properties": "never"
}],
"comma-spacing": [2, { // http://eslint.org/docs/rules/comma-spacing
"before": false,
"after": true
}],
"comma-style": [2, "last"], // http://eslint.org/docs/rules/comma-style
"eol-last": 2, // http://eslint.org/docs/rules/eol-last
"func-names": 1, // http://eslint.org/docs/rules/func-names
"key-spacing": [2, { // http://eslint.org/docs/rules/key-spacing
"beforeColon": false,
"afterColon": true
}],
"new-cap": [2, { // http://eslint.org/docs/rules/new-cap
"newIsCap": true
}],
"no-multiple-empty-lines": [2, { // http://eslint.org/docs/rules/no-multiple-empty-lines
"max": 2
}],
"no-nested-ternary": 2, // http://eslint.org/docs/rules/no-nested-ternary
"no-new-object": 2, // http://eslint.org/docs/rules/no-new-object
"no-spaced-func": 2, // http://eslint.org/docs/rules/no-spaced-func
"no-trailing-spaces": 2, // http://eslint.org/docs/rules/no-trailing-spaces
"no-extra-parens": [2, "functions"], // http://eslint.org/docs/rules/no-extra-parens
"no-underscore-dangle": 0, // http://eslint.org/docs/rules/no-underscore-dangle
"one-var": [2, "never"], // http://eslint.org/docs/rules/one-var
"padded-blocks": [2, "never"], // http://eslint.org/docs/rules/padded-blocks
"semi": [2, "always"], // http://eslint.org/docs/rules/semi
"semi-spacing": [2, { // http://eslint.org/docs/rules/semi-spacing
"before": false,
"after": true
}],
"space-after-keywords": 2, // http://eslint.org/docs/rules/space-after-keywords
"space-before-blocks": 2, // http://eslint.org/docs/rules/space-before-blocks
"space-before-function-paren": [2, "never"], // http://eslint.org/docs/rules/space-before-function-paren
"space-infix-ops": 2, // http://eslint.org/docs/rules/space-infix-ops
"space-return-throw-case": 2, // http://eslint.org/docs/rules/space-return-throw-case
"spaced-comment": [2, "always", {// http://eslint.org/docs/rules/spaced-comment
"markers": ["global", "eslint"]
}]
}
}
lib/adapters/http.js
浏览文件 @
f28a4a82
...
...
@@ -68,35 +68,35 @@ module.exports = function httpAdapter(resolve, reject, config) {
// Create the request
var
transport
=
parsed
.
protocol
===
'
https:
'
?
https
:
http
;
var
req
=
transport
.
request
(
options
,
function
(
res
)
{
var
req
=
transport
.
request
(
options
,
function
handleResponse
(
res
)
{
// uncompress the response body transparently if required
var
stream
=
res
;
switch
(
res
.
headers
[
'
content-encoding
'
])
{
case
'
gzip
'
:
case
'
compress
'
:
case
'
deflate
'
:
{
// add the unzipper to the body stream processing pipeline
stream
=
stream
.
pipe
(
zlib
.
createUnzip
());
// remove the content-encoding in order to not confuse downstream operations
delete
res
.
headers
[
'
content-encoding
'
];
}
switch
(
res
.
headers
[
'
content-encoding
'
])
{
/*eslint default-case:0*/
case
'
gzip
'
:
case
'
compress
'
:
case
'
deflate
'
:
// add the unzipper to the body stream processing pipeline
stream
=
stream
.
pipe
(
zlib
.
createUnzip
());
// remove the content-encoding in order to not confuse downstream operations
delete
res
.
headers
[
'
content-encoding
'
];
break
;
}
var
responseBuffer
=
[];
stream
.
on
(
'
data
'
,
function
(
chunk
)
{
stream
.
on
(
'
data
'
,
function
handleStreamData
(
chunk
)
{
responseBuffer
.
push
(
chunk
);
});
stream
.
on
(
'
end
'
,
function
()
{
var
d
ata
=
Buffer
.
concat
(
responseBuffer
);
stream
.
on
(
'
end
'
,
function
handleStreamEnd
()
{
var
d
=
Buffer
.
concat
(
responseBuffer
);
if
(
config
.
responseType
!==
'
arraybuffer
'
)
{
d
ata
=
data
.
toString
(
'
utf8
'
);
d
=
d
.
toString
(
'
utf8
'
);
}
var
response
=
{
data
:
transformData
(
d
ata
,
d
,
res
.
headers
,
config
.
transformResponse
),
...
...
@@ -114,12 +114,12 @@ module.exports = function httpAdapter(resolve, reject, config) {
});
// Handle errors
req
.
on
(
'
error
'
,
function
(
err
)
{
req
.
on
(
'
error
'
,
function
handleRequestError
(
err
)
{
reject
(
err
);
});
// Handle request timeout
req
.
setTimeout
(
config
.
timeout
,
function
()
{
req
.
setTimeout
(
config
.
timeout
,
function
handleRequestTimeout
()
{
req
.
abort
();
});
...
...
lib/adapters/xhr.js
浏览文件 @
f28a4a82
...
...
@@ -29,13 +29,13 @@ module.exports = function xhrAdapter(resolve, reject, config) {
delete
requestHeaders
[
'
Content-Type
'
];
// Let the browser set it
}
var
a
dapter
=
(
XMLHttpRequest
||
ActiveXObject
);
var
A
dapter
=
(
XMLHttpRequest
||
ActiveXObject
);
var
loadEvent
=
'
onreadystatechange
'
;
var
xDomain
=
false
;
// For IE 8/9 CORS support
if
(
!
isURLSameOrigin
(
config
.
url
)
&&
window
.
XDomainRequest
)
{
a
dapter
=
window
.
XDomainRequest
;
if
(
!
isURLSameOrigin
(
config
.
url
)
&&
window
.
XDomainRequest
)
{
A
dapter
=
window
.
XDomainRequest
;
loadEvent
=
'
onload
'
;
xDomain
=
true
;
}
...
...
@@ -44,18 +44,18 @@ module.exports = function xhrAdapter(resolve, reject, config) {
if
(
config
.
auth
)
{
var
username
=
config
.
auth
.
username
||
''
;
var
password
=
config
.
auth
.
password
||
''
;
requestHeaders
[
'
Authorization
'
]
=
'
Basic
'
+
btoa
(
username
+
'
:
'
+
password
);
requestHeaders
.
Authorization
=
'
Basic
'
+
btoa
(
username
+
'
:
'
+
password
);
}
// Create the request
var
request
=
new
a
dapter
(
'
Microsoft.XMLHTTP
'
);
var
request
=
new
A
dapter
(
'
Microsoft.XMLHTTP
'
);
request
.
open
(
config
.
method
.
toUpperCase
(),
buildURL
(
config
.
url
,
config
.
params
,
config
.
paramsSerializer
),
true
);
// Set the request timeout in MS
request
.
timeout
=
config
.
timeout
;
// Listen for ready state
request
[
loadEvent
]
=
function
()
{
request
[
loadEvent
]
=
function
handleReadyState
()
{
if
(
request
&&
(
request
.
readyState
===
4
||
xDomain
))
{
// Prepare the response
var
responseHeaders
=
xDomain
?
null
:
parseHeaders
(
request
.
getAllResponseHeaders
());
...
...
@@ -99,13 +99,12 @@ module.exports = function xhrAdapter(resolve, reject, config) {
// Add headers to the request
if
(
!
xDomain
)
{
utils
.
forEach
(
requestHeaders
,
function
(
val
,
key
)
{
// Remove Content-Type if data is undefined
utils
.
forEach
(
requestHeaders
,
function
setRequestHeader
(
val
,
key
)
{
if
(
!
data
&&
key
.
toLowerCase
()
===
'
content-type
'
)
{
// Remove Content-Type if data is undefined
delete
requestHeaders
[
key
];
}
// Otherwise add header to the request
else
{
}
else
{
// Otherwise add header to the request
request
.
setRequestHeader
(
key
,
val
);
}
});
...
...
lib/axios.js
浏览文件 @
f28a4a82
...
...
@@ -6,8 +6,9 @@ var dispatchRequest = require('./core/dispatchRequest');
var
InterceptorManager
=
require
(
'
./core/InterceptorManager
'
);
var
isAbsoluteURL
=
require
(
'
./helpers/isAbsoluteURL
'
);
var
combineURLs
=
require
(
'
./helpers/combineURLs
'
);
var
bind
=
require
(
'
./helpers/bind
'
);
function
Axios
(
defaultConfig
)
{
function
Axios
(
defaultConfig
)
{
this
.
defaultConfig
=
utils
.
merge
({
headers
:
{},
timeout
:
defaults
.
timeout
,
...
...
@@ -21,7 +22,8 @@ function Axios (defaultConfig) {
};
}
Axios
.
prototype
.
request
=
function
(
config
)
{
Axios
.
prototype
.
request
=
function
request
(
config
)
{
/*eslint no-param-reassign:0*/
// Allow for axios('example/url'[, config]) a la fetch API
if
(
typeof
config
===
'
string
'
)
{
config
=
utils
.
merge
({
...
...
@@ -42,11 +44,11 @@ Axios.prototype.request = function (config) {
var
chain
=
[
dispatchRequest
,
undefined
];
var
promise
=
Promise
.
resolve
(
config
);
this
.
interceptors
.
request
.
forEach
(
function
(
interceptor
)
{
this
.
interceptors
.
request
.
forEach
(
function
unshiftRequestInterceptors
(
interceptor
)
{
chain
.
unshift
(
interceptor
.
fulfilled
,
interceptor
.
rejected
);
});
this
.
interceptors
.
response
.
forEach
(
function
(
interceptor
)
{
this
.
interceptors
.
response
.
forEach
(
function
pushResponseInterceptors
(
interceptor
)
{
chain
.
push
(
interceptor
.
fulfilled
,
interceptor
.
rejected
);
});
...
...
@@ -61,7 +63,7 @@ var defaultInstance = new Axios();
var
axios
=
module
.
exports
=
bind
(
Axios
.
prototype
.
request
,
defaultInstance
);
axios
.
create
=
function
(
defaultConfig
)
{
axios
.
create
=
function
create
(
defaultConfig
)
{
return
new
Axios
(
defaultConfig
);
};
...
...
@@ -69,7 +71,7 @@ axios.create = function (defaultConfig) {
axios
.
defaults
=
defaults
;
// Expose all/spread
axios
.
all
=
function
(
promises
)
{
axios
.
all
=
function
all
(
promises
)
{
return
Promise
.
all
(
promises
);
};
axios
.
spread
=
require
(
'
./helpers/spread
'
);
...
...
@@ -77,20 +79,10 @@ axios.spread = require('./helpers/spread');
// Expose interceptors
axios
.
interceptors
=
defaultInstance
.
interceptors
;
// Helpers
function
bind
(
fn
,
thisArg
)
{
return
function
()
{
var
args
=
new
Array
(
arguments
.
length
);
for
(
var
i
=
0
;
i
<
args
.
length
;
i
++
)
{
args
[
i
]
=
arguments
[
i
];
}
return
fn
.
apply
(
thisArg
,
args
);
};
}
// Provide aliases for supported request methods
utils
.
forEach
([
'
delete
'
,
'
get
'
,
'
head
'
],
function
(
method
)
{
Axios
.
prototype
[
method
]
=
function
(
url
,
config
)
{
utils
.
forEach
([
'
delete
'
,
'
get
'
,
'
head
'
],
function
forEachMethodNoData
(
method
)
{
/*eslint func-names:0*/
Axios
.
prototype
[
method
]
=
function
(
url
,
config
)
{
return
this
.
request
(
utils
.
merge
(
config
||
{},
{
method
:
method
,
url
:
url
...
...
@@ -99,8 +91,9 @@ utils.forEach(['delete', 'get', 'head'], function (method) {
axios
[
method
]
=
bind
(
Axios
.
prototype
[
method
],
defaultInstance
);
});
utils
.
forEach
([
'
post
'
,
'
put
'
,
'
patch
'
],
function
(
method
)
{
Axios
.
prototype
[
method
]
=
function
(
url
,
data
,
config
)
{
utils
.
forEach
([
'
post
'
,
'
put
'
,
'
patch
'
],
function
forEachMethodWithData
(
method
)
{
/*eslint func-names:0*/
Axios
.
prototype
[
method
]
=
function
(
url
,
data
,
config
)
{
return
this
.
request
(
utils
.
merge
(
config
||
{},
{
method
:
method
,
url
:
url
,
...
...
lib/core/InterceptorManager.js
浏览文件 @
f28a4a82
...
...
@@ -14,7 +14,7 @@ function InterceptorManager() {
*
* @return {Number} An ID used to remove interceptor later
*/
InterceptorManager
.
prototype
.
use
=
function
(
fulfilled
,
rejected
)
{
InterceptorManager
.
prototype
.
use
=
function
use
(
fulfilled
,
rejected
)
{
this
.
handlers
.
push
({
fulfilled
:
fulfilled
,
rejected
:
rejected
...
...
@@ -27,7 +27,7 @@ InterceptorManager.prototype.use = function (fulfilled, rejected) {
*
* @param {Number} id The ID that was returned by `use`
*/
InterceptorManager
.
prototype
.
eject
=
function
(
id
)
{
InterceptorManager
.
prototype
.
eject
=
function
eject
(
id
)
{
if
(
this
.
handlers
[
id
])
{
this
.
handlers
[
id
]
=
null
;
}
...
...
@@ -37,12 +37,12 @@ InterceptorManager.prototype.eject = function (id) {
* Iterate over all the registered interceptors
*
* This method is particularly useful for skipping over any
* interceptors that may have become `null` calling `
remove
`.
* interceptors that may have become `null` calling `
eject
`.
*
* @param {Function} fn The function to call for each interceptor
*/
InterceptorManager
.
prototype
.
forEach
=
function
(
fn
)
{
utils
.
forEach
(
this
.
handlers
,
function
(
h
)
{
InterceptorManager
.
prototype
.
forEach
=
function
forEach
(
fn
)
{
utils
.
forEach
(
this
.
handlers
,
function
forEachHandler
(
h
)
{
if
(
h
!==
null
)
{
fn
(
h
);
}
...
...
lib/core/dispatchRequest.js
浏览文件 @
f28a4a82
...
...
@@ -8,14 +8,13 @@
* @returns {Promise} The Promise to be fulfilled
*/
module
.
exports
=
function
dispatchRequest
(
config
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
executor
(
resolve
,
reject
)
{
try
{
// For browsers use XHR adapter
if
((
typeof
XMLHttpRequest
!==
'
undefined
'
)
||
(
typeof
ActiveXObject
!==
'
undefined
'
))
{
// For browsers use XHR adapter
require
(
'
../adapters/xhr
'
)(
resolve
,
reject
,
config
);
}
// For node use HTTP adapter
else
if
(
typeof
process
!==
'
undefined
'
)
{
}
else
if
(
typeof
process
!==
'
undefined
'
)
{
// For node use HTTP adapter
require
(
'
../adapters/http
'
)(
resolve
,
reject
,
config
);
}
}
catch
(
e
)
{
...
...
lib/defaults.js
浏览文件 @
f28a4a82
...
...
@@ -8,8 +8,8 @@ var DEFAULT_CONTENT_TYPE = {
};
module
.
exports
=
{
transformRequest
:
[
function
(
data
,
headers
)
{
if
(
utils
.
isFormData
(
data
))
{
transformRequest
:
[
function
transformResponseJSON
(
data
,
headers
)
{
if
(
utils
.
isFormData
(
data
))
{
return
data
;
}
if
(
utils
.
isArrayBuffer
(
data
))
{
...
...
@@ -21,7 +21,7 @@ module.exports = {
if
(
utils
.
isObject
(
data
)
&&
!
utils
.
isFile
(
data
)
&&
!
utils
.
isBlob
(
data
))
{
// Set application/json if no Content-Type has been specified
if
(
!
utils
.
isUndefined
(
headers
))
{
utils
.
forEach
(
headers
,
function
(
val
,
key
)
{
utils
.
forEach
(
headers
,
function
processContentTypeHeader
(
val
,
key
)
{
if
(
key
.
toLowerCase
()
===
'
content-type
'
)
{
headers
[
'
Content-Type
'
]
=
val
;
}
...
...
@@ -36,7 +36,8 @@ module.exports = {
return
data
;
}],
transformResponse
:
[
function
(
data
)
{
transformResponse
:
[
function
transformResponseJSON
(
data
)
{
/*eslint no-param-reassign:0*/
if
(
typeof
data
===
'
string
'
)
{
data
=
data
.
replace
(
PROTECTION_PREFIX
,
''
);
try
{
...
...
lib/helpers/btoa.js
浏览文件 @
f28a4a82
...
...
@@ -11,11 +11,12 @@ InvalidCharacterError.prototype = new Error;
InvalidCharacterError
.
prototype
.
code
=
5
;
InvalidCharacterError
.
prototype
.
name
=
'
InvalidCharacterError
'
;
function
btoa
(
input
)
{
function
btoa
(
input
)
{
var
str
=
String
(
input
);
var
output
=
''
;
for
(
// initialize result and counter
var
block
,
charCode
,
idx
=
0
,
map
=
chars
,
output
=
''
;
var
block
,
charCode
,
idx
=
0
,
map
=
chars
;
// if the next str index does not exist:
// change the mapping table to "="
// check if d has no fractional digits
...
...
@@ -23,13 +24,13 @@ function btoa (input) {
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
output
+=
map
.
charAt
(
63
&
block
>>
8
-
idx
%
1
*
8
)
)
{
charCode
=
str
.
charCodeAt
(
idx
+=
3
/
4
);
charCode
=
str
.
charCodeAt
(
idx
+=
3
/
4
);
if
(
charCode
>
0xFF
)
{
throw
new
InvalidCharacterError
(
'
INVALID_CHARACTER_ERR: DOM Exception 5
'
);
}
block
=
block
<<
8
|
charCode
;
}
return
output
;
}
;
}
module
.
exports
=
btoa
;
lib/helpers/buildURL.js
浏览文件 @
f28a4a82
...
...
@@ -21,6 +21,7 @@ function encode(val) {
* @returns {string} The formatted url
*/
module
.
exports
=
function
buildURL
(
url
,
params
,
paramsSerializer
)
{
/*eslint no-param-reassign:0*/
if
(
!
params
)
{
return
url
;
}
...
...
@@ -28,11 +29,10 @@ module.exports = function buildURL(url, params, paramsSerializer) {
var
serializedParams
;
if
(
paramsSerializer
)
{
serializedParams
=
paramsSerializer
(
params
);
}
else
{
}
else
{
var
parts
=
[];
utils
.
forEach
(
params
,
function
(
val
,
key
)
{
utils
.
forEach
(
params
,
function
serialize
(
val
,
key
)
{
if
(
val
===
null
||
typeof
val
===
'
undefined
'
)
{
return
;
}
...
...
@@ -45,11 +45,10 @@ module.exports = function buildURL(url, params, paramsSerializer) {
val
=
[
val
];
}
utils
.
forEach
(
val
,
function
(
v
)
{
utils
.
forEach
(
val
,
function
parseValue
(
v
)
{
if
(
utils
.
isDate
(
v
))
{
v
=
v
.
toISOString
();
}
else
if
(
utils
.
isObject
(
v
))
{
}
else
if
(
utils
.
isObject
(
v
))
{
v
=
JSON
.
stringify
(
v
);
}
parts
.
push
(
encode
(
key
)
+
'
=
'
+
encode
(
v
));
...
...
lib/helpers/cookies.js
浏览文件 @
f28a4a82
...
...
@@ -6,7 +6,7 @@ module.exports = (
utils
.
isStandardBrowserEnv
()
?
// Standard browser envs support document.cookie
(
function
()
{
(
function
standardBrowserEnv
()
{
return
{
write
:
function
write
(
name
,
value
,
expires
,
path
,
domain
,
secure
)
{
var
cookie
=
[];
...
...
@@ -43,7 +43,7 @@ module.exports = (
})()
:
// Non standard browser env (web workers, react-native) lack needed support.
(
function
()
{
(
function
nonStandardBrowserEnv
()
{
return
{
write
:
function
write
()
{},
read
:
function
read
()
{
return
null
;
},
...
...
lib/helpers/deprecatedMethod.js
浏览文件 @
f28a4a82
'
use strict
'
;
/*eslint no-console:0*/
/**
* Supply a warning to the developer that a method they are using
* has been deprecated.
...
...
lib/helpers/isURLSameOrigin.js
浏览文件 @
f28a4a82
...
...
@@ -7,7 +7,7 @@ module.exports = (
// Standard browser envs have full support of the APIs needed to test
// whether the request URL is of the same origin as current location.
(
function
()
{
(
function
standardBrowserEnv
()
{
var
msie
=
/
(
msie|trident
)
/i
.
test
(
navigator
.
userAgent
);
var
urlParsingNode
=
document
.
createElement
(
'
a
'
);
var
originURL
;
...
...
@@ -60,7 +60,7 @@ module.exports = (
})()
:
// Non standard browser envs (web workers, react-native) lack needed support.
(
function
()
{
(
function
nonStandardBrowserEnv
()
{
return
function
isURLSameOrigin
()
{
return
true
;
};
...
...
lib/helpers/parseHeaders.js
浏览文件 @
f28a4a82
...
...
@@ -16,11 +16,14 @@ var utils = require('./../utils');
* @returns {Object} Headers parsed into an object
*/
module
.
exports
=
function
parseHeaders
(
headers
)
{
var
parsed
=
{},
key
,
val
,
i
;
var
parsed
=
{};
var
key
;
var
val
;
var
i
;
if
(
!
headers
)
{
return
parsed
;
}
utils
.
forEach
(
headers
.
split
(
'
\n
'
),
function
(
line
)
{
utils
.
forEach
(
headers
.
split
(
'
\n
'
),
function
parser
(
line
)
{
i
=
line
.
indexOf
(
'
:
'
);
key
=
utils
.
trim
(
line
.
substr
(
0
,
i
)).
toLowerCase
();
val
=
utils
.
trim
(
line
.
substr
(
i
+
1
));
...
...
lib/helpers/spread.js
浏览文件 @
f28a4a82
...
...
@@ -21,7 +21,7 @@
* @returns {Function}
*/
module
.
exports
=
function
spread
(
callback
)
{
return
function
(
arr
)
{
return
function
wrap
(
arr
)
{
return
callback
.
apply
(
null
,
arr
);
};
};
lib/helpers/transformData.js
浏览文件 @
f28a4a82
...
...
@@ -11,7 +11,8 @@ var utils = require('./../utils');
* @returns {*} The resulting transformed data
*/
module
.
exports
=
function
transformData
(
data
,
headers
,
fns
)
{
utils
.
forEach
(
fns
,
function
(
fn
)
{
/*eslint no-param-reassign:0*/
utils
.
forEach
(
fns
,
function
transform
(
fn
)
{
data
=
fn
(
data
,
headers
);
});
...
...
lib/utils.js
浏览文件 @
f28a4a82
...
...
@@ -43,11 +43,13 @@ function isFormData(val) {
* @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
*/
function
isArrayBufferView
(
val
)
{
var
result
;
if
((
typeof
ArrayBuffer
!==
'
undefined
'
)
&&
(
ArrayBuffer
.
isView
))
{
re
turn
ArrayBuffer
.
isView
(
val
);
re
sult
=
ArrayBuffer
.
isView
(
val
);
}
else
{
re
turn
(
val
)
&&
(
val
.
buffer
)
&&
(
val
.
buffer
instanceof
ArrayBuffer
);
re
sult
=
(
val
)
&&
(
val
.
buffer
)
&&
(
val
.
buffer
instanceof
ArrayBuffer
);
}
return
result
;
}
/**
...
...
@@ -171,17 +173,17 @@ function forEach(obj, fn) {
// Force an array if not already something iterable
if
(
typeof
obj
!==
'
object
'
&&
!
isArray
(
obj
))
{
/*eslint no-param-reassign:0*/
obj
=
[
obj
];
}
// Iterate over array values
if
(
isArray
(
obj
))
{
// Iterate over array values
for
(
var
i
=
0
,
l
=
obj
.
length
;
i
<
l
;
i
++
)
{
fn
.
call
(
null
,
obj
[
i
],
i
,
obj
);
}
}
// Iterate over object keys
else
{
}
else
{
// Iterate over object keys
for
(
var
key
in
obj
)
{
if
(
obj
.
hasOwnProperty
(
key
))
{
fn
.
call
(
null
,
obj
[
key
],
key
,
obj
);
...
...
@@ -207,11 +209,13 @@ function forEach(obj, fn) {
* @param {Object} obj1 Object to merge
* @returns {Object} Result of all merge properties
*/
function
merge
(
/*
obj1, obj2, obj3, ...
*/
)
{
function
merge
(
/*
obj1, obj2, obj3, ...
*/
)
{
var
result
=
{};
var
assignValue
=
function
(
val
,
key
)
{
result
[
key
]
=
val
;
};
var
length
=
arguments
.
length
;
for
(
var
i
=
0
;
i
<
length
;
i
++
)
{
function
assignValue
(
val
,
key
)
{
result
[
key
]
=
val
;
}
for
(
var
i
=
0
,
l
=
arguments
.
length
;
i
<
l
;
i
++
)
{
forEach
(
arguments
[
i
],
assignValue
);
}
return
result
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录