PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.8.0
GenerateBlocks v1.8.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / utils / shorthand-css / index.js
generateblocks / src / utils / shorthand-css Last commit date
index.js 2 years ago
index.js
35 lines
1 import isNumeric from '../is-numeric';
2
3 function value( num, unit ) {
4 return isNumeric( num ) && unit
5 ? parseFloat( num ) + unit
6 : num;
7 }
8
9 export default function shorthandCSS( top, right, bottom, left, unit ) {
10 if ( '' === top && '' === right && '' === bottom && '' === left ) {
11 return;
12 }
13
14 top = ( top != 0 && '' !== top ) ? value( top, unit ) + ' ' : '0 '; // eslint-disable-line eqeqeq
15 right = ( right != 0 && '' !== right ) ? value( right, unit ) + ' ' : '0 '; // eslint-disable-line eqeqeq
16 bottom = ( bottom != 0 && '' !== bottom ) ? value( bottom, unit ) + ' ' : '0 '; // eslint-disable-line eqeqeq
17 left = ( left != 0 && '' !== left ) ? value( left, unit ) + ' ' : '0 '; // eslint-disable-line eqeqeq
18
19 if ( right === left ) {
20 left = '';
21
22 if ( top === bottom ) {
23 bottom = '';
24
25 if ( top === right ) {
26 right = '';
27 }
28 }
29 }
30
31 const output = top + right + bottom + left;
32
33 return output.trim();
34 }
35