Created
January 29, 2016 01:15
-
-
Save basarat/aa222c99a1f8da36bc23 to your computer and use it in GitHub Desktop.
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
| type PaddingUnit = number | string; | |
| export function padding(a: PaddingUnit, b?: PaddingUnit, c?: PaddingUnit, d?: PaddingUnit) { | |
| if (!b && !c && !d) { | |
| b = c = d = a; | |
| } | |
| else if (!c && !d) { | |
| c = a; | |
| d = b; | |
| } | |
| return { | |
| paddingTop: _toString(a), | |
| paddingRight: _toString(b), | |
| paddingBottom: _toString(c), | |
| paddingLeft: _toString(d) | |
| }; | |
| } | |
| function _toString(value: PaddingUnit) { | |
| if (typeof value === 'number') { | |
| return value.toString() + 'px'; | |
| } | |
| else { | |
| return value.toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment