diff --git a/index.js b/index.js index db5f48e..c2aa9f0 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,16 @@ const DEFAULT_FORM_TYPE = 'application/x-www-form-urlencoded' var __dirname = PATH.dirname(URL.fileURLToPath(import.meta.url)) -var tmpdir = PATH.resolve(__dirname, './.tmp/') +var tmpdir = PATH.resolve(__dirname, '.tmp/') var encode = encodeURIComponent var decode = decodeURIComponent +if (fs.isdir(tmpdir)) { + fs.rm(tmpdir, true) +} + +fs.mkdir(tmpdir) + function hideProperty(host, name, value) { Object.defineProperty(host, name, { value: value, @@ -40,12 +46,6 @@ export default class Request { hideProperty(this, '__COOKIE__', parseCookie(this.header('cookie') || '')) this.__fixUrl() - - if (fs.isdir(tmpdir)) { - fs.rm(tmpdir) - } else { - fs.mkdir(tmpdir) - } } // 修正请求的url @@ -135,11 +135,7 @@ export default class Request { this.__GET__ = para } - return key - ? this.__GET__.hasOwnProperty(key) - ? this.__GET__[key] - : null - : this.__GET__ + return key ? (this.__GET__.hasOwnProperty(key) ? this.__GET__[key] : null) : this.__GET__ } /** @@ -173,10 +169,7 @@ export default class Request { return } if (~contentType.indexOf('urlencoded')) { - if ( - name.slice(0, 2) === '{"' && - (name.slice(-2) === '"}' || value.slice(-2) === '"}') - ) { + if (name.slice(0, 2) === '{"' && (name.slice(-2) === '"}' || value.slice(-2) === '"}')) { name = name.replace(/\s/g, '+') if (value.slice(0, 1) === '=') value = '=' + value diff --git a/package.json b/package.json index a216da9..2f2b6ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/request", - "version": "1.2.5", + "version": "1.2.6", "description": "对Http的request进一步封装, 提供常用的API", "main": "index.js", "author": "yutent",