Resource class for handling file and URL paths.

Constructors

  • Creates a new Resource instance.

    Parameters

    • path: string

      The file or URL path.

    Returns Resource

Properties

path: string

The file or URL path.

Accessors

  • get ext(): string

    Gets the file extension of the file or URL.

    Returns string

    The file extension of the file or URL.

  • get isUrl(): boolean

    Checks if the path is a valid URL.

    Returns boolean

    True if the path is a valid URL, false otherwise.

  • get name(): string

    Gets the name of the file or URL.

    Returns string

    The name of the file or URL.

  • get parent(): Resource

    Gets the parent directory of the file or URL.

    Returns Resource

    The parent directory of the file or URL.

  • get url(): URL

    Creates a URL object from the Resource.

    Returns URL

    A URL object representing the Resource. Will be a file URL if the path is not a valid URL.

Methods

  • Compares the paths of two Resource instances and returns the differences.

    Parameters

    • other: Resource

      The other Resource instance to compare with.

    Returns string[]

    An array of segments that are different between the two paths.

  • Checks if the file or URL exists.

    Returns Promise<boolean>

    True if the file or URL exists, false otherwise.

  • Fetches the contents of the file or URL.

    Returns Promise<string>

    The contents of file the Resource points to.

  • Joins the Resource with other segments to create a new Resource.

    Parameters

    • ...segments: string[]

      The segments to join with the Resource.

    Returns Resource

    A new Resource instance with the joined path.

  • Splits the Resource path into an array of segments.

    Returns string[]

    An array of segments in the path, in order of occurrence.

  • Returns the string representation of the Resource instance.

    Returns string

    The path of the Resource.

  • Creates a new Resource instance with the current working directory.

    Returns Resource

    A new Resource instance with the current working directory.