Skip to content

Commit

Permalink
fix(PetitioResponse): support non-ascii json responses (#11)
Browse files Browse the repository at this point in the history
* fix(PetitioResponse): add encoding to json for non-ascii responses

* docs(PetitioResponse): document json encoding option

Co-authored-by: Nytelife26 <xtylerjrx@gmail.com>
  • Loading branch information
zero734kr and Nytelife26 authored Apr 2, 2021
1 parent d91ed7f commit d8344e4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/PetitioResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,11 @@ export class PetitioResponse {

/**
* @template T Type casting parameter for the JSON result.
* @return {*} A serialized object result parsed from the response body.
* @param {BufferEncoding} [encoding="utf8"] The encoding to use when parsing the response body.
* @return {T} A serialized object result parsed from the response body.
*/
public json<T = any>(): T {
return JSON.parse(String.fromCharCode(...this.body.toJSON().data));
public json<T = any>(encoding: BufferEncoding = "utf8"): T {
return JSON.parse(this.body.toString(encoding));
}

/**
Expand Down

0 comments on commit d8344e4

Please sign in to comment.