| 1134 | * @since 4.0.0 |
| 1135 | */ |
| 1136 | export function splitKeyValue<E extends string>(options?: { |
| 1137 | readonly separator?: string | undefined |
| 1138 | readonly keyValueSeparator?: string | undefined |
| 1139 | }): Getter<Record<string, string>, E> { |
| 1140 | const separator = options?.separator ?? "," |
| 1141 | const keyValueSeparator = options?.keyValueSeparator ?? "=" |
| 1142 | return transform((input) => |
| 1143 | input.split(separator).reduce((acc, pair) => { |
| 1144 | const [key, value] = pair.split(keyValueSeparator) |
| 1145 | if (key && value) { |
| 1146 | InternalRecord.assignProperty(acc, key, value) |
| 1147 | } |
| 1148 | return acc |
| 1149 | }, {} as Record<string, string>) |
| 1150 | ) |
| 1151 | } |
| 1152 | |
| 1153 | /** |
| 1154 | * Joins a record of key-value pairs into a delimited string. |