MCPcopy Create free account
hub / github.com/microsoft/SandDance / parsePosition

Function parsePosition

docs/app/js/sanddance-app.js:89482–89502  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

89480var _typeofDefault = parcelHelpers.interopDefault(_typeof);
89481var PERCENT_OR_PIXELS_REGEX = /([0-9]+\.?[0-9]*)(%|px)/;
89482function parsePosition(value) {
89483 switch((0, _typeofDefault.default)(value)){
89484 case "number":
89485 return {
89486 position: value,
89487 relative: false
89488 };
89489 case "string":
89490 var match = value.match(PERCENT_OR_PIXELS_REGEX);
89491 if (match && match.length >= 3) {
89492 var relative = match[2] === "%";
89493 var position = parseFloat(match[1]);
89494 return {
89495 position: relative ? position / 100 : position,
89496 relative: relative
89497 };
89498 }
89499 default:
89500 throw new Error("Could not parse position string ".concat(value));
89501 }
89502}
89503function getPosition(position, extent) {
89504 return position.relative ? Math.round(position.position * extent) : position.position;
89505}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected