本文整理匯總了TypeScript中vs/base/common/paths.dirname函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript dirname函數的具體用法?TypeScript dirname怎麽用?TypeScript dirname使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了dirname函數的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: dirname
export function dirname(resource: URI): URI | null {
if (resource.scheme === Schemas.file) {
return URI.file(paths.dirname(fsPath(resource)));
}
let dirname = paths.dirname(resource.path, '/');
if (resource.authority && dirname.length && dirname.charCodeAt(0) !== CharCode.Slash) {
return null; // If a URI contains an authority component, then the path component must either be empty or begin with a CharCode.Slash ("/") character
}
return resource.with({
path: dirname
});
}
示例2: 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;
}
示例3: 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;
}
}
示例4: assertDirname
function assertDirname(path: string, expected: string, win = false) {
const actual = paths.dirname(path, win ? '\\' : '/');
if (actual !== expected) {
assert.fail(`${path}: expected: ${expected}, ours: ${actual}`);
}
}
示例5: save
export function save(file: string, content: string): any {
mkdirp(dirname(file)).then(() => {
return writeFile(file, content, 'ascii');
}, err => {
//
});
}
示例6: createPath
export function createPath(parent: string, fileName: string): string {
var stat = fs.statSync(parent);
if (stat && !stat.isDirectory()) {
parent = dirname(parent);
}
return join(parent, fileName);
};
示例7: defaultWorkspacePath
export function defaultWorkspacePath(contextService: IWorkspaceContextService, historyService: IHistoryService, environmentService: IEnvironmentService): string {
// Check for current workspace config file first...
if (contextService.getWorkbenchState() === WorkbenchState.WORKSPACE && !isUntitledWorkspace(contextService.getWorkspace().configuration.fsPath, environmentService)) {
return dirname(contextService.getWorkspace().configuration.fsPath);
}
// ...then fallback to default folder path
return defaultFolderPath(contextService, historyService);
}
示例8: dirname
export function dirname(resource: uri): uri {
const dirname = paths.dirname(resource.path);
if (resource.authority && dirname && !paths.isAbsolute(dirname)) {
return null; // If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character
}
return resource.with({
path: dirname
});
}
示例9: defaultFilePath
export function defaultFilePath(contextService: IWorkspaceContextService, historyService: IHistoryService): string {
let candidate: URI;
// Check for last active file first...
candidate = historyService.getLastActiveFile();
// ...then for last active file root
if (!candidate) {
candidate = historyService.getLastActiveWorkspaceRoot('file');
}
return candidate ? dirname(candidate.fsPath) : void 0;
}
示例10:
handler: (accessor) => {
const historyService = accessor.get(IHistoryService);
const terminalService = accessor.get(ITerminalService);
const root = historyService.getLastActiveWorkspaceRoot(Schemas.file);
if (root) {
terminalService.openTerminal(root.fsPath);
} else {
// Opens current file's folder, if no folder is open in editor
const activeFile = historyService.getLastActiveFile();
if (activeFile) {
terminalService.openTerminal(paths.dirname(activeFile.fsPath));
}
}
}