This file contains hidden or 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 getUrlParams = (url) => { | |
| const { searchParams } = new URL(url); | |
| return Object.fromEntries([...searchParams.entries()]); | |
| }; |
This file contains hidden or 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 createReducer = (initialState = {}, handlers = {}) => ( | |
| state = {}, | |
| action = {} | |
| ) => | |
| handlers.hasOwnProperty(action.type) | |
| ? handlers[action.type](state, action) | |
| : { ...initialState, ...state }; | |
| export default createReducer; |
This file contains hidden or 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 API_URL = 'https://apis.google.com/js/api.js'; | |
| const GOOGLE_CLIENT_ID = ''; | |
| const GOOGLE_CLIENT_SCOPE = ''; | |
| function loadScript(src) { | |
| return new Promise((resolve, reject) => { | |
| try { | |
| if (!document.querySelector(`script[src="${src}"]`)) { |
This file contains hidden or 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
| function processRow(row, separator) { | |
| let finalVal = ""; | |
| for (let j = 0; j < row.length; j++) { | |
| let innerValue = row[j] === null ? "" : row[j].toString(); | |
| if (row[j] instanceof Date) { | |
| innerValue = row[j].toLocaleString(); | |
| } |
This file contains hidden or 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 containsHTML = (str) => /<[a-z][\s\S]*>/i.test(str); |
This file contains hidden or 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
| import { Buffer } from 'buffer'; | |
| const generateBasicToken = (user, pass) => | |
| new Buffer([user, pass].join(':')).toString('base64'); |
This file contains hidden or 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 asyncCompose = (…functions) => input => functions.reduceRight((chain, func) => chain.then(func), Promise.resolve(input)); | |
| const asyncPipe = (…functions) => input => functions.reduce((chain, func) => chain.then(func), Promise.resolve(input)); |
This file contains hidden or 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 parseHex = (hex) => (startChar, endChar) => | |
| parseInt(hex.slice(startChar, endChar), 16); | |
| function hexToRGBA(hex, a = 1) { | |
| const r = parseHex(hex)(1, 3); | |
| const g = parseHex(hex)(3, 5); | |
| const b = parseHex(hex)(5, 7); | |
| return `rgba(${r},${g},${b},${a})`; | |
| } |
This file contains hidden or 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 pipe = (...ops) => ops.reduce( | |
| (a, b) => (...arg) => b(a(...arg)) | |
| ) |
This file contains hidden or 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 bytes = (s) => ~-encodeURI(s).split(/%..|./).length; | |
| const jsonSize = (s) => bytes(JSON.stringify(s)); |