MCPcopy Index your code
hub / github.com/docker/getting-started / toValue

Function toValue

app/src/static/js/react-bootstrap.js:4650–4692  ·  view source on GitHub ↗

* Converts a string containing value + unit into a px value number * @function * @memberof {modifiers~offset} * @private * @argument {String} str - Value + unit string * @argument {String} measurement - `height` or `width` * @argument {Object} popperOffsets * @argument {Object} referenceOffse

(str, measurement, popperOffsets, referenceOffsets)

Source from the content-addressed store, hash-verified

4648
4649
4650function toValue(str, measurement, popperOffsets, referenceOffsets) {
4651 // separate value from unit
4652 var split = str.match(/((?:\-|\+)?\d*\.?\d*)(.*)/);
4653 var value = +split[1];
4654 var unit = split[2]; // If it's not a number it's an operator, I guess
4655
4656 if (!value) {
4657 return str;
4658 }
4659
4660 if (unit.indexOf('%') === 0) {
4661 var element = void 0;
4662
4663 switch (unit) {
4664 case '%p':
4665 element = popperOffsets;
4666 break;
4667
4668 case '%':
4669 case '%r':
4670 default:
4671 element = referenceOffsets;
4672 }
4673
4674 var rect = getClientRect(element);
4675 return rect[measurement] / 100 * value;
4676 } else if (unit === 'vh' || unit === 'vw') {
4677 // if is a vh or vw, we calculate the size based on the viewport
4678 var size = void 0;
4679
4680 if (unit === 'vh') {
4681 size = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
4682 } else {
4683 size = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
4684 }
4685
4686 return size / 100 * value;
4687 } else {
4688 // if is an explicit pixel unit, we get rid of the unit and keep the value
4689 // if is an implicit unit, it's px, and we return just the value
4690 return value;
4691 }
4692}
4693/**
4694 * Parse an `offset` string to extrapolate `x` and `y` numeric offsets.
4695 * @function

Callers 1

parseOffsetFunction · 0.85

Calls 1

getClientRectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…