How to use true-case-path - 2 common examples

To help you get started, we’ve selected a few true-case-path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / rushstack / apps / rush-lib / src / api / EnvironmentConfiguration.ts View on Github external
folderPath = path.normalize(folderPath);
    const endsWithSlash: boolean = folderPath.charAt(folderPath.length - 1) === path.sep;
    const parsedPath: path.ParsedPath = path.parse(folderPath);
    const pathRoot: string = parsedPath.root;
    const pathWithoutRoot: string = parsedPath.dir.substr(pathRoot.length);
    const pathParts: string[] = [...pathWithoutRoot.split(path.sep), parsedPath.name].filter((part) => !!part);

    // Starting with all path sections, and eliminating one from the end during each loop iteration,
    // run trueCasePathSync. If trueCasePathSync returns without exception, we've found a subset
    // of the path that exists and we've now gotten the correct casing.
    //
    // Once we've found a parent folder that exists, append the path sections that didn't exist.
    for (let i: number = pathParts.length; i >= 0; i--) {
      const constructedPath: string = path.join(pathRoot, ...pathParts.slice(0, i));
      try {
        const normalizedConstructedPath: string = trueCasePathSync(constructedPath);
        const result: string = path.join(normalizedConstructedPath, ...pathParts.slice(i));
        if (endsWithSlash) {
          return `${result}${path.sep}`;
        } else {
          return result;
        }
      } catch (e) {
        // This path doesn't exist, continue to the next subpath
      }
    }

    return undefined;
  }
}
github ManifoldScholar / manifold / client / codeshifts / fix-import-case.js View on Github external
) {
        absSource = path.resolve("src", source);
      }

      if (absSource) {
        if (!fs.existsSync(absSource)) absSource = `${absSource}.js`;
        if (!fs.existsSync(absSource)) {
          console.error("#########################");
          console.error("Incorrect import");
          console.error("#########################");
          console.error("IN      ", fileInfo.path);
          console.error("SOURCE  ", source);
          console.error("ABS     ", absSource);
        }

        const trueFsPath = trueCasePathSync(absSource);
        if (absSource !== trueFsPath) {
          let newSource;
          if (isRel) {
            newSource = path.relative(fileInfo.path, trueFsPath);
          } else if (endsWith(trueFsPath, ".js")) {
            newSource = trueFsPath.slice(source.length * -1 - 3);
          } else {
            newSource = trueFsPath.slice(source.length * -1);
          }
          if (startsWith(source, "./") && startsWith(newSource, "../"))
            newSource = newSource.substr(1);
          if (startsWith(source, "../") && startsWith(newSource, "../"))
            newSource = newSource.substr(3);
          if (endsWith(newSource, ".js")) newSource = newSource.slice(0, -3);
          console.log(`Transforming import in ${fileInfo.path}:`);
          console.log(`   from: ${source}`);

true-case-path

Given a possibly case-variant version of an existing filesystem path, returns the case-exact, normalized version as stored in the filesystem.

Apache-2.0
Latest version published 5 years ago

Package Health Score

65 / 100
Full package analysis

Popular true-case-path functions

Similar packages