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 composePromise = (...fns) => initialValue => | |
fns.reduceRight((res, fn) => Promise.resolve(res).then(fn), initialValue); | |
// Individual Promises | |
const saveAppFee = () => saveFees(a, b, c); | |
const saveLnpFee = () => saveFees(x, y, z); | |
// Composed Promises | |
const saveAppAndLnp = composePromise(saveAppFee, saveLnpFee); | |
const saveApp = composePromise(saveAppFee); |
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
// Arrow | |
const buildMockArray = <T>(num: number, content: T): T[] => Array(num).fill(null).map(() => content); | |
// Traditional | |
function buildMockArray<T>(num: number, content: T): T[] { | |
return Array(num).fill(null).map(() => content); | |
} |
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
{ | |
"Stateless Functional Component": { | |
"prefix": "stateless", | |
"body": [ | |
"import React from 'react';", | |
"import PropTypes from 'prop-types';", | |
"", | |
"const ${TM_FILENAME_BASE/(.*)\\..+$/$1/} = () => {", | |
" return <div className=\"\"></div>;", | |
"}", |
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
// From https://stackoverflow.com/questions/286141/remove-blank-attributes-from-an-object-in-javascript | |
const removeEmpty = (obj) => { | |
return Object.keys(obj) | |
.filter(k => obj[k] !== null && obj[k] !== undefined && obj[k] !== '') | |
.reduce((newObj, k) => { | |
return typeof obj[k] === 'object' ? | |
Object.assign(newObj, {[k]: removeEmpty(obj[k])}) : // Recurse. | |
Object.assign(newObj, {[k]: obj[k]}); // Copy value. | |
}, {}); | |
} |
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 flattenFilePath = (pathPart, directoryOrFileContents) => { | |
return Object.entries(directoryOrFileContents).reduce((flattenedFilePaths, [key, value]) => { | |
if (typeof value === "object") { | |
Object.assign(flattenedFilePaths, flattenFilePath(`${pathPart}/${key}`, value)) | |
} else { | |
flattenedFilePaths[`${pathPart}/${key}`] = value | |
} | |
return flattenedFilePaths | |
}, {}) |
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 fs = require('fs'); | |
// Paths functions from | |
// https://lowrey.me/getting-all-paths-of-an-javascript-object/ | |
function getPaths(root) { | |
let paths = []; | |
let nodes = [{ | |
obj: root, | |
path: [] |
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 pause = (duration) => new Promise(res => setTimeout(res, duration)); | |
const retry = (retries, fn) => | |
fn().catch(err => retries > 1 ? retry(retries - 1, fn) : Promise.reject(err)); | |
const backoff = (retries, fn, delay = 500) => | |
fn().catch(err => retries > 1 | |
? pause(delay).then(() => backoff(retries - 1, fn, delay * 2)) | |
: Promise.reject(err)); |
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 { transform, isEqual, isObject } from 'lodash'; | |
/** | |
* Deep diff between two object, using lodash | |
* @param {Object} object Object compared | |
* @param {Object} base Object to compare with | |
* @return {Object} Return a new object who represent the diff | |
*/ | |
function difference(object, base) { | |
return transform(object, (result, value, key) => { |
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
/* ES5, using Bluebird */ | |
var isMomHappy = true; | |
// Promise | |
var willIGetNewPhone = new Promise( | |
function (resolve, reject) { | |
if (isMomHappy) { | |
var phone = { | |
brand: 'Samsung', | |
color: 'black' |
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
@mixin transform($property) { | |
-webkit-transform: $property; | |
-ms-transform: $property; | |
transform: $property; | |
} | |
.box { @include transform(rotate(30deg)); } |