espn-fantasy-football-api
Version:
A Javascript API to connect to ESPN's fantasy football API
1,122 lines (992 loc) • 841 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["espn-fantasy-football-api"] = factory();
else
root["espn-fantasy-football-api"] = factory();
})(global, () => {
return /******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ "./node_modules/asynckit/index.js":
/*!****************************************!*\
!*** ./node_modules/asynckit/index.js ***!
\****************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
module.exports =
{
parallel : __webpack_require__(/*! ./parallel.js */ "./node_modules/asynckit/parallel.js"),
serial : __webpack_require__(/*! ./serial.js */ "./node_modules/asynckit/serial.js"),
serialOrdered : __webpack_require__(/*! ./serialOrdered.js */ "./node_modules/asynckit/serialOrdered.js")
};
/***/ }),
/***/ "./node_modules/asynckit/lib/abort.js":
/*!********************************************!*\
!*** ./node_modules/asynckit/lib/abort.js ***!
\********************************************/
/***/ ((module) => {
// API
module.exports = abort;
/**
* Aborts leftover active jobs
*
* @param {object} state - current state object
*/
function abort(state)
{
Object.keys(state.jobs).forEach(clean.bind(state));
// reset leftover jobs
state.jobs = {};
}
/**
* Cleans up leftover job by invoking abort function for the provided job id
*
* @this state
* @param {string|number} key - job id to abort
*/
function clean(key)
{
if (typeof this.jobs[key] == 'function')
{
this.jobs[key]();
}
}
/***/ }),
/***/ "./node_modules/asynckit/lib/async.js":
/*!********************************************!*\
!*** ./node_modules/asynckit/lib/async.js ***!
\********************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var defer = __webpack_require__(/*! ./defer.js */ "./node_modules/asynckit/lib/defer.js");
// API
module.exports = async;
/**
* Runs provided callback asynchronously
* even if callback itself is not
*
* @param {function} callback - callback to invoke
* @returns {function} - augmented callback
*/
function async(callback)
{
var isAsync = false;
// check if async happened
defer(function() { isAsync = true; });
return function async_callback(err, result)
{
if (isAsync)
{
callback(err, result);
}
else
{
defer(function nextTick_callback()
{
callback(err, result);
});
}
};
}
/***/ }),
/***/ "./node_modules/asynckit/lib/defer.js":
/*!********************************************!*\
!*** ./node_modules/asynckit/lib/defer.js ***!
\********************************************/
/***/ ((module) => {
module.exports = defer;
/**
* Runs provided function on next iteration of the event loop
*
* @param {function} fn - function to run
*/
function defer(fn)
{
var nextTick = typeof setImmediate == 'function'
? setImmediate
: (
typeof process == 'object' && typeof process.nextTick == 'function'
? process.nextTick
: null
);
if (nextTick)
{
nextTick(fn);
}
else
{
setTimeout(fn, 0);
}
}
/***/ }),
/***/ "./node_modules/asynckit/lib/iterate.js":
/*!**********************************************!*\
!*** ./node_modules/asynckit/lib/iterate.js ***!
\**********************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var async = __webpack_require__(/*! ./async.js */ "./node_modules/asynckit/lib/async.js")
, abort = __webpack_require__(/*! ./abort.js */ "./node_modules/asynckit/lib/abort.js")
;
// API
module.exports = iterate;
/**
* Iterates over each job object
*
* @param {array|object} list - array or object (named list) to iterate over
* @param {function} iterator - iterator to run
* @param {object} state - current job status
* @param {function} callback - invoked when all elements processed
*/
function iterate(list, iterator, state, callback)
{
// store current index
var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
state.jobs[key] = runJob(iterator, key, list[key], function(error, output)
{
// don't repeat yourself
// skip secondary callbacks
if (!(key in state.jobs))
{
return;
}
// clean up jobs
delete state.jobs[key];
if (error)
{
// don't process rest of the results
// stop still active jobs
// and reset the list
abort(state);
}
else
{
state.results[key] = output;
}
// return salvaged results
callback(error, state.results);
});
}
/**
* Runs iterator over provided job element
*
* @param {function} iterator - iterator to invoke
* @param {string|number} key - key/index of the element in the list of jobs
* @param {mixed} item - job description
* @param {function} callback - invoked after iterator is done with the job
* @returns {function|mixed} - job abort function or something else
*/
function runJob(iterator, key, item, callback)
{
var aborter;
// allow shortcut if iterator expects only two arguments
if (iterator.length == 2)
{
aborter = iterator(item, async(callback));
}
// otherwise go with full three arguments
else
{
aborter = iterator(item, key, async(callback));
}
return aborter;
}
/***/ }),
/***/ "./node_modules/asynckit/lib/state.js":
/*!********************************************!*\
!*** ./node_modules/asynckit/lib/state.js ***!
\********************************************/
/***/ ((module) => {
// API
module.exports = state;
/**
* Creates initial state object
* for iteration over list
*
* @param {array|object} list - list to iterate over
* @param {function|null} sortMethod - function to use for keys sort,
* or `null` to keep them as is
* @returns {object} - initial state object
*/
function state(list, sortMethod)
{
var isNamedList = !Array.isArray(list)
, initState =
{
index : 0,
keyedList: isNamedList || sortMethod ? Object.keys(list) : null,
jobs : {},
results : isNamedList ? {} : [],
size : isNamedList ? Object.keys(list).length : list.length
}
;
if (sortMethod)
{
// sort array keys based on it's values
// sort object's keys just on own merit
initState.keyedList.sort(isNamedList ? sortMethod : function(a, b)
{
return sortMethod(list[a], list[b]);
});
}
return initState;
}
/***/ }),
/***/ "./node_modules/asynckit/lib/terminator.js":
/*!*************************************************!*\
!*** ./node_modules/asynckit/lib/terminator.js ***!
\*************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var abort = __webpack_require__(/*! ./abort.js */ "./node_modules/asynckit/lib/abort.js")
, async = __webpack_require__(/*! ./async.js */ "./node_modules/asynckit/lib/async.js")
;
// API
module.exports = terminator;
/**
* Terminates jobs in the attached state context
*
* @this AsyncKitState#
* @param {function} callback - final callback to invoke after termination
*/
function terminator(callback)
{
if (!Object.keys(this.jobs).length)
{
return;
}
// fast forward iteration index
this.index = this.size;
// abort jobs
abort(this);
// send back results we have so far
async(callback)(null, this.results);
}
/***/ }),
/***/ "./node_modules/asynckit/parallel.js":
/*!*******************************************!*\
!*** ./node_modules/asynckit/parallel.js ***!
\*******************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var iterate = __webpack_require__(/*! ./lib/iterate.js */ "./node_modules/asynckit/lib/iterate.js")
, initState = __webpack_require__(/*! ./lib/state.js */ "./node_modules/asynckit/lib/state.js")
, terminator = __webpack_require__(/*! ./lib/terminator.js */ "./node_modules/asynckit/lib/terminator.js")
;
// Public API
module.exports = parallel;
/**
* Runs iterator over provided array elements in parallel
*
* @param {array|object} list - array or object (named list) to iterate over
* @param {function} iterator - iterator to run
* @param {function} callback - invoked when all elements processed
* @returns {function} - jobs terminator
*/
function parallel(list, iterator, callback)
{
var state = initState(list);
while (state.index < (state['keyedList'] || list).length)
{
iterate(list, iterator, state, function(error, result)
{
if (error)
{
callback(error, result);
return;
}
// looks like it's the last one
if (Object.keys(state.jobs).length === 0)
{
callback(null, state.results);
return;
}
});
state.index++;
}
return terminator.bind(state, callback);
}
/***/ }),
/***/ "./node_modules/asynckit/serial.js":
/*!*****************************************!*\
!*** ./node_modules/asynckit/serial.js ***!
\*****************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var serialOrdered = __webpack_require__(/*! ./serialOrdered.js */ "./node_modules/asynckit/serialOrdered.js");
// Public API
module.exports = serial;
/**
* Runs iterator over provided array elements in series
*
* @param {array|object} list - array or object (named list) to iterate over
* @param {function} iterator - iterator to run
* @param {function} callback - invoked when all elements processed
* @returns {function} - jobs terminator
*/
function serial(list, iterator, callback)
{
return serialOrdered(list, iterator, null, callback);
}
/***/ }),
/***/ "./node_modules/asynckit/serialOrdered.js":
/*!************************************************!*\
!*** ./node_modules/asynckit/serialOrdered.js ***!
\************************************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
var iterate = __webpack_require__(/*! ./lib/iterate.js */ "./node_modules/asynckit/lib/iterate.js")
, initState = __webpack_require__(/*! ./lib/state.js */ "./node_modules/asynckit/lib/state.js")
, terminator = __webpack_require__(/*! ./lib/terminator.js */ "./node_modules/asynckit/lib/terminator.js")
;
// Public API
module.exports = serialOrdered;
// sorting helpers
module.exports.ascending = ascending;
module.exports.descending = descending;
/**
* Runs iterator over provided sorted array elements in series
*
* @param {array|object} list - array or object (named list) to iterate over
* @param {function} iterator - iterator to run
* @param {function} sortMethod - custom sort function
* @param {function} callback - invoked when all elements processed
* @returns {function} - jobs terminator
*/
function serialOrdered(list, iterator, sortMethod, callback)
{
var state = initState(list, sortMethod);
iterate(list, iterator, state, function iteratorHandler(error, result)
{
if (error)
{
callback(error, result);
return;
}
state.index++;
// are we there yet?
if (state.index < (state['keyedList'] || list).length)
{
iterate(list, iterator, state, iteratorHandler);
return;
}
// done here
callback(null, state.results);
});
return terminator.bind(state, callback);
}
/*
* -- Sort methods
*/
/**
* sort helper to sort array elements in ascending order
*
* @param {mixed} a - an item to compare
* @param {mixed} b - an item to compare
* @returns {number} - comparison result
*/
function ascending(a, b)
{
return a < b ? -1 : a > b ? 1 : 0;
}
/**
* sort helper to sort array elements in descending order
*
* @param {mixed} a - an item to compare
* @param {mixed} b - an item to compare
* @returns {number} - comparison result
*/
function descending(a, b)
{
return -1 * ascending(a, b);
}
/***/ }),
/***/ "./src/base-classes/base-cacheable-object/base-cacheable-object.js":
/*!*************************************************************************!*\
!*** ./src/base-classes/base-cacheable-object/base-cacheable-object.js ***!
\*************************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/isEmpty */ "./node_modules/lodash/isEmpty.js");
/* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js");
/* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js");
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _base_object_base_object_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../base-object/base-object.js */ "./src/base-classes/base-object/base-object.js");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _get2() { if (typeof Reflect !== "undefined" && Reflect.get) { _get2 = Reflect.get.bind(); } else { _get2 = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get2.apply(this, arguments); }
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/**
* The base class for all project objects that can be cached. This class is extremely useful for
* classes which have unique identifiers but cannot make API calls.
*
* Note: The id used for caching may be different than any id used by the response from the wire.
* This allows for caching of an instance with the same id but different season data. Example:
* League with different `seasonId`s can all be cached using this functionality. See the
* `getCacheId` method for implementation.
*
* When managing the cache, never set an object to an `undefined` id. Always check that the result
* from `getCacheId` is valid (see `_populateObject` for an example). Otherwise the cache will not
* be in the correct state.
*
* @extends {BaseObject}
*/
var BaseCacheableObject = /*#__PURE__*/function (_BaseObject) {
_inherits(BaseCacheableObject, _BaseObject);
var _super = _createSuper(BaseCacheableObject);
function BaseCacheableObject() {
_classCallCheck(this, BaseCacheableObject);
return _super.apply(this, arguments);
}
_createClass(BaseCacheableObject, [{
key: "getIDParams",
value:
/**
* Returns an object containing all IDs used for API requests and caching for the instance.
* @return {Object}
*/
function getIDParams() {
return this.constructor.getIDParams(this);
}
/**
* Returns the id used for caching. Important for classes that have multiple identifiers. Example:
* League is identified by its `leagueId` and its `seasonId`. This method prevents separate
* seasons from overriding each other's data.
* @return {String|undefined}
*/
}, {
key: "getCacheId",
value: function getCacheId() {
return this.constructor.getCacheId(this);
}
}], [{
key: "_populateObject",
value:
/**
* Defers to `BaseObject._populateObject` and then caches the instance using the caching id from
* `getCacheId`.
* @override
*/
function _populateObject(_ref) {
var data = _ref.data,
constructorParams = _ref.constructorParams,
rawData = _ref.rawData,
instance = _ref.instance,
isDataFromServer = _ref.isDataFromServer;
var populatedInstance = _get2(_getPrototypeOf(BaseCacheableObject), "_populateObject", this).call(this, {
data: data,
constructorParams: constructorParams,
rawData: rawData,
instance: instance,
isDataFromServer: isDataFromServer
});
if (isDataFromServer && populatedInstance.getCacheId()) {
this.cache[populatedInstance.getCacheId()] = populatedInstance;
}
return populatedInstance;
}
/**
* Returns all cached instances of an BaseCacheableObject. If no cache exists, a cache object is
* created. This implementation ensures each class has a unique cache of only instances of the
* BaseCacheableObject that does not overlap with other BaseCacheableObject classes. The keys of
* the cache should use the caching id implemented in `getCacheId`.
* @return {Object.<String, BaseCacheableObject>} The cache of BaseCacheableObjects.
*/
}, {
key: "cache",
get: function get() {
if (!this._cache) {
this._cache = {};
}
return this._cache;
}
/**
* Sets the cache object.
* @param {Object.<String, BaseCacheableObject>} cache
*/,
set: function set(cache) {
this._cache = cache;
}
/**
* Resets cache to an empty object.
*/
}, {
key: "clearCache",
value: function clearCache() {
this._cache = {};
}
/**
* Returns a cached instance matching the passed caching id if it exists. Otherwise, returns
* undefined.
* @param {Number} id This id must match the form of the caching id provided by `getCacheId`.
* @return {BaseCacheableObject|undefined}
*/
}, {
key: "get",
value: function get(id) {
return lodash_get__WEBPACK_IMPORTED_MODULE_2___default()(this.cache, id);
}
/**
* Should be overridden by each subclass. Returns an object containing all IDs used for API
* requests and caching.
* @return {Object}
*/
}, {
key: "getIDParams",
value: function getIDParams() {
return {};
}
/**
* Constructs and returns an id for the cache if possible from the passed params. If construction
* is not possible, returns undefined.
* @param {Object} idParams
* @return {string|undefined}
*/
}, {
key: "getCacheId",
value: function getCacheId(idParams) {
var cacheId = lodash_map__WEBPACK_IMPORTED_MODULE_1___default()(this.getIDParams(idParams), function (value, key) {
return "".concat(key, "=").concat(value, ";");
}).join('');
return lodash_isEmpty__WEBPACK_IMPORTED_MODULE_0___default()(cacheId) ? undefined : cacheId;
}
}]);
return BaseCacheableObject;
}(_base_object_base_object_js__WEBPACK_IMPORTED_MODULE_3__["default"]);
BaseCacheableObject.displayName = 'BaseCacheableObject';
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BaseCacheableObject);
/***/ }),
/***/ "./src/base-classes/base-object/base-object.js":
/*!*****************************************************!*\
!*** ./src/base-classes/base-object/base-object.js ***!
\*****************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var lodash_forEach__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/forEach */ "./node_modules/lodash/forEach.js");
/* harmony import */ var lodash_forEach__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_forEach__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lodash_set__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/set */ "./node_modules/lodash/set.js");
/* harmony import */ var lodash_set__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_set__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! lodash/isUndefined */ "./node_modules/lodash/isUndefined.js");
/* harmony import */ var lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! lodash/isPlainObject */ "./node_modules/lodash/isPlainObject.js");
/* harmony import */ var lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var lodash_isString__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! lodash/isString */ "./node_modules/lodash/isString.js");
/* harmony import */ var lodash_isString__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(lodash_isString__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js");
/* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var lodash_isFunction__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! lodash/isFunction */ "./node_modules/lodash/isFunction.js");
/* harmony import */ var lodash_isFunction__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(lodash_isFunction__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js");
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! lodash/isEmpty */ "./node_modules/lodash/isEmpty.js");
/* harmony import */ var lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var lodash_assignWith__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! lodash/assignWith */ "./node_modules/lodash/assignWith.js");
/* harmony import */ var lodash_assignWith__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(lodash_assignWith__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ../../utils.js */ "./src/utils.js");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
/**
* The base class for all project objects. Provides data mapping functionality.
*/
var BaseObject = /*#__PURE__*/function () {
/**
* @param {Object} options Properties to be assigned to the BaseObject. Must match the keys of the
* BaseObject's `responseMap` or valid options defined by the class's
* `constructor`.
*/
function BaseObject() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, BaseObject);
if (!lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8___default()(options)) {
this.constructor._populateObject({
data: options,
instance: this,
isDataFromServer: false
});
}
}
/**
* The class name. Minification will break `this.constructor.name`; this allows for readable
* logging even in minified code.
* @type {String}
*/
_createClass(BaseObject, null, [{
key: "responseMap",
get: function get() {
return this._responseMap;
},
set: function set(_responseMap) {
this._responseMap = lodash_assignWith__WEBPACK_IMPORTED_MODULE_9___default()({}, this._responseMap, _responseMap);
}
}, {
key: "_processObjectValue",
value:
/**
* Helper for processing items on `responseMap`s that are objects.
* @private
*
* @param {Object} options.data
* @param {BaseObject} options.instance The instance to populate. This instance will be mutated.
* @param {Object} options.constructorParams Params to be passed to the instance's constructor.
* Useful for passing parent data, such as `leagueId`.
* @param {String} options.value The value of the responseMap entry being parsed.
* @return {*}
*/
function _processObjectValue(_ref) {
var data = _ref.data,
rawData = _ref.rawData,
constructorParams = _ref.constructorParams,
instance = _ref.instance,
value = _ref.value;
if (!value.key) {
throw new Error("".concat(this.displayName, ": _populateObject: Invalid responseMap object. Object must define ") + 'key. See docs for typedef of ResponseMapValueObject.');
}
var responseData = lodash_get__WEBPACK_IMPORTED_MODULE_7___default()(data, value.key);
if (lodash_isFunction__WEBPACK_IMPORTED_MODULE_6___default()(value.manualParse)) {
return value.manualParse(responseData, data, rawData, constructorParams, instance);
} else if (value.BaseObject) {
var buildInstance = function buildInstance(passedData) {
return value.BaseObject.buildFromServer(passedData, constructorParams, rawData);
};
return value.isArray ? lodash_map__WEBPACK_IMPORTED_MODULE_5___default()(responseData, buildInstance) : buildInstance(responseData);
}
throw new Error("".concat(this.displayName, ": _populateObject: Invalid responseMap object. Object must define ") + '`BaseObject` or `manualParse`. See docs for typedef of ResponseMapValueObject.');
}
/**
* Helper method for `_populateObject` that houses the attribute mapping logic. Should never be
* used by other methods. See {@link ResponseMapValueObject} for `responseMap` documentation.
* @private
*
* @param {Object} options.data
* @param {BaseObject} options.instance The instance to populate. This instance will be mutated.
* @param {Object} options.constructorParams Params to be passed to the instance's constructor.
* Useful for passing parent data, such as `leagueId`.
* @param {Boolean} options.isDataFromServer When true, the data came from the ESPN API over the
* wire. When false, the data came locally.
* @param {String} options.key The key of the responseMap entry being parsed.
* @param {String} options.value The value of the responseMap entry being parsed.
*/
}, {
key: "_processResponseMapItem",
value: function _processResponseMapItem(_ref2) {
var data = _ref2.data,
rawData = _ref2.rawData,
constructorParams = _ref2.constructorParams,
instance = _ref2.instance,
isDataFromServer = _ref2.isDataFromServer,
key = _ref2.key,
value = _ref2.value;
/**
* @typedef {Object} BaseObject~ResponseMapValueObject
*
* The `responseMap` can have two values: a string or a ResponseMapValueObject. When string, the
* data found on that response is directly mapped to the BaseObject without mutation. When
* ResponseMapValueObject, the data at the `key` will be used to create BaseObject(s) or
* manually parsed with a provided `manualParse function`. Either result is attached to the
* BaseObject being populated.
*
* @property {String} key The key on the response data where the data can be found. This must be
* defined.
* @property {BaseObject} BaseObject The BaseObject to create with the response data.
* @property {Boolean} isArray Whether or not the response data is an array. Useful for
* attributes such as "teams".
* @property {Boolean} defer Whether or not to wait to parse the entry until a second pass of
* the map. This is useful for populating items with cached instances
* that are not guaranteed to be parsed/cached during initial parsing.
* Example: Using Team instances on League.
* @property {function} manualParse A function to manually apply logic to the response. This
* function must return its result to be attached to the
* populated BaseObject. The arguments to this function are:
* (data at the key), (the whole response), (the instance being
* populated).
* @example
* static responseMap = {
* teamId: 'teamId',
* team: {
* key: 'team_on_response',
* BaseObject: true
* },
* teams: {
* key: 'teams_on_response',
* BaseObject: Team,
* isArray: true
* },
* manualTeams: {
* key: 'manual_teams_on_response',
* BaseObject: Team,
* manualParse: (responseData, response, constructorParams, instance) => (
* Team.buildFromServer(responseData)
* )
* }
* };
*/
var item;
if (!isDataFromServer) {
item = lodash_get__WEBPACK_IMPORTED_MODULE_7___default()(data, key);
} else if (lodash_isString__WEBPACK_IMPORTED_MODULE_4___default()(value)) {
item = lodash_get__WEBPACK_IMPORTED_MODULE_7___default()(data, value);
} else if (lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3___default()(value)) {
item = this._processObjectValue({
data: data,
rawData: rawData,
constructorParams: constructorParams,
instance: instance,
value: value
});
} else {
throw new Error("".concat(this.displayName, ": _populateObject: Did not recognize responseMap value type for key ") + "".concat(key));
}
if (!lodash_isUndefined__WEBPACK_IMPORTED_MODULE_2___default()(item)) {
lodash_set__WEBPACK_IMPORTED_MODULE_1___default()(instance, key, item);
}
}
/**
* Returns the passed instance of the BaseObject populated with the passed data, mapping the
* attributes defined in the value of responseMap to the matching key.
* @private
*
* @param {Object} options.data The data to map onto the passed instance.
* @param {BaseObject} options.instance The instance to populate. This instance will be mutated.
* @param {Boolean} options.isDataFromServer When true, the data came from ESPN. When false, the
* data came locally.
* @return {BaseObject} The mutated BaseObject instance.
*/
}, {
key: "_populateObject",
value: function _populateObject(_ref3) {
var _this = this;
var data = _ref3.data,
rawData = _ref3.rawData,
constructorParams = _ref3.constructorParams,
instance = _ref3.instance,
isDataFromServer = _ref3.isDataFromServer;
if (!instance) {
throw new Error("".concat(this.displayName, ": _populateObject: Did not receive instance to populate"));
} else if (lodash_isEmpty__WEBPACK_IMPORTED_MODULE_8___default()(data)) {
return instance;
}
var deferredMapItems = {};
lodash_forEach__WEBPACK_IMPORTED_MODULE_0___default()(this.responseMap, function (value, key) {
if (lodash_isPlainObject__WEBPACK_IMPORTED_MODULE_3___default()(value) && value.defer) {
lodash_set__WEBPACK_IMPORTED_MODULE_1___default()(deferredMapItems, key, value);
} else {
_this._processResponseMapItem({
data: data,
rawData: rawData,
constructorParams: constructorParams,
instance: instance,
isDataFromServer: isDataFromServer,
key: key,
value: value
});
}
});
lodash_forEach__WEBPACK_IMPORTED_MODULE_0___default()(deferredMapItems, function (value, key) {
_this._processResponseMapItem({
data: data,
rawData: rawData,
constructorParams: constructorParams,
instance: instance,
isDataFromServer: isDataFromServer,
key: key,
value: value
});
});
return instance;
}
/**
* Returns a new instance of the BaseObject populated with the passed data that came from ESPN,
* mapping the attributes defined in the value of responseMap to the matching key. Use this method
* when constructing BaseObjects with server responses.
* @param {Object} data Data originating from the server.
* @param {Object} constructorParams Params to be passed to the instance's constructor. Useful
* for passing parent data, such as `leagueId`.
* @return {BaseObject} A new instance of the BaseObject populated with the passed data.
*/
}, {
key: "buildFromServer",
value: function buildFromServer(data, constructorParams) {
var instance = new this(constructorParams);
var flatData = this.flattenResponse ? (0,_utils_js__WEBPACK_IMPORTED_MODULE_10__.flattenObjectSansNumericKeys)(data) : data;
this._populateObject({
data: flatData,
rawData: data,
constructorParams: constructorParams,
instance: instance,
isDataFromServer: true
});
return instance;
}
}]);
return BaseObject;
}();
BaseObject.displayName = 'BaseObject';
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BaseObject);
/***/ }),
/***/ "./src/boxscore-player/boxscore-player.js":
/*!************************************************!*\
!*** ./src/boxscore-player/boxscore-player.js ***!
\************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js");
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _player_player__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../player/player */ "./src/player/player.js");
/* harmony import */ var _player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../player-stats/player-stats */ "./src/player-stats/player-stats.js");
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../constants */ "./src/constants.js");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
/* global PlayerStats */
/**
* Represents a player and their stats on a boxscore.
*
* @augments {Player}
*/
var BoxscorePlayer = /*#__PURE__*/function (_Player) {
_inherits(BoxscorePlayer, _Player);
var _super = _createSuper(BoxscorePlayer);
function BoxscorePlayer() {
_classCallCheck(this, BoxscorePlayer);
return _super.apply(this, arguments);
}
return _createClass(BoxscorePlayer);
}(_player_player__WEBPACK_IMPORTED_MODULE_1__["default"]);
BoxscorePlayer.displayName = 'BoxscorePlayer';
/* eslint-disable jsdoc/no-undefined-types */
/**
* @typedef {PlayerMap} BoxscorePlayerMap
*
* @property {Player} player The player model representing the NFL player.
* @property {string} rosteredPosition The position the player is slotted at in the fantasy lineup
* @property {number} totalPoints The total points scored by the player.
* @property {PlayerStats} pointBreakdown The PlayerStats model with the points scored by the
* player.
* @property {PlayerStats} rawStats The PlayerStats model with the raw statistics registered by
* the player.
*/
/* eslint-enable jsdoc/no-undefined-types */
/**
* @type {BoxscorePlayerMap}
*/
BoxscorePlayer.responseMap = {
availabilityStatus: {
key: 'status',
manualParse: function manualParse(responseData, data, rawData) {
return rawData.playerPoolEntry.status;
}
},
rosteredPosition: {
key: 'lineupSlotId',
manualParse: function manualParse(responseData) {
return lodash_get__WEBPACK_IMPORTED_MODULE_0___default()(_constants__WEBPACK_IMPORTED_MODULE_3__.slotCategoryIdToPositionMap, responseData);
}
},
totalPoints: 'appliedStatTotal',
pointBreakdown: {
key: 'stats',
manualParse: function manualParse(responseData, data, rawData, constructorParams) {
return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({
responseData: responseData,
constructorParams: constructorParams,
usesPoints: true,
statKey: 'appliedStats',
statSourceId: 0,
statSplitTypeId: 1
});
}
},
projectedPointBreakdown: {
key: 'stats',
manualParse: function manualParse(responseData, data, rawData, constructorParams) {
return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({
responseData: responseData,
constructorParams: constructorParams,
usesPoints: true,
statKey: 'appliedStats',
statSourceId: 1,
statSplitTypeId: 1
});
}
},
rawStats: {
key: 'stats',
manualParse: function manualParse(responseData, data, rawData, constructorParams) {
return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({
responseData: responseData,
constructorParams: constructorParams,
usesPoints: false,
statKey: 'stats',
statSourceId: 0,
statSplitTypeId: 1
});
}
},
projectedRawStats: {
key: 'stats',
manualParse: function manualParse(responseData, data, rawData, constructorParams) {
return (0,_player_stats_player_stats__WEBPACK_IMPORTED_MODULE_2__.parsePlayerStats)({
responseData: responseData,
constructorParams: constructorParams,
usesPoints: false,
statKey: 'stats',
statSourceId: 1,
statSplitTypeId: 1
});
}
}
};
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (BoxscorePlayer);
/***/ }),
/***/ "./src/boxscore/boxscore.js":
/*!**********************************!*\
!*** ./src/boxscore/boxscore.js ***!
\**********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash/map */ "./node_modules/lodash/map.js");
/* harmony import */ var lodash_map__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash_map__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! lodash/get */ "./node_modules/lodash/get.js");
/* harmony import */ var lodash_get__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(lodash_get__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _base_classes_base_object_base_object__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../base-classes/base-object/base-object */ "./src/base-classes/base-object/base-object.js");
/* harmony import */ var _boxscore_player_boxscore_player__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../boxscore-player/boxscore-player */ "./src/boxscore-player/boxscore-player.js");
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : fun