@thingts/path - v2.0.4
    Preparing search index...

    Interface FilenameOps

    Interface defining operations on objects that have filenames

    interface FilenameOps {
        extension: string | undefined;
        stem: string | undefined;
        equals(other: string | FilenameOps): boolean;
        replaceExtension(newExt: string): this;
        replaceStem(newStem: string): this;
        toString(): string;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    extension: string | undefined

    Returns the extension of the filename including the leading dot, as a string. If the filename has no extension, returns an empty string.

    Note that if the filename starts with a dot (e.g. .gitignore), that dot is considered part of the stem. So .gitignore has extension '' and .gitignore.bak has extension .bak

    stem: string | undefined

    Returns the stem of the filename, i.e. the part before the extension. If the filename has no extension, returns the entire filename

    Note that if the filename starts with a dot (e.g. .gitignore), that dot is considered part of the stem. So .gitignore and .gitignore.bak both have stem .gitignore

    Methods

    • Replace the filename extension, keeping the stem the same. The passed string can include or omit the leading dot; if omitted, it will be added.

      Parameters

      • newExt: string

        New extension, e.g. json or .json

      Returns this

      A new instance with the filename extension replaced.

      new Filename('file.txt').replaceExtension('json') // → Filename('file.json')
      
    • Replace the filename stem, keeping the extension the same

      Parameters

      • newStem: string

      Returns this

      A new instance with the filename stem replaced.

      new Filename('index.ts').replaceStem('main') // → Filename('main.ts')