This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const idGenerator = (length: number) => { | |
const allowedCharacters = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" | |
let response: string = "" | |
for (let i = 0; i < length; i++) { | |
const {length: charLength} = allowedCharacters | |
response += allowedCharacters.charAt(Math.floor(Math.random() * charLength)) | |
} | |
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Regular Expression | |
* for common use! | |
* | |
* @author Amadeusz Blanik | |
*/ | |
const GoogleAnalytics = /^UA-\d{4,9}-\d{1,4}$/i; | |
const GoogleTagManager = /^GTM-[A-Z0-9]{1,7}$/i; | |
const FacebookPages = /(?:https?:\/\/)?(?:www\.)?facebook\.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[\w\-]*\/)*([\w\-\.]*)/ // @author https://gist.github.com/marcgg/733592 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export { settingsStore } from "./settings"; | |
export { withSettings } from "./withSettings"; | |
export { useSettings } from "./useSettings"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type DATE = number | Date; | |
const makeNumber = (value: DATE) => { | |
if (typeof value !== "number") { | |
value = value.getTime(); | |
} | |
return value; | |
}; | |
const daysDiff = (dateA: DATE, dateB: DATE) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ActionTypeProps<P> { | |
key: keyof P, | |
value: any, | |
} | |
type actionType<P> = (props: ActionTypeProps<P>) => void | |
type forEachObjectType<P> = (object: P, action: actionType<P>) => void | |
export const forEachObject: forEachObjectType<{ [key: string]: any }> = (object, action) => { | |
for (const [key, value] of Object.entries(object)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const preventDefault = evt => { | |
evt.preventDefault() | |
} | |
const disableScroll = () => { | |
window.addEventListener("touchmove", preventDefault, { passive: false }) | |
window.addEventListener("touchend", preventDefault, { passive: false }) | |
} | |
const enableScroll = () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkSum = (digits: number[]) => { | |
const digit11 = digits[10]; | |
digits.pop(); | |
const times = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]; | |
const reducer = (accumulator, currentValue, index) => accumulator + (currentValue * times[index]); | |
let sum = digits.reduce(reducer); | |
sum %= 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// inlineSVG.ts | |
// Works with React | |
// | |
// Created by Amadeusz Blanik on 24/05/2019. | |
// Copyright © 2019 Amadeusz Blanik. All rights reserved. | |
// | |
interface SVGResponse extends Response { | |
parsedBody?: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isDOMelement = (element, nodeListAllowed = true) => { | |
if (typeof element !== "object" || element === null) { | |
console.debug("Element is not an object.\nIt's fine you are in debug mode."); | |
return false; | |
} else { | |
if (!element instanceof HTMLElement) { | |
console.warn("element is not an instanceof HTMLElement"); | |
return false; | |
} else if (typeof element.classList !== "object") { | |
if (!NodeList.prototype.isPrototypeOf(element)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class MobileDetect { | |
constructor() { | |
this.mount(); | |
} | |
mount() { | |
if (typeof window === "object") { | |
if (window.mobile !== "undefined") { | |
window.mobile = function () { | |
let check = false; |
NewerOlder