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