Home Reference Source Test Repository
public class | source

PathResolver

Provides a file path resolver that is NPM module aware.

Example:

const pathResolver = new PathResolver('.', 'foo/bar.js', 'foo-bar', 'foo/bar.js');
pathResolver.importPath;            // 'foo-bar'
pathResolver.filePath;              // 'foo/bar.js'
pathResolver.resolve('./baz.js');   // 'foo/baz.js'

Constructor Summary

Public Constructor
public

constructor(rootPath: string, filePath: string, packageName: string, mainFilePath: string)

Instantiate PathResolver.

Member Summary

Public Members
public get

Gets the absolute file path.

public get

Gets the file path that is the relative path from the root dir.

public get

Gets import path that is considered package name or main file and path prefix.

Private Members
private
private
private

_packageName: NPMPackageObject

private

Method Summary

Public Methods
public

resolve(relativePath: string): string

Resolves the given file path with the data initialized in PathResolver.

public

Resolve absolute path given the file path on this file.

public

setPathData(rootPath: string, filePath: string, packageName: string, mainFilePath: string)

Sets the given path data to this PathResolver.

Private Methods
private

_slash(filePath: string): string

Converts 'back slash' to 'slash' as necessary if the OS platform is windows.

Public Constructors

public constructor(rootPath: string, filePath: string, packageName: string, mainFilePath: string) source

Instantiate PathResolver.

Params:

NameTypeAttributeDescription
rootPath string

root directory path.

filePath string

relative file path from root directory path.

packageName string
  • optional

npm package name.

mainFilePath string
  • optional

npm main file path.

Public Members

public get absolutePath: string: * source

Gets the absolute file path.

Return:

string

public get filePath: string: * source

Gets the file path that is the relative path from the root dir.

Return:

string

public get importPath: string: * source

Gets import path that is considered package name or main file and path prefix.

Return:

string

Private Members

private _filePath: string source

private _mainFilePath: string source

private _packageName: NPMPackageObject source

private _rootPath: string source

Public Methods

public resolve(relativePath: string): string source

Resolves the given file path with the data initialized in PathResolver.

Params:

NameTypeAttributeDescription
relativePath string

relative path on this file.

Return:

string

public resolveAbsolutePath(relativePath: string): string source

Resolve absolute path given the file path on this file.

Params:

NameTypeAttributeDescription
relativePath string

relative path on this file.

Return:

string

public setPathData(rootPath: string, filePath: string, packageName: string, mainFilePath: string) source

Sets the given path data to this PathResolver.

Params:

NameTypeAttributeDescription
rootPath string

root directory path.

filePath string

relative file path from root directory path.

packageName string
  • optional

npm package name.

mainFilePath string
  • optional

npm main file path.

Private Methods

private _slash(filePath: string): string source

Converts 'back slash' to 'slash' as necessary if the OS platform is windows.

Params:

NameTypeAttributeDescription
filePath string

Target file path.

Return:

string

converted path.