UNPKG

jointjs

Version:

JavaScript diagramming library

37 lines (27 loc) 2.37 kB
<pre class="docs-method-signature"><code>util.parseCssNumeric(value)</code></pre> <p>Parse the provided value as a float and return an object with the number as the <code>value</code> parameter. If the value cannot be converted into a number, return <code>null</code>.</p> <p>If the number is followed by a unit, assign it as the <code>unit</code> parameter in the return object. If there is no unit, assign an empty string. Examples:</p> <pre><code>joint.util.parseCssNumeric('hello'); // => null joint.util.parseCssNumeric(1.1); // => { value: 1.1, unit: '' } joint.util.parseCssNumeric('1.1'); // => { value: 1.1, unit: '' } joint.util.parseCssNumeric('1.1px'); // => { value: 1.1, unit: 'px' } joint.util.parseCssNumeric('1.1em'); // => { value: 1.1, unit: 'em' }</code></pre> <pre class="docs-method-signature"><code>util.parseCssNumeric(value, restrictUnits)</code></pre> <p>Parse the provided value and only accept it if its unit is part of the <code>restrictUnits</code> parameter; otherwise return <code>null</code>.</p> <p>The <code>restrictUnits</code> parameter can be a string or an array of strings. If you provide an empty string, that means you are expecting <code>value</code> to have no unit. Providing an empty array always returns <code>null</code>. Examples:</p> <pre><code>joint.util.parseCssNumeric(1.1, ''); // => { value: 1.1, unit: '' }) joint.util.parseCssNumeric('1.1', ''); // => { value: 1.1, unit: '' }) joint.util.parseCssNumeric('1.1px', ''); // => null joint.util.parseCssNumeric('1.1px', 'px'); // => { value: 1.1, unit: 'px' }); joint.util.parseCssNumeric('1.1px', 'em'); // => null joint.util.parseCssNumeric(1.1, []); // => null joint.util.parseCssNumeric('1.1', []); // => null joint.util.parseCssNumeric('1.1px', []); // => null joint.util.parseCssNumeric(1.1, ['']); // => { value: 1.1, unit: '' }) joint.util.parseCssNumeric('1.1', ['']); // => { value: 1.1, unit: '' }) joint.util.parseCssNumeric('1.1px', ['px']); // => { value: 1.1, unit: 'px' }); joint.util.parseCssNumeric('1.1px', ['em']); // => null joint.util.parseCssNumeric(1.1, ['', 'px']); // => { value: 1.1, unit: '' }) joint.util.parseCssNumeric('1.1', ['', 'px']); // => { value: 1.1, unit: '' }) joint.util.parseCssNumeric('1.1px', ['', 'px']); // => { value: 1.1, unit: 'px' }) joint.util.parseCssNumeric('1.1em', ['', 'px']); // => null</code></pre>