pathTo function

String pathTo(
  1. String path
)

Normalizes and joins a given path with the application base directory path. This function normalizes the input path, formats it as a URI, applies additional path normalization, and finally joins it with the application directory path obtained from pathApp. Example usage:

String fullPath = pathTo('assets/images');

Implementation

String pathTo(String path) {
  path = p.normalize(path);

  // If path is absolute and starts with appPath, make it relative
  var normalizedAppPath = p.normalize(pathApp);
  if (p.isAbsolute(path) && path.startsWith(normalizedAppPath)) {
    path = path.substring(normalizedAppPath.length);
  }

  path = pathNorm(path);
  return p.normalize(p.join(pathApp, path));
}