当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript posix.normalize方法代码示例

本文整理汇总了TypeScript中path.posix.normalize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript posix.normalize方法的具体用法?TypeScript posix.normalize怎么用?TypeScript posix.normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在path.posix的用法示例。


在下文中一共展示了posix.normalize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: urlFromPath

 urlFromPath(filepath) {
   if (!filepath.startsWith(this.root)) {
     throw new Error(`file path is not in root: ${filepath} (${this.root})`);
   }
   // convert filesystem path to URL
   return path.normalize(osPath.relative(this.root, filepath));
 }
开发者ID:honzalo,项目名称:polymer-cli,代码行数:7,代码来源:bundle.ts

示例2: 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

示例3: relativeURL

export function relativeURL(base: string, url: string) {
	// 忽略 data:... 等 URI
	if (/^[\w+\-\.\+]+:(?!\/)/.test(url)) {
		return url
	}
	const baseObject = parse(base, false, true)
	const urlObject = parse(url, false, true)
	// 协议不同,只能使用绝对路径
	if (baseObject.protocol !== urlObject.protocol) {
		return format(urlObject)
	}
	// 协议相同但主机(含端口)或用户名(含密码)不同,使用省略协议的绝对路径
	if (baseObject.host !== urlObject.host || baseObject.auth !== urlObject.auth) {
		if (urlObject.slashes) {
			delete urlObject.protocol
		}
		return format(urlObject)
	}
	// 两个地址必须都是相对路径或都是绝对路径,否则只能使用绝对路径
	if (baseObject.pathname && urlObject.pathname && (baseObject.pathname.charCodeAt(0) === 47 /*/*/) !== (urlObject.pathname.charCodeAt(0) === 47 /*/*/)) {
		return format(urlObject)
	}
	// 计算地址开头的相同部分,以 `/` 为界
	base = baseObject.pathname ? posix.normalize(baseObject.pathname) : ""
	url = urlObject.pathname ? posix.normalize(urlObject.pathname) : ""
	let index = -1
	let i = 0
	for (; i < base.length && i < url.length; i++) {
		const ch1 = base.charCodeAt(i)
		const ch2 = url.charCodeAt(i)
		if (ch1 !== ch2) {
			break
		}
		if (ch1 === 47 /*/*/) {
			index = i
		}
	}
	// 重新追加不同的路径部分
	let pathname = url.substring(index + 1) || (i === base.length ? "" : ".")
	for (let i = index + 1; i < base.length; i++) {
		if (base.charCodeAt(i) === 47 /*/*/) {
			pathname = pathname === "." ? "../" : `../${pathname}`
		}
	}
	return `${pathname}${urlObject.search || ""}${urlObject.hash || ""}`
}
开发者ID:tpack,项目名称:utilskit,代码行数:46,代码来源:url.ts

示例4: getNormalizedInstruction

function getNormalizedInstruction() {
  const files = project.build.copyFiles;
  let normalizedInstruction = {};

  for (let key in files) {
    normalizedInstruction[path.posix.normalize(key)] = files[key];
  }

  return normalizedInstruction;
}
开发者ID:AshleyGrant,项目名称:cli,代码行数:10,代码来源:copy-files.ts

示例5: normalizeURL

export function normalizeURL(url: string) {
	if (!url || /^[\w+\-\.\+]+:(?!\/)/.test(url)) {
		return url
	}
	const urlObject = parse(url, false, true)
	if (urlObject.pathname) {
		urlObject.pathname = posix.normalize(urlObject.pathname)
	}
	return format(urlObject)
}
开发者ID:tpack,项目名称:utilskit,代码行数:10,代码来源:url.ts

示例6: handleFileUrl

  /**
   * Take the given URL which is either a file:// url or a url with the
   * configured hostname, and treat its pathname as though it points to a file
   * on the local filesystem, producing a file:/// url.
   *
   * Also corrects sibling URLs like `../foo` to point to
   * `./${component_dir}/foo`
   */
  private handleFileUrl(url: Url, unresolvedHref: string) {
    let pathname: string;
    const unresolvedUrl = parseUrl(unresolvedHref);
    if (unresolvedUrl.pathname && unresolvedUrl.pathname.startsWith('/') &&
        unresolvedUrl.protocol !== 'file:') {
      // Absolute urls point to the package root.
      let unresolvedPathname: string;
      try {
        unresolvedPathname =
            posix.normalize(decodeURIComponent(unresolvedUrl.pathname));
      } catch (e) {
        return undefined;  // undecodable url
      }
      pathname = pathlib.join(this.packageDir, unresolvedPathname);
    } else {
      // Otherwise, consider the url that has already been resolved
      // against the baseUrl
      try {
        pathname = posix.normalize(decodeURIComponent(url.pathname || ''));
      } catch (e) {
        return undefined;  // undecodable url
      }
    }

    // If the path points to a sibling directory, resolve it to the
    // component directory
    const parentOfPackageDir = pathlib.dirname(this.packageDir);
    let path = this.filesystemPathForPathname(pathname);
    if (path.startsWith(parentOfPackageDir) &&
        !path.startsWith(this.packageDir)) {
      path = pathlib.join(
          this.packageDir,
          this.componentDir,
          path.substring(parentOfPackageDir.length));
    }

    // TODO(rictic): investigate moving to whatwg URLs internally:
    //     https://github.com/Polymer/polymer-analyzer/issues/804
    // Re-encode URI, since it is expected we are emitting a relative URL.
    return this.brandAsResolved(Uri.file(path).toString());
  }
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:49,代码来源:package-url-resolver.ts

示例7: pathnameForComponentDirUrl

 /**
  * If the given URL is a file url inside our dependencies (e.g.
  * bower_components) then return a resolved posix path to its file.
  * Otherwise return undefined.
  */
 private pathnameForComponentDirUrl(resolvedUrl: ResolvedUrl): string
     |undefined {
   const url = parseUrl(resolvedUrl);
   if (this.shouldHandleAsFileUrl(url) && url.pathname) {
     let pathname;
     try {
       pathname = posix.normalize(decodeURIComponent(url.pathname));
     } catch {
       return undefined;
     }
     const path = this.filesystemPathForPathname(pathname);
     if (path && pathIsInside(path, this.resolvedComponentDir)) {
       return path;
     }
   }
   return undefined;
 }
开发者ID:MehdiRaash,项目名称:tools,代码行数:22,代码来源:package-url-resolver.ts

示例8: 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

示例9: resolve

 resolve(url: FileRelativeUrl|PackageRelativeUrl) {
   return this.simpleUrlResolve(
       url, posix.normalize(process.cwd()) as ResolvedUrl);
 }
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:4,代码来源:url-resolver_test.ts

示例10:

 const files = fileNames.map(f => path.posix.normalize(f));
开发者ID:ramyothman,项目名称:testdashboard,代码行数:1,代码来源:tsconfig.ts


注:本文中的path.posix.normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。