Skip to content

Instantly share code, notes, and snippets.

View mturnwall's full-sized avatar

Michael Turnwall mturnwall

View GitHub Profile
@mturnwall
mturnwall / data_array.js
Last active August 24, 2018 07:32
Code Exercise 1.0
const dataOptions = [{
id: '1',
name: 'Surgery',
value: 'surgery',
children: [{
id: '1.1',
name: 'Septoplasty',
value: 'septoplasty',
},{
id: '1.2',
@mturnwall
mturnwall / renameKey.js
Last active October 14, 2018 18:08
Rename Object Property
/**
* Change the key for a giving object
*
* @param {string} oldKey - the key (property) you want to change
* @param {string} newKey - the new key
* @param {Object} old - object that needs to be changed
*
* @returns {Object}
*/
export default function (oldKey, newKey, {[oldKey]: old, ...rest}) {
@mturnwall
mturnwall / api.js
Created June 7, 2019 17:07
Promise wrapper for @fdaciuk/ajax
// Requires https://www.npmjs.com/package/@fdaciuk/ajax
import ajax from '@fdaciuk/ajax';
/**
* Object that holds all the API endpoints.
* @example
* {
* apiName: '/apiPath'
* }
*/
@mturnwall
mturnwall / color-adjust.js
Last active April 29, 2020 17:03
Color Adjust Functions
import { hex, rgb } from 'color-convert';
/**
* Determine if a string is a hex color
* @param {string} color - hex representation of a color
* @returns {boolean}
*/
const isHexColor = color => /^#?(?:[a-f0-9]{3}){1,2}$/i.test(color);
/**
@mturnwall
mturnwall / getObjValue.js
Created September 30, 2020 22:34
Function to get a value from an object regardless of the object's depth
/**
*
* @param {Object} obj - the object you want to get a value out of
* @param {Array | String} path - the path to the value, can either be an array `['a', 'b', 'c']` of keys or
* string using dotnotation `a.b.c`
* @param {*} [defaultValue=undefined] the value you want to return if the key is not found in the object
*/
const getObjValue = (obj, path, defaultValue) => {
let checkedPath = path;
if (!Array.isArray(checkedPath)) {