Comparing version 2.0.0 to 2.1.0
366
dist/ajax.js
@@ -1,254 +0,200 @@ | ||
var app = (function () { | ||
'use strict'; | ||
/* eslint-env browser */ | ||
var Ajax = | ||
/*#__PURE__*/ | ||
function () { | ||
function Ajax() {} | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
Ajax.serialize = function serialize(data) { | ||
var queryString = ''; | ||
return _typeof(obj); | ||
} | ||
var formatValue = function formatValue(k, v) { | ||
return "&" + encodeURIComponent(k) + "=" + encodeURIComponent(v); | ||
}; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
} | ||
Object.keys(data).forEach(function (key) { | ||
var value = data[key]; | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
if (Array.isArray(value)) { | ||
value.forEach(function (k) { | ||
queryString += formatValue(key, k); | ||
}); | ||
} else { | ||
queryString += formatValue(key, value); | ||
} | ||
}); | ||
return queryString.substring(1); | ||
}; | ||
Ajax.get = function get(url) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'GET'].concat(args)); | ||
}; | ||
/* eslint-env browser */ | ||
var Ajax = | ||
/*#__PURE__*/ | ||
function () { | ||
function Ajax() { | ||
_classCallCheck(this, Ajax); | ||
Ajax.post = function post(url) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
_createClass(Ajax, null, [{ | ||
key: "serialize", | ||
value: function serialize(data) { | ||
var queryString = ''; | ||
return Ajax.request.apply(Ajax, [url, 'POST'].concat(args)); | ||
}; | ||
var formatValue = function formatValue(k, v) { | ||
return "&".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(v)); | ||
}; | ||
Ajax.patch = function patch(url) { | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
Object.keys(data).forEach(function (key) { | ||
var value = data[key]; | ||
return Ajax.request.apply(Ajax, [url, 'PATCH'].concat(args)); | ||
}; | ||
if (Array.isArray(value)) { | ||
value.forEach(function (k) { | ||
queryString += formatValue(key, k); | ||
}); | ||
} else { | ||
queryString += formatValue(key, value); | ||
} | ||
}); | ||
return queryString.substring(1); | ||
} | ||
}, { | ||
key: "get", | ||
value: function get(url) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
Ajax.put = function put(url) { | ||
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'GET'].concat(args)); | ||
} | ||
}, { | ||
key: "post", | ||
value: function post(url) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'PUT'].concat(args)); | ||
}; | ||
return Ajax.request.apply(Ajax, [url, 'POST'].concat(args)); | ||
} | ||
}, { | ||
key: "patch", | ||
value: function patch(url) { | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
} | ||
Ajax.head = function head(url) { | ||
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { | ||
args[_key5 - 1] = arguments[_key5]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'PATCH'].concat(args)); | ||
} | ||
}, { | ||
key: "put", | ||
value: function put(url) { | ||
for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { | ||
args[_key4 - 1] = arguments[_key4]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'HEAD'].concat(args)); | ||
}; | ||
return Ajax.request.apply(Ajax, [url, 'PUT'].concat(args)); | ||
} | ||
}, { | ||
key: "head", | ||
value: function head(url) { | ||
for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { | ||
args[_key5 - 1] = arguments[_key5]; | ||
} | ||
Ajax.del = function del(url) { | ||
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { | ||
args[_key6 - 1] = arguments[_key6]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'HEAD'].concat(args)); | ||
} | ||
}, { | ||
key: "del", | ||
value: function del(url) { | ||
for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) { | ||
args[_key6 - 1] = arguments[_key6]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'DELETE'].concat(args)); | ||
}; | ||
return Ajax.request.apply(Ajax, [url, 'DELETE'].concat(args)); | ||
} | ||
}, { | ||
key: "options", | ||
value: function options(url) { | ||
for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) { | ||
args[_key7 - 1] = arguments[_key7]; | ||
} | ||
Ajax.options = function options(url) { | ||
for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) { | ||
args[_key7 - 1] = arguments[_key7]; | ||
} | ||
return Ajax.request.apply(Ajax, [url, 'OPTIONS'].concat(args)); | ||
} | ||
/** | ||
* request - Makes a request to a remote server | ||
* | ||
* @param {String} url Url for the request | ||
* @param {String} method Request method: GET, POST, etc (default: GET) | ||
* @param {Object} data Data payload. Set to null to not send | ||
* anything. Data is sent as raw json (default: null) | ||
* @param {Function} callback Called con completion with an object containing | ||
* the status code and the data. If the response | ||
* has a content-type containing json data will | ||
* be parsed, otherwise it will be the raw data. | ||
* @return XMLHttpRequest Original XMLHttpRequest object to allow further | ||
* event binding. | ||
*/ | ||
return Ajax.request.apply(Ajax, [url, 'OPTIONS'].concat(args)); | ||
} | ||
/** | ||
* request - Makes a request to a remote server | ||
* | ||
* @param {String} url Url for the request | ||
* @param {String} method Request method: GET, POST, etc (default: GET) | ||
* @param {Object} data Data payload. Set to null to not send | ||
* anything. Data is sent as raw json (default: null) | ||
* @param {Function} callback Called con completion with an object containing | ||
* the status code and the data. If the response | ||
* has a content-type containing json data will | ||
* be parsed, otherwise it will be the raw data. | ||
* @return XMLHttpRequest Original XMLHttpRequest object to allow further | ||
* event binding. | ||
*/ | ||
; | ||
}, { | ||
key: "request", | ||
value: function request(url) { | ||
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) { | ||
args[_key8 - 1] = arguments[_key8]; | ||
} | ||
Ajax.request = function request(url) { | ||
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) { | ||
args[_key8 - 1] = arguments[_key8]; | ||
} | ||
var method = args[0], | ||
data = args[1], | ||
headers = args[2], | ||
callback = args[3]; | ||
var method = args[0], | ||
data = args[1], | ||
headers = args[2], | ||
callback = args[3]; | ||
if (typeof method === 'function') { | ||
method = 'GET'; | ||
callback = method; | ||
data = null; | ||
headers = {}; | ||
} | ||
if (typeof method === 'function') { | ||
method = 'GET'; | ||
callback = method; | ||
data = null; | ||
headers = {}; | ||
} | ||
if (typeof data === 'function') { | ||
callback = data; | ||
data = null; | ||
headers = {}; | ||
} | ||
if (typeof data === 'function') { | ||
callback = data; | ||
data = null; | ||
headers = {}; | ||
} | ||
if (typeof headers === 'function') { | ||
callback = headers; | ||
headers = {}; | ||
} | ||
if (typeof headers === 'function') { | ||
callback = headers; | ||
headers = {}; | ||
} | ||
if (headers === null || typeof headers === 'undefined') { | ||
headers = {}; | ||
} | ||
if (headers === null || typeof headers === 'undefined') { | ||
headers = {}; | ||
} | ||
var useMethod = method.toUpperCase(); | ||
var validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS']; | ||
var useMethod = method.toUpperCase(); | ||
var validMethods = ['GET', 'POST', 'PUT', 'PATCH', 'HEAD', 'DELETE', 'OPTIONS']; | ||
if (validMethods.indexOf(useMethod) === -1) { | ||
var err = new TypeError("Method must be one of the following: ".concat(validMethods.join(', '))); | ||
return callback(err); | ||
} | ||
if (validMethods.indexOf(useMethod) === -1) { | ||
var err = new TypeError("Method must be one of the following: " + validMethods.join(', ')); | ||
return callback(err); | ||
} | ||
if (_typeof(data) === 'object' && data !== null && method === 'GET') { | ||
var serializedData = data; | ||
if (typeof data === 'object' && data !== null && method === 'GET') { | ||
var serializedData = data; | ||
if (_typeof(data) === 'object' && data !== null) { | ||
serializedData = Ajax.serialize(data); | ||
var join = url.indexOf('?') > -1 ? '&' : '?'; | ||
url = url + join + serializedData; | ||
data = null; | ||
} | ||
} | ||
if (typeof data === 'object' && data !== null) { | ||
serializedData = Ajax.serialize(data); | ||
var join = url.indexOf('?') > -1 ? '&' : '?'; | ||
url = url + join + serializedData; | ||
data = null; | ||
} | ||
} | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open(useMethod, url); | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open(useMethod, url); | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState > 3 && xhr.status > 0) { | ||
var contentType = xhr.getResponseHeader('content-type'); | ||
var parsedResponse = xhr.responseText; | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState > 3 && xhr.status > 0) { | ||
var contentType = xhr.getResponseHeader('content-type'); | ||
var parsedResponse = xhr.responseText; | ||
if (contentType && contentType.toLowerCase().indexOf('json') > -1) { | ||
parsedResponse = JSON.parse(parsedResponse); | ||
} | ||
if (contentType && contentType.toLowerCase().indexOf('json') > -1) { | ||
parsedResponse = JSON.parse(parsedResponse); | ||
} | ||
return callback(null, { | ||
headers: xhr.getAllResponseHeaders(), | ||
statusCode: xhr.status, | ||
data: parsedResponse | ||
}); | ||
} | ||
}; | ||
xhr.onerror = function (e) { | ||
return callback(e, null); | ||
}; | ||
Object.keys(headers).forEach(function (header) { | ||
xhr.setRequestHeader(header, headers[header]); | ||
return callback(null, { | ||
headers: xhr.getAllResponseHeaders(), | ||
statusCode: xhr.status, | ||
data: parsedResponse | ||
}); | ||
} | ||
}; | ||
if (data !== null) { | ||
var dataString = data; | ||
var contentHeader = 'application/x-www-form-urlencoded'; | ||
xhr.onerror = function (e) { | ||
return callback(e, null); | ||
}; | ||
if (_typeof(data) === 'object') { | ||
dataString = JSON.stringify(data); | ||
contentHeader = 'application/json'; | ||
} | ||
Object.keys(headers).forEach(function (header) { | ||
xhr.setRequestHeader(header, headers[header]); | ||
}); | ||
xhr.setRequestHeader('Content-Type', contentHeader); | ||
xhr.send(dataString); | ||
} else { | ||
xhr.send(); | ||
} | ||
if (data !== null) { | ||
var dataString = data; | ||
var contentHeader = 'application/x-www-form-urlencoded'; | ||
return xhr; | ||
if (typeof data === 'object') { | ||
dataString = JSON.stringify(data); | ||
contentHeader = 'application/json'; | ||
} | ||
}]); | ||
return Ajax; | ||
}(); | ||
xhr.setRequestHeader('Content-Type', contentHeader); | ||
xhr.send(dataString); | ||
} else { | ||
xhr.send(); | ||
} | ||
return xhr; | ||
}; | ||
return Ajax; | ||
}(); | ||
}()); | ||
export default Ajax; | ||
//# sourceMappingURL=ajax.js.map |
{ | ||
"name": "bequest", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "An ajax class", | ||
"main": "index.js", | ||
"module": "dist/ajax.esm.js", | ||
"module": "dist/ajax.js", | ||
"scripts": { | ||
@@ -11,3 +11,4 @@ "start": "scriptkit", | ||
"dev": "scriptkit dev", | ||
"test": "cat test/bequest.test.dist.js | tape-run --static . --browser phantomjs --render tap-spec", | ||
"test": "cat test/bequest.test.dist.bundle.js | tape-run --static . --browser phantomjs --render tap-spec", | ||
"pretest": "scriptkit build", | ||
"prepublishOnly": "scriptkit" | ||
@@ -35,9 +36,9 @@ }, | ||
"devDependencies": { | ||
"eslint-config-firstandthird": "^4.3.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-config-firstandthird": "^4.4.0", | ||
"eslint-plugin-import": "^2.18.0", | ||
"phantomjs-prebuilt": "^2.1.16", | ||
"scriptkit": "^2.0.1", | ||
"scriptkit": "^3.0.0", | ||
"tap-spec": "^5.0.0", | ||
"tape-rollup": "^4.6.4", | ||
"tape-run": "^5.0.0" | ||
"tape-run": "^6.0.0" | ||
}, | ||
@@ -44,0 +45,0 @@ "scriptkit": { |
# bequest | ||
Makes a request to a remote server | ||
@@ -3,0 +4,0 @@ |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
43
0
18787
446