node-fantasyJS
(written by d4nny)
Overview
The fantasyJS module provides functionality for interacting with the fantasy.cat API and the FC2 API. It also encapsulates the logic for working with IndexedDB and handling data storage.
The module can be used in any browser environment. It does work in a vanilla HTML/CSS/JS environament however, it is not intended to do so and it will break some methods. You can use it by removing the exports and the node:fs
module. But keep in mind that this will break some methods.
The module can be used with a large variety of frameworks and contexts:
-
Single-page applications (SPAs): Whether you are using a framework like React, Angular, or Vue.js, or building a custom SPA, you can incorporate this code to manage client-side data storage.
-
Progressive Web Apps (PWAs): PWAs are web applications that can provide native-like experiences on mobile devices. This code can be used to enable data storage and offline capabilities in PWAs.
-
Hybrid mobile applications: If you are using frameworks like Cordova or Ionic to build hybrid mobile applications, this code can be used to store data on the device using IndexedDB.
-
Electron applications: Electron allows you to build cross-platform desktop applications using web technologies. You can use this code in Electron applications to implement client-side data storage.
Installation
Download the necessary files from here. The archive will always be named node-fantasyJS - vX.X.X.zip
and it contains 2 files: fantasyJS.js
(main source file) and fantasyJS-min.js
(minified version of fantasyJS.js
).
Usage
In order to use the files in your code you will need to import them according to the framework or technology you are using.
Angular/Vue/React: import { fantasyAPI, IndexedDB } from './path/to/fantasyJS'
IndexedDB()
Description
The API
IndexedDB is a low-level API for client-side storage of significant amounts of structured data, including files/blobs. This API uses indexes to enable high-performance searches of this data. For more information regarding indexedDB, check out the MDN documentation here.
The Function
The IndexedDB()
function provides an interface for working with indexedDB, allowing you to store and retrieve data on the client-side.
The function accepts two parameters. IndexedDB(dbName, storeName)
.
-
dbName
(string) it references the database name you want to modify. -
storeName
(string) it references the object stores. More information on object stores can be found here.
A database can contain multiple uniquely named object stores which can contain multiple objects or other data types.
It includes methods for setting, getting, removing, and clearing data in the IndexedDB database.
Methods
Note: The value
parameter accepts all JavaScript data types. (More Info) The key
parameter has to be a string.
set(key, value)
: Sets the value of a given key in the IndexedDB database.
get(key)
: Retrieves the value associated with a given key from the IndexedDB database.
remove(key)
: Removes the value associated with a given key from the IndexedDB database.
clear()
: Clears all data stored in the IndexedDB database.
Usage
fantasyAPI
Description
fantasyAPI
is the exported variable that contains the WebAPI()
function. It is being exported in this way in order to prevent confusion.
This function encapsulates the functionality for making HTTP requests to web APIs, specifically the fantasy.cat web API. It provides methods for performing most of the API operations presented in the fantasy.cat SDK.
Methods
All the available methods are named after their counterparts as found in the web API documentation (here).
The methods available in this module follow this format:
JavaScript | |
---|---|
Where:
-
isRequired()
is a function that ensures the parameter entered is not missing. -
sanityCheck()
is a function that the makes sure the entered parameters are not empty strings. -
software = 'universe'
all methods' software parameter will default to 'universe' if no parameter is provided
The rest of the parameters are named after their web API counterparts. (Such as key = license key, and so on).
Usage
JavaScript | |
---|---|