| 163 | * @publicApi |
| 164 | */ |
| 165 | export class HttpParams { |
| 166 | private map: Map<string, string[]> | null; |
| 167 | private encoder: HttpParameterCodec; |
| 168 | private updates: Update[] | null = null; |
| 169 | private cloneFrom: HttpParams | null = null; |
| 170 | |
| 171 | constructor(options: HttpParamsOptions = {} as HttpParamsOptions) { |
| 172 | this.encoder = options.encoder || new HttpUrlEncodingCodec(); |
| 173 | if (options.fromString) { |
| 174 | if (options.fromObject) { |
| 175 | throw new RuntimeError( |
| 176 | RuntimeErrorCode.CANNOT_SPECIFY_BOTH_FROM_STRING_AND_FROM_OBJECT, |
| 177 | ngDevMode && 'Cannot specify both fromString and fromObject.', |
| 178 | ); |
| 179 | } |
| 180 | this.map = paramParser(options.fromString, this.encoder); |
| 181 | } else if (!!options.fromObject) { |
| 182 | this.map = new Map<string, string[]>(); |
| 183 | Object.keys(options.fromObject).forEach((key) => { |
| 184 | const value = (options.fromObject as any)[key]; |
| 185 | // convert the values to strings |
| 186 | const values = Array.isArray(value) ? value.map(valueToString) : [valueToString(value)]; |
| 187 | this.map!.set(key, values); |
| 188 | }); |
| 189 | } else { |
| 190 | this.map = null; |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Reports whether the body includes one or more values for a given parameter. |
| 196 | * @param param The parameter name. |
| 197 | * @returns True if the parameter has one or more values, |
| 198 | * false if it has no value or is not present. |
| 199 | */ |
| 200 | has(param: string): boolean { |
| 201 | this.init(); |
| 202 | return this.map!.has(param); |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Retrieves the first value for a parameter. |
| 207 | * @param param The parameter name. |
| 208 | * @returns The first value of the given parameter, |
| 209 | * or `null` if the parameter is not present. |
| 210 | */ |
| 211 | get(param: string): string | null { |
| 212 | this.init(); |
| 213 | const res = this.map!.get(param); |
| 214 | return !!res ? res[0] : null; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * Retrieves all values for a parameter. |
| 219 | * @param param The parameter name. |
| 220 | * @returns All values in a string array, |
| 221 | * or `null` if the parameter not present. |
| 222 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…