Skip to content

Instantly share code, notes, and snippets.

View abdelgrib's full-sized avatar

Abdellah GRIB abdelgrib

View GitHub Profile
@abdelgrib
abdelgrib / http_helper_code.ts
Last active November 22, 2021 17:17
TypeScript - HTTP and Fetch API helper
export const Status = {
Ok: 200,
Unassigned: 299,
BadRequest: 400,
Unauthorized: 401,
NotFound: 404,
};
export const Methods = {
Get: "GET",
@abdelgrib
abdelgrib / axios_helper.js
Last active December 31, 2022 20:37
JavaScript - HTTP and Axios helper
import axios from "axios";
require("dotenv").config();
const authTokenKey = "blabla"; /* Example of a bearer token stored in localStorage */
/*Axios configuration*/
const axiosInstance = axios.create({
baseURL: process.env.REACT_APP_API_URL,
});
@abdelgrib
abdelgrib / http_helper.js
Last active October 25, 2020 13:37
JavaScript - HTTP and Fetch API helper
export const Status = {
Ok: 200,
Unassigned: 299,
BadRequest: 400,
Unauthorized: 401,
NotFound: 404,
};
export const Methods = {
Get: "GET",
@abdelgrib
abdelgrib / form_helper.js
Last active April 13, 2022 09:52
JavaScript, HTML5 - Form helper
export default class FormHelper {
/**
* Check input for validity using JavaScript/HTML5 client-side form validation
* Link : https://developer.mozilla.org/en-US/docs/Learn/Forms/Form_validation
* @param {object} target - e.g. JavaScript event.target or selected HTML element object
* @returns {string []} - Errors list
*/
static inputValidation = (target) => {
if (!target) return null;
@abdelgrib
abdelgrib / basic_functions.js
Last active May 2, 2020 13:38
Useful functions in JavaScript
/*Date functions*/
/**
* Returns the number of the current week
* @returns {number} - Number of the current week
*/
Date.prototype.getWeek = function()
{
var date = new Date(this.getTime());
date.setHours(0, 0, 0, 0);
// Thursday in current week decides the year.