(input: string)
| 285 | const rgbUnits = {'%': 100}; |
| 286 | |
| 287 | export function getRGBValues(input: string): number[] | null { |
| 288 | const CHAR_CODE_0 = 48; |
| 289 | const length = input.length; |
| 290 | let i = 0; |
| 291 | let digitsCount = 0; |
| 292 | let digitSequence = false; |
| 293 | let floatDigitsCount = -1; |
| 294 | let delimiter = C_SPACE; |
| 295 | let channel = -1; |
| 296 | let result: number[] | null = null; |
| 297 | while (i < length) { |
| 298 | const c = input.charCodeAt(i); |
| 299 | if ((c >= C_0 && c <= C_9) || c === C_DOT) { |
| 300 | if (!digitSequence) { |
| 301 | digitSequence = true; |
| 302 | digitsCount = 0; |
| 303 | floatDigitsCount = -1; |
| 304 | channel++; |
| 305 | if (channel === 3 && result) { |
| 306 | result[3] = 0; |
| 307 | } |
| 308 | if (channel > 3) { |
| 309 | return null; |
| 310 | } |
| 311 | } |
| 312 | if (c === C_DOT) { |
| 313 | if (floatDigitsCount > 0) { |
| 314 | return null; |
| 315 | } |
| 316 | floatDigitsCount = 0; |
| 317 | } else { |
| 318 | const d = c - CHAR_CODE_0; |
| 319 | if (!result) { |
| 320 | result = [0, 0, 0, 1]; |
| 321 | } |
| 322 | if (floatDigitsCount > -1) { |
| 323 | floatDigitsCount++; |
| 324 | result[channel] += d / (10 ** floatDigitsCount); |
| 325 | } else { |
| 326 | digitsCount++; |
| 327 | if (digitsCount > 3) { |
| 328 | return null; |
| 329 | } |
| 330 | result[channel] = result[channel] * 10 + d; |
| 331 | } |
| 332 | } |
| 333 | } else if (c === C_PERCENT) { |
| 334 | if (channel < 0 || channel > 3 || delimiter !== C_SPACE || !result) { |
| 335 | return null; |
| 336 | } |
| 337 | result[channel] = channel < 3 ? Math.round(result[channel] * 255 / 100) : (result[channel] / 100); |
| 338 | digitSequence = false; |
| 339 | } else { |
| 340 | digitSequence = false; |
| 341 | if (c === C_SPACE) { |
| 342 | if (channel === 0) { |
| 343 | delimiter = c; |
| 344 | } |
no outgoing calls
no test coverage detected