index.js
27 lines
| 1 | export default function shorthandCSS( top, right, bottom, left, unit ) { |
| 2 | if ( '' === top && '' === right && '' === bottom && '' === left ) { |
| 3 | return; |
| 4 | } |
| 5 | |
| 6 | top = ( parseFloat( top ) != 0 && '' !== top ) ? parseFloat( top ) + unit + ' ' : '0 '; // eslint-disable-line eqeqeq |
| 7 | right = ( parseFloat( right ) != 0 && '' !== right ) ? parseFloat( right ) + unit + ' ' : '0 '; // eslint-disable-line eqeqeq |
| 8 | bottom = ( parseFloat( bottom ) != 0 && '' !== bottom ) ? parseFloat( bottom ) + unit + ' ' : '0 '; // eslint-disable-line eqeqeq |
| 9 | left = ( parseFloat( left ) != 0 && '' !== left ) ? parseFloat( left ) + unit + ' ' : '0 '; // eslint-disable-line eqeqeq |
| 10 | |
| 11 | if ( right === left ) { |
| 12 | left = ''; |
| 13 | |
| 14 | if ( top === bottom ) { |
| 15 | bottom = ''; |
| 16 | |
| 17 | if ( top === right ) { |
| 18 | right = ''; |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | const output = top + right + bottom + left; |
| 24 | |
| 25 | return output.trim(); |
| 26 | } |
| 27 |