@php-wasm/util
Advanced tools
Comparing version 0.1.61 to 0.2.0
40
index.js
@@ -43,2 +43,41 @@ // packages/php-wasm/util/src/lib/semaphore.ts | ||
// packages/php-wasm/util/src/lib/join-paths.ts | ||
function joinPaths(...paths) { | ||
let path = paths.join("/"); | ||
const isAbsolute = path.charAt(0) === "/"; | ||
const trailingSlash = path.substring(path.length - 1) === "/"; | ||
path = normalizePathsArray( | ||
path.split("/").filter((p) => !!p), | ||
!isAbsolute | ||
).join("/"); | ||
if (!path && !isAbsolute) { | ||
path = "."; | ||
} | ||
if (path && trailingSlash) { | ||
path += "/"; | ||
} | ||
return (isAbsolute ? "/" : "") + path; | ||
} | ||
function normalizePathsArray(parts, allowAboveRoot) { | ||
let up = 0; | ||
for (let i = parts.length - 1; i >= 0; i--) { | ||
const last = parts[i]; | ||
if (last === ".") { | ||
parts.splice(i, 1); | ||
} else if (last === "..") { | ||
parts.splice(i, 1); | ||
up++; | ||
} else if (up) { | ||
parts.splice(i, 1); | ||
up--; | ||
} | ||
} | ||
if (allowAboveRoot) { | ||
for (; up; up--) { | ||
parts.unshift(".."); | ||
} | ||
} | ||
return parts; | ||
} | ||
// packages/php-wasm/util/src/lib/php-vars.ts | ||
@@ -81,4 +120,5 @@ var literal = Symbol("literal"); | ||
Semaphore, | ||
joinPaths, | ||
phpVar, | ||
phpVars | ||
}; |
{ | ||
"name": "@php-wasm/util", | ||
"version": "0.1.61", | ||
"version": "0.2.0", | ||
"type": "commonjs", | ||
@@ -15,3 +15,7 @@ "typedoc": { | ||
}, | ||
"gitHead": "f2cd7382004f7b003904b5db1d33d37fd2b1bfab" | ||
"gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7", | ||
"engines": { | ||
"node": ">=16.15.1", | ||
"npm": ">=8.11.0" | ||
} | ||
} |
3541
120