Skip to content

Instantly share code, notes, and snippets.

View adamgruber's full-sized avatar

Adam Gruber adamgruber

View GitHub Profile
@adamgruber
adamgruber / asPureComponent.js
Created September 6, 2017 14:14
HOC to turn a stateless functional component into an instance of a PureComponent
import { PureComponent } from 'react';
/**
* PureComponent HOC.
*
* @param {Function} renderFn Stateless functional component
* @return {PureComponent} Component wrapped as PureComponent
*/
module.exports = function asPureComponent(renderFn) {
const comp = class AsPureComponent extends PureComponent {
@adamgruber
adamgruber / extractSassToJs.js
Created June 11, 2017 12:48
Use sass-extract to get JS object from sass variables
/* eslint-disable import/no-webpack-loader-syntax */
import mapValues from 'lodash/mapValues';
const style = require('sass-extract-loader!./colors.scss');
function getSassValue(sassVar) {
const {type,value} = sassVar;
switch (type) {
case 'SassString':
case 'SassBoolean':
@adamgruber
adamgruber / jsonToJs.js
Last active May 12, 2017 13:56
Convert a JSON.stringified string to a regular JS object with single-quotes
function jsonToJs(jsonStr) {
return jsonStr
.replace(/^(\s+)"(\w+\b)"/g, "$1$2")
.replace(/"(.+)"(,?$)/g, "'$1'$2");
}
@adamgruber
adamgruber / samsung.js
Last active August 29, 2015 14:04
samsung.js - A jQuery Plugin
function newSamsungProduct() {
return $('apple').clone();
}