當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript posix.isAbsolute方法代碼示例

本文整理匯總了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), '');
};
開發者ID:diegolameira,項目名稱:codesandbox-client,代碼行數:32,代碼來源:node-path-zero-length-strings.ts

示例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);
   }
 }
開發者ID:,項目名稱:,代碼行數:33,代碼來源:

示例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;
  }
開發者ID:Polymer,項目名稱:url-loader,代碼行數:20,代碼來源:package-url-resolver.ts

示例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));
 }
開發者ID:Microsoft,項目名稱:vscode-chrome-debug-core,代碼行數:4,代碼來源:remotePathTransformer.ts


注:本文中的path.posix.isAbsolute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。