Skip to content

Commit

Permalink
Clean up assetPathUtils code
Browse files Browse the repository at this point in the history
Summary:
Cleaning up a bunch of legacy JS (var) and removing some variable names for stuff that is just used once.

Changelog: [Internal]

Reviewed By: GijsWeterings

Differential Revision: D22627397

fbshipit-source-id: 783af84b17cbf37df3b8e2ae10bb39d50dd8180d
  • Loading branch information
cpojer authored and facebook-github-bot committed Jul 22, 2020
1 parent a77f2c4 commit 09a1120
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions Libraries/Image/assetPathUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getAndroidResourceFolderName(
if (!drawableFileTypes.has(asset.type)) {
return 'raw';
}
var suffix = getAndroidAssetSuffix(scale);
const suffix = getAndroidAssetSuffix(scale);
if (!suffix) {
throw new Error(
"Don't know which android drawable suffix to use for scale: " +
Expand All @@ -62,30 +62,25 @@ function getAndroidResourceFolderName(
JSON.stringify(androidScaleSuffix, null, '\t'),
);
}
const androidFolder = 'drawable-' + suffix;
return androidFolder;
return 'drawable-' + suffix;
}

function getAndroidResourceIdentifier(asset: PackagerAsset): string {
var folderPath = getBasePath(asset);
return (folderPath + '/' + asset.name)
return (getBasePath(asset) + '/' + asset.name)
.toLowerCase()
.replace(/\//g, '_') // Encode folder structure in file name
.replace(/([^a-z0-9_])/g, '') // Remove illegal chars
.replace(/^assets_/, ''); // Remove "assets_" prefix
}

function getBasePath(asset: PackagerAsset): string {
var basePath = asset.httpServerLocation;
if (basePath[0] === '/') {
basePath = basePath.substr(1);
}
return basePath;
const basePath = asset.httpServerLocation;
return basePath.startsWith('/') ? basePath.substr(1) : basePath;
}

module.exports = {
getAndroidAssetSuffix: getAndroidAssetSuffix,
getAndroidResourceFolderName: getAndroidResourceFolderName,
getAndroidResourceIdentifier: getAndroidResourceIdentifier,
getBasePath: getBasePath,
getAndroidAssetSuffix,
getAndroidResourceFolderName,
getAndroidResourceIdentifier,
getBasePath,
};

0 comments on commit 09a1120

Please sign in to comment.