MCPcopy
hub / github.com/andremichelle/openDAW / y

Method y

packages/lib/std/src/string-mapping.ts:100–133  ·  view source on GitHub ↗
(x: string)

Source from the content-addressed store, hash-verified

98 }
99
100 y(x: string): ParseResult<number> {
101 let value = x.trim()
102 const float = parseFloat(value)
103 if (isNaN(float)) {
104 return {type: "unknown", value: value}
105 } else if (this.#unit === "%") {
106 return {
107 type: "explicit",
108 value: float / 100.0
109 }
110 } else if (value.endsWith("%")) {
111 return {
112 type: "unitValue",
113 value: this.#bipolar
114 ? clamp(float / 200.0 + 0.5, 0.0, 1.0)
115 : clamp(float / 100.0, 0.0, 1.0)
116 }
117 } else {
118 if (value.endsWith(this.#unit) && this.#unit.length > 0) {
119 // remove unit
120 value = value.slice(0, -this.#unit.length)
121 }
122 const regex = /(\d+)(\D+)/
123 const match: Nullable<RegExpExecArray> = regex.exec(value)
124 const last = match?.at(2)?.at(0)
125 if (isDefined(last)) {
126 const index: int = prefixes.indexOf(last)
127 if (index > -1) {
128 return {type: "explicit", value: float * Math.pow(10.0, (index - 4) * 3.0)}
129 }
130 }
131 return {type: "explicit", value: float}
132 }
133 }
134 x(y: number): StringResult {
135 if (Number.isNaN(y)) {
136 return {value: "💣", unit: this.#unit}

Callers

nothing calls this directly

Calls 4

clampFunction · 0.90
isDefinedFunction · 0.90
sliceMethod · 0.80
indexOfMethod · 0.80

Tested by

no test coverage detected