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
/** | |
* Pseudo styles | |
* @param {Object} pseudoStates - state object with keys matching pseudo attributes | |
* @returns {Object} use(styles) | |
* | |
* @example | |
* const styles = {color: '#000', hover: {color: 'red'}, active: {color: 'green'}}; | |
* const state = {hover: true, active: true}; | |
* pseudoStyles(state) | |
* .use(styles.button) |
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
/** | |
* Immutable move item | |
*/ | |
const move = (arr, from, to) => { | |
const clone = [...arr]; | |
Array.prototype.splice.call(clone, to, 0, | |
Array.prototype.splice.call(clone, from, 1)[0] | |
); | |
return clone; | |
}; |
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
/** | |
* Assigns object keys to the assigned child object | |
* @returns {Object} keyed object | |
*/ | |
const withKeys = (obj, uid = 'uid') => { | |
return Object.keys(obj).reduce((keyObj, key) => { | |
let keyed; | |
if (typeof obj[key] === 'object') { | |
keyed = {...obj[key], [uid]: key}; | |
} else { |
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
// Array Destructure Assignment Examples | |
const myArray = ['a', ['b', ['c']], ['d']]; | |
const oldWayA = myArray[0]; // 'a' | |
const [newWayA] = myArray; // 'a' | |
const oldWayB = myArray[1][0][0]; // 'b' |
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
#!/usr/bin/env node | |
const fs = require('fs'); | |
const path = require('path'); | |
const args = process.argv.slice(2); | |
const targetDependencies = args.filter(arg => arg.includes('ependencies')).length | |
? args.filter(arg => arg.includes('ependencies')) | |
: ['peerDependencies', 'devDependencies', 'dependencies']; | |
const packageFiles = args.filter(arg => arg.includes('json')).length |
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
/** | |
* Uncontrolled component | |
* DOM controls state and is source of truth. | |
*/ | |
const EditHeader = ({ | |
style, | |
value, | |
}) => { | |
let elem; |
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 parseStyles | |
* Parses a string of inline styles into a javascript object with casing for react | |
* | |
* @param {string} styles | |
* @returns {Object} | |
*/ | |
const parseStyles = styles => styles | |
.split(';') | |
.filter(style => style.split(':')[0] && style.split(':')[1]) |
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
/** | |
* fsExists promise | |
* @param {string} fp - filepath to check exists | |
* @returns {Promise} fsExists | |
*/ | |
const fsExists = (fp) => new Promise( | |
resolve => fs.access(fp, err => resolve(!err)) | |
); | |
const filepath = path.resolve(__dirname, 'tmp/service-worker.js'); |
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
<p class="pseudo-content" before="“" after="”">You can quote me on this</p> | |
<!-- will render as: | |
"You can quote me on this" | |
--> |
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 localforage from 'localforage'; | |
import throttle from 'lodash/throttle'; | |
const forageConfig = { | |
name: 'myproject', | |
storeName: 'myproject-data', | |
}; | |
const appStore = localforage.createInstance(forageConfig); |