util.normalizeSides(box)
Return a new object of the form { top: Number, right: Number, bottom: Number, left: Number }
.
If box
is a number, the value of all four sides will be this number. If box
is an object with some/all of the top
, right
, bottom
, left
properties defined, the values of these properties will be used.
Composite properties horizontal
(for right and left side) and vertical
(for top and bottom side) can be used, as well; they will be destructured appropriately. When two properties clash (e.g. horizontal: 10
and left: 5
), the more specific one prevails (here the returned object would contain right: 10
and left: 5
).
If any property is missing, its side will be set to 0
in the resulting object.
joint.util.normalizeSides() // { top: 0, right: 0, bottom: 0, left: 0 }
joint.util.normalizeSides(5) // { top: 5, right: 5, bottom: 5, left: 5 }
joint.util.normalizeSides({ horizontal: 5 }) // { top: 0, right: 5, bottom: 0, left: 5 }
joint.util.normalizeSides({ left: 5 }) // { top: 0, right: 0, bottom: 0, left: 5 }
joint.util.normalizeSides({ horizontal: 10, left: 5 }) // { top: 0, right: 10, bottom: 0, left: 5 }
joint.util.normalizeSides({ horizontal: 0, left: 5 }) // { top: 0, left: 5, right: 0, bottom: 0 }
JointJS and Rappid use this method internally whenever there is an option object that can be specified either by a number or a (possibly incomplete) object with sides (for example, the padding
option).