Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'ReceiptUtils.js' lib to TypeScript #27794

Merged
Merged
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
21 changes: 16 additions & 5 deletions src/libs/ReceiptUtils.js → src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import Str from 'expensify-common/lib/str';
import {ImageSourcePropType} from 'react-native';
import * as FileUtils from './fileDownload/FileUtils';
import CONST from '../CONST';
import ReceiptHTML from '../../assets/images/receipt-html.png';
import ReceiptDoc from '../../assets/images/receipt-doc.png';
import ReceiptGeneric from '../../assets/images/receipt-generic.png';
import ReceiptSVG from '../../assets/images/receipt-svg.png';

type ThumbnailAndImageURI = {
image: ImageSourcePropType | string;
thumbnail: string | null;
};

type FileNameAndExtension = {
fileExtension?: string;
fileName?: string;
};

/**
* Grab the appropriate receipt image and thumbnail URIs based on file type
*
* @param {String} path URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg
* @param {String} filename of uploaded image or last part of remote URI
* @returns {Object}
* @param path URI to image, i.e. blob:new.expensify.com/9ef3a018-4067-47c6-b29f-5f1bd35f213d or expensify.com/receipts/w_e616108497ef940b7210ec6beb5a462d01a878f4.jpg
* @param filename of uploaded image or last part of remote URI
*/
function getThumbnailAndImageURIs(path, filename) {
function getThumbnailAndImageURIs(path: string, filename: string): ThumbnailAndImageURI {
const isReceiptImage = Str.isImage(filename);

// For local files, we won't have a thumbnail yet
Expand All @@ -25,7 +35,7 @@ function getThumbnailAndImageURIs(path, filename) {
return {thumbnail: `${path}.1024.jpg`, image: path};
}

const {fileExtension} = FileUtils.splitExtensionFromFileName(filename);
const {fileExtension} = FileUtils.splitExtensionFromFileName(filename) as FileNameAndExtension;
let image = ReceiptGeneric;
if (fileExtension === CONST.IOU.FILE_TYPES.HTML) {
image = ReceiptHTML;
Expand All @@ -38,6 +48,7 @@ function getThumbnailAndImageURIs(path, filename) {
if (fileExtension === CONST.IOU.FILE_TYPES.SVG) {
image = ReceiptSVG;
}

return {thumbnail: null, image};
}

Expand Down