Skip to main content

Editor.Model.SourcePath

Class

Represents a file path within a Lens Studio project, combining a root-relative path with a source root directory.

Index

Example

const sp = new Editor.Model.SourcePath(
new Editor.Path('Textures/logo.png'),
Editor.Model.SourceRootDirectory.Assets
);

console.log(`toString: ${sp.toString()}`);
console.log(`extension: ${sp.extension}`);
console.log(`fileName: ${sp.fileName}`);
console.log(`fileNameBase: ${sp.fileNameBase}`);
console.log(`isEmpty: ${sp.isEmpty}`);
console.log(`parent: ${sp.parent}`);
console.log(`relativeToProject: ${sp.relativeToProject}`);
console.log(`relativeToRoot: ${sp.relativeToRoot}`);
console.log(`rootDirectory: ${sp.rootDirectory}`);

console.log(`hasExtension('.png'): ${sp.hasExtension('.png')}`);
console.log(`hasExtension('.jpg'): ${sp.hasExtension('.jpg')}`);

const replaced = sp.replaceFileNameBase('icon');
console.log(`After replaceFileNameBase('icon'): ${replaced.toString()}`);

Constructors

Constructor

new SourcePath(relativeToRoot, rootDirectory): SourcePath

Constructs a SourcePath specifying a relative path and root directory within the asset file system.

Parameters

ParameterType
relativeToRootPath
rootDirectorySourceRootDirectory

Returns

SourcePath

Properties

extension

readonly extension: string

File extension of the path, including the leading dot.


fileName

readonly fileName: Path

File name portion of the path as an Editor.Path.


fileNameBase

readonly fileNameBase: string

File name without extension.


isEmpty

readonly isEmpty: boolean

True if the path is empty or unset.


parent

readonly parent: SourcePath

Parent directory of the path as a SourcePath.


relativeToProject

readonly relativeToProject: Path

Path relative to the project root.


relativeToRoot

readonly relativeToRoot: Path

Path relative to the source root directory.


rootDirectory

readonly rootDirectory: Path

Source root directory this path is anchored to.

Methods

hasExtension()

hasExtension(extension): boolean

Returns true if the path's file extension matches the given extension string.

Parameters

ParameterType
extensionstring

Returns

boolean


replaceFileNameBase()

replaceFileNameBase(newBaseName): SourcePath

Returns a new SourcePath with the file name base replaced by the given string.

Parameters

ParameterType
newBaseNamestring

Returns

SourcePath


toString()

toString(): string

Returns the full path as a string.

Returns

string