Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Remove content-type dependency #211

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,5 @@
"url": "https://github.com/unsplash/unsplash-js/issues"
},
"homepage": "https://github.com/unsplash/unsplash-js#readme",
"dependencies": {
"@types/content-type": "^1.1.3",
"content-type": "^1.0.4"
}
"dependencies": {}
}
2 changes: 2 additions & 0 deletions src/helpers/fp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable no-redeclare */

import { isDefined } from './typescript';

/** Takes a dictionary containing nullish values and returns a dictionary of all the defined
Expand Down
16 changes: 7 additions & 9 deletions src/helpers/json.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import * as ContentTypeHelpers from 'content-type';
import { DecodingError } from './errors';
import { AnyJson, isDefined } from './typescript';

const CONTENT_TYPE_RESPONSE_HEADER = 'content-type';
const CONTENT_TYPE_JSON = 'application/json';
const checkIsJsonResponse = (response: Response) => {
const contentTypeHeader = response.headers.get(CONTENT_TYPE_RESPONSE_HEADER);
// Regex from: https://stackoverflow.com/a/73613161
const isJSON = (contentType: string): boolean =>
/application\/[^+]*[+]?(json);?.*/.test(contentType);

return (
isDefined(contentTypeHeader) &&
ContentTypeHelpers.parse(contentTypeHeader).type === CONTENT_TYPE_JSON
);
const checkIsJsonResponse = (response: Response): boolean => {
const contentTypeHeader = response.headers.get('content-type');

return isDefined(contentTypeHeader) && isJSON(contentTypeHeader);
};

/**
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1207,11 +1207,6 @@
dependencies:
"@babel/types" "^7.3.0"

"@types/content-type@^1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/content-type/-/content-type-1.1.3.tgz#3688bd77fc12f935548eef102a4e34c512b03a07"
integrity sha512-pv8VcFrZ3fN93L4rTNIbbUzdkzjEyVMp5mPVjsFfOYTDOZMZiZ8P1dhu+kEv3faYyKzZgLlSvnyQNFg+p/v5ug==

"@types/estree@*":
version "0.0.45"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.45.tgz#e9387572998e5ecdac221950dab3e8c3b16af884"
Expand Down Expand Up @@ -2623,7 +2618,7 @@ content-disposition@0.5.3:
dependencies:
safe-buffer "5.1.2"

content-type@^1.0.4, content-type@~1.0.4:
content-type@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
integrity sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==
Expand Down
Loading