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)); } |
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 increment(input) { return input + 1;} | |
function decrement(input) { return input - 1; } | |
function double(input) { return input * 2; } | |
function halve(input) { return input / 2; } | |
var initial_value = 1; | |
var pipeline = [ | |
increment, | |
increment, |
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
// Avoid "Cannot read property of undefined" | |
// https://silvantroxler.ch/2017/avoid-cannot-read-property-of-undefined/ | |
export function getSafe(fn) { | |
try { | |
return fn(); | |
} catch (e) { | |
return undefined; | |
} | |
} |