本文整理汇总了TypeScript中vs/base/common/paths.basename函数的典型用法代码示例。如果您正苦于以下问题:TypeScript basename函数的具体用法?TypeScript basename怎么用?TypeScript basename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了basename函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: resolve
resolve(variable: Variable): string {
const { name } = variable;
if (name === 'TM_FILENAME') {
return basename(this._model.uri.fsPath);
} else if (name === 'TM_FILENAME_BASE') {
const name = basename(this._model.uri.fsPath);
const idx = name.lastIndexOf('.');
if (idx <= 0) {
return name;
} else {
return name.slice(0, idx);
}
} else if (name === 'TM_DIRECTORY') {
const dir = dirname(this._model.uri.fsPath);
return dir !== '.' ? dir : '';
} else if (name === 'TM_FILEPATH') {
return this._model.uri.fsPath;
}
return undefined;
}
开发者ID:servicesgpr,项目名称:vscode,代码行数:26,代码来源:snippetVariables.ts
示例2: resolve
resolve(name: string): string {
if (name === 'SELECTION' || name === 'TM_SELECTED_TEXT') {
return this._model.getValueInRange(this._selection);
} else if (name === 'TM_CURRENT_LINE') {
return this._model.getLineContent(this._selection.positionLineNumber);
} else if (name === 'TM_CURRENT_WORD') {
const info = this._model.getWordAtPosition({
lineNumber: this._selection.positionLineNumber,
column: this._selection.positionColumn
});
return info ? info.word : '';
} else if (name === 'TM_LINE_INDEX') {
return String(this._selection.positionLineNumber - 1);
} else if (name === 'TM_LINE_NUMBER') {
return String(this._selection.positionLineNumber);
} else if (name === 'TM_FILENAME') {
return basename(this._model.uri.fsPath);
} else if (name === 'TM_DIRECTORY') {
const dir = dirname(this._model.uri.fsPath);
return dir !== '.' ? dir : '';
} else if (name === 'TM_FILEPATH') {
return this._model.uri.fsPath;
} else {
return undefined;
}
}
开发者ID:hungys,项目名称:vscode,代码行数:34,代码来源:snippetVariables.ts
示例3: guessMimeTypes
export function guessMimeTypes(path: string, firstLine?: string): string[] {
if (!path) {
return [MIME_UNKNOWN];
}
path = path.toLowerCase();
const filename = paths.basename(path);
// 1.) User configured mappings have highest priority
const configuredMime = guessMimeTypeByPath(path, filename, userRegisteredAssociations);
if (configuredMime) {
return [configuredMime, MIME_TEXT];
}
// 2.) Registered mappings have middle priority
const registeredMime = guessMimeTypeByPath(path, filename, nonUserRegisteredAssociations);
if (registeredMime) {
return [registeredMime, MIME_TEXT];
}
// 3.) Firstline has lowest priority
if (firstLine) {
const firstlineMime = guessMimeTypeByFirstline(firstLine);
if (firstlineMime) {
return [firstlineMime, MIME_TEXT];
}
}
return [MIME_UNKNOWN];
}
开发者ID:costincaraivan,项目名称:vscode,代码行数:30,代码来源:mime.ts
示例4: getWorkspaceLabel
export function getWorkspaceLabel(workspace: (IWorkspaceIdentifier | ISingleFolderWorkspaceIdentifier), environmentService: IEnvironmentService, uriDisplayService: IUriDisplayService, options?: { verbose: boolean }): string {
// Workspace: Single Folder
if (isSingleFolderWorkspaceIdentifier(workspace)) {
// Folder on disk
if (workspace.scheme === Schemas.file) {
return options && options.verbose ? uriDisplayService.getLabel(workspace) : getBaseLabel(workspace);
}
// Remote folder
return options && options.verbose ? uriDisplayService.getLabel(workspace) : `${getBaseLabel(workspace)} (${workspace.scheme})`;
}
// Workspace: Untitled
if (isParent(workspace.configPath, environmentService.workspacesHome, !isLinux /* ignore case */)) {
return localize('untitledWorkspace', "Untitled (Workspace)");
}
// Workspace: Saved
const filename = basename(workspace.configPath);
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
if (options && options.verbose) {
return localize('workspaceNameVerbose', "{0} (Workspace)", uriDisplayService.getLabel(URI.file(join(dirname(workspace.configPath), workspaceName))));
}
return localize('workspaceName', "{0} (Workspace)", workspaceName);
}
开发者ID:burhandodhy,项目名称:azuredatastudio,代码行数:27,代码来源:workspaces.ts
示例5: getWorkspaceLabel
export function getWorkspaceLabel(environmentService: IEnvironmentService, workspace: IWorkspaceIdentifier): string {
if (isParent(workspace.configPath, environmentService.workspacesHome, !isLinux /* ignore case */)) {
return localize('untitledWorkspace', "Untitled Workspace");
}
const filename = basename(workspace.configPath);
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
return localize('workspaceName', "{0} (Workspace)", workspaceName);
}
开发者ID:naturtle,项目名称:vscode,代码行数:10,代码来源:workspaces.ts
示例6: getSettingsTargetName
export function getSettingsTargetName(target: ConfigurationTarget, resource: URI, workspaceContextService: IWorkspaceContextService): string {
switch (target) {
case ConfigurationTarget.USER:
return localize('userSettingsTarget', "User Settings");
case ConfigurationTarget.WORKSPACE:
return localize('workspaceSettingsTarget', "Workspace Settings");
case ConfigurationTarget.FOLDER:
const root = workspaceContextService.getRoot(resource);
return root ? paths.basename(root.fsPath) : '';
}
}
开发者ID:armanio123,项目名称:vscode,代码行数:11,代码来源:preferences.ts
示例7: getDragLabel
public getDragLabel(tree: _.ITree, elements: any[]): string {
if (elements.length > 1) {
return String(elements.length);
}
const resource = this.toResource(elements[0]);
if (resource) {
return basename(resource.fsPath);
}
return void 0;
}
开发者ID:AlexxNica,项目名称:sqlopsstudio,代码行数:12,代码来源:treeDnd.ts
示例8: getSimpleWorkspaceLabel
export function getSimpleWorkspaceLabel(workspace: IWorkspaceIdentifier | URI, workspaceHome: string): string {
if (isSingleFolderWorkspaceIdentifier(workspace)) {
return resourceBasename(workspace);
}
// Workspace: Untitled
if (isParent(workspace.configPath, workspaceHome, !isLinux /* ignore case */)) {
return localize('untitledWorkspace', "Untitled (Workspace)");
}
const filename = basename(workspace.configPath);
const workspaceName = filename.substr(0, filename.length - WORKSPACE_EXTENSION.length - 1);
return localize('workspaceName', "{0} (Workspace)", workspaceName);
}
开发者ID:VishalMadhvani,项目名称:vscode,代码行数:13,代码来源:label.ts
示例9: getPathLabel
export function getPathLabel(resource: URI | string, userHomeProvider: IUserHomeProvider, rootProvider?: IWorkspaceFolderProvider): string {
if (!resource) {
return null;
}
if (typeof resource === 'string') {
resource = URI.file(resource);
}
// return early if we can resolve a relative path label from the root
const baseResource = rootProvider ? rootProvider.getWorkspaceFolder(resource) : null;
if (baseResource) {
const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1;
let pathLabel: string;
if (isEqual(baseResource.uri, resource, !isLinux)) {
pathLabel = ''; // no label if paths are identical
} else {
pathLabel = normalize(ltrim(resource.path.substr(baseResource.uri.path.length), sep), true);
}
if (hasMultipleRoots) {
const rootName = (baseResource && baseResource.name) ? baseResource.name : pathsBasename(baseResource.uri.fsPath);
pathLabel = pathLabel ? (rootName + ' ⢠' + pathLabel) : rootName; // always show root basename if there are multiple
}
return pathLabel;
}
// return if the resource is neither file:// nor untitled:// and no baseResource was provided
if (resource.scheme !== Schemas.file && resource.scheme !== Schemas.untitled) {
return resource.with({ query: null, fragment: null }).toString(true);
}
// convert c:\something => C:\something
if (hasDriveLetter(resource.fsPath)) {
return normalize(normalizeDriveLetter(resource.fsPath), true);
}
// normalize and tildify (macOS, Linux only)
let res = normalize(resource.fsPath, true);
if (!isWindows && userHomeProvider) {
res = tildify(res, userHomeProvider.userHome);
}
return res;
}
开发者ID:developers23,项目名称:vscode,代码行数:47,代码来源:labels.ts
示例10: getPathLabel
export function getPathLabel(resource: URI | string, rootProvider?: IWorkspaceFolderProvider, userHomeProvider?: IUserHomeProvider): string {
if (!resource) {
return null;
}
if (typeof resource === 'string') {
resource = URI.file(resource);
}
if (resource.scheme !== 'file' && resource.scheme !== 'untitled') {
return resource.authority + resource.path;
}
// return early if we can resolve a relative path label from the root
const baseResource = rootProvider ? rootProvider.getWorkspaceFolder(resource) : null;
if (baseResource) {
const hasMultipleRoots = rootProvider.getWorkspace().folders.length > 1;
let pathLabel: string;
if (isEqual(baseResource.uri.fsPath, resource.fsPath, !platform.isLinux /* ignorecase */)) {
pathLabel = ''; // no label if pathes are identical
} else {
pathLabel = normalize(ltrim(resource.fsPath.substr(baseResource.uri.fsPath.length), nativeSep), true);
}
if (hasMultipleRoots) {
const rootName = pathsBasename(baseResource.uri.fsPath);
pathLabel = pathLabel ? join(rootName, pathLabel) : rootName; // always show root basename if there are multiple
}
return pathLabel;
}
// convert c:\something => C:\something
if (hasDriveLetter(resource.fsPath)) {
return normalize(normalizeDriveLetter(resource.fsPath), true);
}
// normalize and tildify (macOS, Linux only)
let res = normalize(resource.fsPath, true);
if (!platform.isWindows && userHomeProvider) {
res = tildify(res, userHomeProvider.userHome);
}
return res;
}
开发者ID:servicesgpr,项目名称:vscode,代码行数:46,代码来源:labels.ts
注:本文中的vs/base/common/paths.basename函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论