Last active
August 21, 2017 08:31
-
-
Save preco21/dcbc793ce134dcd17a1c312dae63f059 to your computer and use it in GitHub Desktop.
A simple `calcMargin()`
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
export default function calcMargin(obj = {}) { | |
if (Number.isInteger(obj)) { | |
return { | |
top: obj, | |
right: obj, | |
bottom: obj, | |
left: obj, | |
}; | |
} | |
if (typeof obj === 'string') { | |
const [top, right = top, bottom = top, left = right] = obj.split(' '); | |
return { | |
top: Number(top), | |
right: Number(right), | |
bottom: Number(bottom), | |
left: Number(left), | |
}; | |
} | |
const {top = 0, right = 0, bottom = 0, left = 0} = obj; | |
return { | |
top, | |
right, | |
bottom, | |
left, | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment