Skip to content

Instantly share code, notes, and snippets.

View michalklim's full-sized avatar
🎯
Focusing

Michal Klim michalklim

🎯
Focusing
View GitHub Profile
@michalklim
michalklim / RecursiveFileSearch.js
Created November 12, 2018 18:41
Recursively search for files in directories
/*
Given collection like:
```
const fileData = {
dir : 'app',
files : [
'index.html',
{
dir : 'js',
files: [
@michalklim
michalklim / reactRouterShapes.js
Created June 28, 2018 12:48
React Router shapes
import PropTypes from 'prop-types'
export const locationShape = PropTypes.shape({
pathname: PropTypes.string.isRequired,
search: PropTypes.string.isRequired,
hash: PropTypes.string.isRequired,
state: PropTypes.object,
});
export const historyShape = PropTypes.shape({
@michalklim
michalklim / compactFormData.js
Last active September 19, 2018 12:11
Compact form data
export const compactFormData = obj => {
const objectFilteredKeys = Object.keys(obj).filter(k => !isNil(obj[k]) && !(isString(obj[k]) && isEmpty(obj[k])))
const assignData = (newObj, k) =>
isObject(obj[k]) ? Object.assign(newObj, { [k]: compactFormData(obj[k]) }) : Object.assign(newObj, { [k]: obj[k] })
if (isArray(obj)) {
return objectFilteredKeys.reduce(assignData, [])
} else if (isObject(obj)) {
return objectFilteredKeys.reduce(assignData, {})