Skip to content

Commit

Permalink
Merge pull request #27794 from software-mansion-labs/ts-migration/Rec…
Browse files Browse the repository at this point in the history
…eiptUtils

[TS migration] Migrate 'ReceiptUtils.js' lib to TypeScript
  • Loading branch information
AndrewGable committed Sep 27, 2023
2 parents cf9ad20 + 5fa86e9 commit f596e35
Showing 1 changed file with 16 additions and 5 deletions.
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

0 comments on commit f596e35

Please sign in to comment.