| 1405 | } |
| 1406 | |
| 1407 | function parseString(input, valueFormatFn) { |
| 1408 | const regex = /(\w+):\s*((?:(?!\n\w+:).)*)/g; |
| 1409 | const matches = {}; |
| 1410 | |
| 1411 | let match; |
| 1412 | while ((match = regex.exec(input)) !== null) { |
| 1413 | const [, key, value] = match; |
| 1414 | const _key = key.trim(); |
| 1415 | if (!_key || matches[_key]) { |
| 1416 | continue; |
| 1417 | } |
| 1418 | |
| 1419 | let _value = value.trim(); |
| 1420 | |
| 1421 | try { |
| 1422 | _value = valueFormatFn ? valueFormatFn(_value) : _value; |
| 1423 | const jsonValue = JSON.parse(_value); |
| 1424 | matches[_key] = jsonValue; |
| 1425 | } catch (error) { |
| 1426 | matches[_key] = _value; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | return matches; |
| 1431 | } |
| 1432 | |
| 1433 | function parseHeaders(headers) { |
| 1434 | if (!headers) return {}; |