本文整理匯總了TypeScript中path.posix.isAbsolute方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript posix.isAbsolute方法的具體用法?TypeScript posix.isAbsolute怎麽用?TypeScript posix.isAbsolute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類path.posix
的用法示例。
在下文中一共展示了posix.isAbsolute方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: function
export default function() {
// These testcases are specific to one uncommon behaviour in path module. Few
// of the functions in path module, treat '' strings as current working
// directory. This test makes sure that the behaviour is intact between commits.
// See: https://github.com/nodejs/node/pull/2106
var pwd = process.cwd();
// join will internally ignore all the zero-length strings and it will return
// '.' if the joined string is a zero-length string.
assert.equal(path.posix.join(''), '.');
assert.equal(path.posix.join('', ''), '.');
assert.equal(path.join(pwd), pwd);
assert.equal(path.join(pwd, ''), pwd);
// normalize will return '.' if the input is a zero-length string
assert.equal(path.posix.normalize(''), '.');
assert.equal(path.normalize(pwd), pwd);
// Since '' is not a valid path in any of the common environments, return false
assert.equal(path.posix.isAbsolute(''), false);
// resolve, internally ignores all the zero-length strings and returns the
// current working directory
assert.equal(path.resolve(''), pwd);
assert.equal(path.resolve('', ''), pwd);
// relative, internally calls resolve. So, '' is actually the current directory
assert.equal(path.relative('', pwd), '');
assert.equal(path.relative(pwd, ''), '');
assert.equal(path.relative(pwd, pwd), '');
};
示例2: formatImportUrl
/**
* Format an import from the current document to the given JS URL. If an
* original HTML import URL is given, attempt to match the format of that
* import URL as much as possible. For example, if the original import URL was
* an absolute path, return an absolute path as well.
*
* TODO(fks): Make this run on Windows/Non-Unix systems (#236)
*/
private formatImportUrl(
toUrl: ConvertedDocumentUrl, originalHtmlImportUrl?: string,
forcePath = false): string {
// Return an absolute URL path if the original HTML import was absolute.
// TODO(fks) 11-06-2017: Still return true absolute paths when using
// bare/named imports?
if (originalHtmlImportUrl && path.posix.isAbsolute(originalHtmlImportUrl)) {
const formattedUrl = '/' + toUrl.slice('./'.length);
return this.webcomponentsLiteToBundle(formattedUrl);
}
// If the import is contained within a single package (internal), return
// a path-based import.
if (this.urlHandler.isImportInternal(this.convertedUrl, toUrl)) {
return this.urlHandler.getPathImportUrl(this.convertedUrl, toUrl);
}
// Otherwise, return the external import URL formatted for names or paths.
if (forcePath || this.conversionSettings.npmImportStyle === 'path') {
const formattedUrl =
this.urlHandler.getPathImportUrl(this.convertedUrl, toUrl);
return this.webcomponentsLiteToBundle(formattedUrl);
} else {
const formattedUrl = this.urlHandler.getNameImportUrl(toUrl);
return this.webcomponentsLiteToBundle(formattedUrl);
}
}
示例3: resolve
resolve(url: string): string {
let urlObject = parseUrl(url);
let pathname = pathlib.normalize(decodeURIComponent(urlObject.pathname));
if (!this._isValid(urlObject, pathname)) {
throw new Error(`Invalid URL ${url}`);
}
// If the path points to a sibling directory, resolve it to the
// component directory
if (pathname.startsWith('../')) {
pathname = pathlib.join(this.componentDir,pathname.substring(3));
}
// make all paths relative to the root directory
if (pathlib.isAbsolute(pathname)) {
pathname = pathname.substring(1);
}
return pathname;
}
示例4: shouldMapPaths
private shouldMapPaths(remotePath: string): boolean {
// Map paths only if localRoot/remoteRoot are set, and the remote path is absolute on some system
return !!this._localRoot && !!this._remoteRoot && (path.posix.isAbsolute(remotePath) || path.win32.isAbsolute(remotePath) || utils.isFileUrl(remotePath));
}