All files / src/shared/lib/helpers assets.ts

81.25% Statements 13/16
50% Branches 1/2
40% Functions 2/5
72.73% Lines 8/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 4743x                                     43x 65x             43x         56x     43x       43x       43x      
import Path from "path";
 
export type Asset = {
  filename: string;
  plugin?: string;
  _v?: number;
};
 
export type AssetType =
  | "avatars"
  | "backgrounds"
  | "emotes"
  | "tilesets"
  | "fonts"
  | "music"
  | "sounds"
  | "sprites"
  | "ui";
 
export const assetPath = (assetType: AssetType, asset: Asset) => {
  return (
    asset.plugin
      ? Path.join("plugins", asset.plugin, assetType, asset.filename)
      : Path.join("assets", assetType, asset.filename)
  ).replace(/\\/g, "/");
};
 
export const assetFilename = (
  projectRoot: string,
  assetType: AssetType,
  asset: Asset
) => {
  return Path.join(projectRoot, assetPath(assetType, asset));
};
 
export const assetURL = (assetType: AssetType, asset: Asset) => {
  return `gbs://project/${assetPath(assetType, asset)}?_v=${asset._v}`;
};
 
export const assetURLStyleProp = (assetType: AssetType, asset: Asset) => {
  return `url("gbs://project/${assetPath(assetType, asset)}?_v=${asset._v}")`;
};
 
export const assetNameFromFilename = (filename: string) => {
  return filename.replace(/\.[^.]*$/, "");
};