utils.ts

Overview

The utils.ts file provides utility functions and constants related to generating and managing image resource names used throughout the application. Its primary purpose is to create structured arrays of image path strings following a consistent naming pattern. This facilitates easy referencing and organization of images by type (e.g., books, manuals, presentations) within the system.

Specifically, it exports an ImageMap object that maps various resource categories to arrays of image path strings generated dynamically via the helper function getImageName.


Detailed Explanation

Function: getImageName

const getImageName = (prefix: string, length: number) => 
  new Array(length)
    .fill(0)
    .map((x, idx) => `chunk-method/${prefix}-0${idx + 1}`);

Constant: ImageMap

export const ImageMap = {
  book: getImageName('book', 4),
  laws: getImageName('law', 2),
  manual: getImageName('manual', 4),
  picture: getImageName('media', 2),
  naive: getImageName('naive', 2),
  paper: getImageName('paper', 2),
  presentation: getImageName('presentation', 2),
  qa: getImageName('qa', 2),
  resume: getImageName('resume', 2),
  table: getImageName('table', 2),
  one: getImageName('one', 2),
  knowledge_graph: getImageName('knowledge-graph', 2),
  tag: getImageName('tag', 2),
};

Important Implementation Details and Algorithms


Interaction with Other Parts of the System


Diagram: Function and Constant Flowchart

flowchart TD
    A[getImageName(prefix, length)]
    B[ImageMap object]

    A --> B

    subgraph ImageMap Keys
      book["book: getImageName('book',4)"]
      laws["laws: getImageName('law',2)"]
      manual["manual: getImageName('manual',4)"]
      picture["picture: getImageName('media',2)"]
      naive["naive: getImageName('naive',2)"]
      paper["paper: getImageName('paper',2)"]
      presentation["presentation: getImageName('presentation',2)"]
      qa["qa: getImageName('qa',2)"]
      resume["resume: getImageName('resume',2)"]
      table["table: getImageName('table',2)"]
      one["one: getImageName('one',2)"]
      knowledge_graph["knowledge_graph: getImageName('knowledge-graph',2)"]
      tag["tag: getImageName('tag',2)"]
    end

    B --> book
    B --> laws
    B --> manual
    B --> picture
    B --> naive
    B --> paper
    B --> presentation
    B --> qa
    B --> resume
    B --> table
    B --> one
    B --> knowledge_graph
    B --> tag

Summary