Skip to content

Commit

Permalink
feat(client): simplify isBlob function
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanshatford committed Mar 30, 2024
1 parent 1f8f651 commit 3d18aae
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 112 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-snakes-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hey-api/openapi-ts": minor
---

Check value instanceof Blob when using isBlob
4 changes: 2 additions & 2 deletions package-lock.json

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

12 changes: 1 addition & 11 deletions src/templates/core/functions/isBlob.hbs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};
12 changes: 1 addition & 11 deletions test/__snapshots__/v2/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_angular/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_axios/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_client/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_enums_typescript/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_node/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_options/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down
12 changes: 1 addition & 11 deletions test/__snapshots__/v3_xhr/core/request.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,7 @@ export const isStringWithValue = (value: unknown): value is string => {
};

export const isBlob = (value: any): value is Blob => {
return (
value !== null &&
typeof value === 'object' &&
typeof value.type === 'string' &&
typeof value.stream === 'function' &&
typeof value.arrayBuffer === 'function' &&
typeof value.constructor === 'function' &&
typeof value.constructor.name === 'string' &&
/^(Blob|File)$/.test(value.constructor.name) &&
/^(Blob|File)$/.test(value[Symbol.toStringTag])
);
return value instanceof Blob;
};

export const isFormData = (value: unknown): value is FormData => {
Expand Down

0 comments on commit 3d18aae

Please sign in to comment.