UNPKG

797 BJavaScriptView Raw
1/**
2 @function parseSides
3 @desc Converts a string of directional CSS shorthand values into an object with the values expanded.
4 @param {String|Number} sides The CSS shorthand string to expand.
5 */
6export default function(sides) {
7 var values;
8 if (typeof sides === "number") { values = [sides]; }
9 else { values = sides.split(/\s+/); }
10
11 if (values.length === 1) { values = [values[0], values[0], values[0], values[0]]; }
12 else if (values.length === 2) { values = values.concat(values); }
13 else if (values.length === 3) { values.push(values[1]); }
14
15 return [
16 "top",
17 "right",
18 "bottom",
19 "left"
20 ].reduce(function (acc, direction, i) {
21 var value = parseFloat(values[i]);
22 acc[direction] = value || 0;
23 return acc;
24 }, {});
25}
26
27//# sourceMappingURL=parseSides.js.map
\No newline at end of file