utils.d.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Normalises alias mappings, ensuring that more specific aliases are resolved before less specific ones.
  3. * This function also ensures that aliases do not resolve to themselves cyclically.
  4. *
  5. * @param _aliases - A set of alias mappings where each key is an alias and its value is the actual path it points to.
  6. * @returns a set of normalised alias mappings.
  7. */
  8. declare function normalizeAliases(_aliases: Record<string, string>): Record<string, string>;
  9. /**
  10. * Resolves a path string to its alias if applicable, otherwise returns the original path.
  11. * This function normalises the path, resolves the alias and then joins it to the alias target if necessary.
  12. *
  13. * @param path - The path string to resolve.
  14. * @param aliases - A set of alias mappings to use for resolution.
  15. * @returns the resolved path as a string.
  16. */
  17. declare function resolveAlias(path: string, aliases: Record<string, string>): string;
  18. /**
  19. * Resolves a path string to its possible alias.
  20. *
  21. * Returns an array of possible alias resolutions (could be empty), sorted by specificity (longest first).
  22. */
  23. declare function reverseResolveAlias(path: string, aliases: Record<string, string>): string[];
  24. /**
  25. * Extracts the filename from a given path, excluding any directory paths and the file extension.
  26. *
  27. * @param path - The full path of the file from which to extract the filename.
  28. * @returns the filename without the extension, or `undefined` if the filename cannot be extracted.
  29. */
  30. declare function filename(path: string): string | undefined;
  31. export { filename, normalizeAliases, resolveAlias, reverseResolveAlias };