Skip to content

Commit

Permalink
add type to push(l)
Browse files Browse the repository at this point in the history
  • Loading branch information
anniel-stripe committed Jan 11, 2023
1 parent 9d7b051 commit c6fbd2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const multipartDataGenerator = (
let buffer = new Uint8Array(0);
const endBuffer = textEncoder.encode('\r\n');

function push(l: any): void {
function push(l: string | Uint8Array): void {
const prevBuffer = buffer;
const newBuffer =
l instanceof Uint8Array ? l : new Uint8Array(textEncoder.encode(l));
Expand All @@ -48,7 +48,7 @@ const multipartDataGenerator = (
if (Object.prototype.hasOwnProperty.call(v, 'data')) {
const typedEntry: {
name: string;
data: BufferedFile;
data: string | Uint8Array;
type: string;
} = v as any;
push(
Expand Down
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,12 @@ const utils = {
// For use in multipart requests
flattenAndStringify: (
data: MultipartRequestData
): Record<string, unknown> => {
const result: RequestData = {};
): Record<string, string | Uint8Array> => {
const result: Record<string, string | Uint8Array> = {};

const step = (obj: RequestData, prevKey: string | null): void => {
const step = (obj: MultipartRequestData, prevKey: string | null): void => {
Object.keys(obj).forEach((key) => {
// @ts-ignore
const value = obj[key];

const newKey = prevKey ? `${prevKey}[${key}]` : key;
Expand All @@ -389,7 +390,7 @@ const utils = {
!Object.prototype.hasOwnProperty.call(value, 'data')
) {
// Non-buffer non-file Objects are recursively flattened
return step(value as RequestData, newKey);
return step(value, newKey);
} else {
// Buffers and file objects are stored without modification
result[newKey] = value;
Expand Down

0 comments on commit c6fbd2a

Please sign in to comment.