View idGenerator.ts
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 |
View regexp.ts
/** | |
* 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 |
View index.ts
export { settingsStore } from "./settings"; | |
export { withSettings } from "./withSettings"; | |
export { useSettings } from "./useSettings"; |
View dateDiff.ts
type DATE = number | Date; | |
const makeNumber = (value: DATE) => { | |
if (typeof value !== "number") { | |
value = value.getTime(); | |
} | |
return value; | |
}; | |
const daysDiff = (dateA: DATE, dateB: DATE) => { |
View forEachObject.ts
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)) { |
View disableIOSScroll.js
const preventDefault = evt => { | |
evt.preventDefault() | |
} | |
const disableScroll = () => { | |
window.addEventListener("touchmove", preventDefault, { passive: false }) | |
window.addEventListener("touchend", preventDefault, { passive: false }) | |
} | |
const enableScroll = () => { |
View peselVadation.ts
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; |
View inlineSVG.ts
// | |
// 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; |
View tdd_nodeelements.js
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)) { |
View mobileDetect.js
export default class MobileDetect { | |
constructor() { | |
this.mount(); | |
} | |
mount() { | |
if (typeof window === "object") { | |
if (window.mobile !== "undefined") { | |
window.mobile = function () { | |
let check = false; |
NewerOlder