當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。