Skip to content

Instantly share code, notes, and snippets.

View mturnwall's full-sized avatar

Michael Turnwall mturnwall

View GitHub Profile
@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)) {
@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 / 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 / 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 / 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',
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@mturnwall
mturnwall / SassMeister-input.scss
Last active October 28, 2020 07:56
Generated by SassMeister.com.
// ----
// libsass (v3.5.0.beta.2)
// ----
$font-size-base: 16px !default;
$font-fallback-type: '' !default;
@function get-relative-font-size($actual, $relative: $font-size-base, $unitType: 'rem') {
@if $unitType == 'rem' {
@return #{($actual / $font-size-base)}rem;
@mturnwall
mturnwall / SassMeister-input.scss
Last active November 10, 2017 20:08
Sass Button Mixin
// ----
// libsass (v3.5.0.beta.2)
// ----
$btn-themes: (
primary: (
bgColor: #ef6c29,
border: #333,
color: #fff,
hover: darken 15%,
@mturnwall
mturnwall / SassMeister-input.scss
Last active October 28, 2020 07:36
Generated by SassMeister.com.
// ----
// libsass (v3.3.6)
// ----
@mixin heading-2() {
font-size: 1.1rem;
line-height: 1.2;
font-weight: 500;
}
@mixin button($color: #fff, $bg-color: #f00) {
@mturnwall
mturnwall / buttons_with_themes.scss
Last active April 9, 2016 01:10
Generated by SassMeister.com.
// ----
// libsass (v3.3.2)
// ----
/// Button themes
$button-themes: (
primary: (
bgColor: blue,
color: white
),