Every directory will have an index.js which is used solely for gathering exports
The services directory is for getting external data The utils directory is for utility functions
Run for dev using
npm run dev
This code provides functions to make API calls using the Axios library. It contains the following functions:
- callApi - a function that makes an API call using the URL and options provided. It returns the response from the server.
- createApiUrl - a function that returns an API URL based on the baseUrl, endpoint and queryParams.
- createApiOptions - a function that returns the request api options, with default fallbacks.
- handleError - a function that handles API call errors.
- handleErrorCode - a function for handling error codes.
- handleResponse - a function for handling API response.
- parseResponse - a function for parsing API response data.
Example Usage -
const thisUrl = useApi.createApiUrl(`https://example.com`, `example-dir`, `{ fb-tracking: 'abcd', google: 'efgh' }`);
const thisOptions = useApi.createApiOptions({method: 'post'});
const thisApiCall = await useApi.callApi(thisUrl, thisOptions); // Use inside async
This code provides date utilities, for formatting dates and getting future, past and current dates / datetimes
- getCurrentDate - a function to get the datetime now
- getYesterdayDate - a function to get the date yesterday
- formatDateToIsoString - a function to format any date / datetime to ISO String format
- minutesFromNow - a function to generate a datetime for x minutes from now
Example Usage -
const now = getCurrentDate();
const isoNow = formatDateToIsoString(now);
This code provides encryption and tokenization utility functions
- encrypt - a function that encrypts a string
- decrypt - a function that decrypts a string
- createToken - a function that creates a random token (currently 20 characters long)
This code provides utility functions for formatting text and other inputs
- isEqualLowerCase - a function that converts two strings to lowerCase and compares them