当前位置: 首页>>代码示例>>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;未经允许,请勿转载。