Skip to content

Commit

Permalink
Merge pull request #211 from unsplash/rm-content-type
Browse files Browse the repository at this point in the history
Remove content-type dependency
  • Loading branch information
samhh committed Dec 14, 2023
2 parents 8a2cb28 + 8606f32 commit 93e8d35
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
5 changes: 1 addition & 4 deletions package.json
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
@@ -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
@@ -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
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

0 comments on commit 93e8d35

Please sign in to comment.