(opts: { cwd?: () => string } = {})
| 22 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | |
| 24 | export function createPath(opts: { cwd?: () => string } = {}): Path { |
| 25 | function assertPath(path: any) { |
| 26 | if (typeof path !== 'string') { |
| 27 | throw new TypeError('Path must be a string. Received ' + JSON.stringify(path)); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | // Resolves . and .. elements in a path with directory names |
| 32 | function normalizeStringPosix(path: string, allowAboveRoot: boolean): string { |
| 33 | let res = ''; |
| 34 | let lastSegmentLength = 0; |
| 35 | let lastSlash = -1; |
| 36 | let dots = 0; |
| 37 | let code; |
| 38 | for (let i = 0; i <= path.length; ++i) { |
| 39 | if (i < path.length) { |
| 40 | code = path.charCodeAt(i); |
| 41 | } else if (code === 47 /*/*/) { |
| 42 | break; |
| 43 | } else { |
| 44 | code = 47 /*/*/; |
| 45 | } |
| 46 | if (code === 47 /*/*/) { |
| 47 | if (lastSlash === i - 1 || dots === 1) { |
| 48 | // NOOP |
| 49 | } else if (lastSlash !== i - 1 && dots === 2) { |
| 50 | if ( |
| 51 | res.length < 2 || |
| 52 | lastSegmentLength !== 2 || |
| 53 | res.charCodeAt(res.length - 1) !== 46 /*.*/ || |
| 54 | res.charCodeAt(res.length - 2) !== 46 /*.*/ |
| 55 | ) { |
| 56 | if (res.length > 2) { |
| 57 | const lastSlashIndex = res.lastIndexOf('/'); |
| 58 | if (lastSlashIndex !== res.length - 1) { |
| 59 | if (lastSlashIndex === -1) { |
| 60 | res = ''; |
| 61 | lastSegmentLength = 0; |
| 62 | } else { |
| 63 | res = res.slice(0, lastSlashIndex); |
| 64 | lastSegmentLength = res.length - 1 - res.lastIndexOf('/'); |
| 65 | } |
| 66 | lastSlash = i; |
| 67 | dots = 0; |
| 68 | continue; |
| 69 | } |
| 70 | } else if (res.length === 2 || res.length === 1) { |
| 71 | res = ''; |
| 72 | lastSegmentLength = 0; |
| 73 | lastSlash = i; |
| 74 | dots = 0; |
| 75 | continue; |
| 76 | } |
| 77 | } |
| 78 | if (allowAboveRoot) { |
| 79 | if (res.length > 0) { |
| 80 | res += '/..'; |
| 81 | } else { |
no outgoing calls
no test coverage detected
searching dependent graphs…