@ritttzy/core
Version:
## Project setup ``` npm install ```
157 lines (137 loc) • 4.85 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["ritttzy-core"] = factory();
else
root["ritttzy-core"] = factory();
})((typeof self !== 'undefined' ? self : this), function() {
return /******/ (function() { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ !function() {
/******/ __webpack_require__.p = "";
/******/ }();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"doFetch": function() { return /* reexport */ doFetch; }
});
;// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/setPublicPath.js
/* eslint-disable no-var */
// This file is imported into lib/wc client bundles.
if (typeof window !== 'undefined') {
var currentScript = window.document.currentScript
if (false) { var getCurrentScript; }
var src = currentScript && currentScript.src.match(/(.+\/)[^/]+\.js(\?.*)?$/)
if (src) {
__webpack_require__.p = src[1] // eslint-disable-line
}
}
// Indicate to webpack that this file can be concatenated
/* harmony default export */ var setPublicPath = (null);
;// CONCATENATED MODULE: ./src/functions/doFetch.ts
async function doFetch(url, method = "GET", // eslint-disable-next-line @typescript-eslint/no-explicit-any
body = null, opts = {}) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const headers = {};
/*
if (!opts.noAuth) {
const user = getUser();
if (user != null) {
const token = await getSession(user, "id");
headers.Authorization = token;
}
}
*/
//stringify body
//default option is application/json
opts.contentType ??= "application/json"; //if theres a body recieved
if (body) {
//if the body is an object, stringify it and add the header
if (opts.contentType == "application/json") {
body = JSON.stringify(body);
}
}
opts.return ??= "json"; //try to fetch
try {
//fetch the source using the obtained properties
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let content = await fetch(url, {
headers: headers,
method: method,
body: body
}); //if the content is wrong throw the error with the message
if (!content.ok) {
return {
ok: false,
completed: true,
body: {
message: content.message
}
};
} //if the content obtained is ok and the possible answer is a json convert it to json
if (opts.return == "json") {
content = await content.json();
}
return {
ok: true,
completed: true,
body: content
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error) {
//if the fetch was unsuccesful throw the corresponding error
return {
ok: false,
completed: false,
body: {
message: error.message
}
};
}
}
;// CONCATENATED MODULE: ./src/index.ts
;// CONCATENATED MODULE: ./node_modules/@vue/cli-service/lib/commands/build/entry-lib-no-default.js
/******/ return __webpack_exports__;
/******/ })()
;
});
//# sourceMappingURL=ritttzy-core.umd.js.map