@php-wasm/util 0.1.60 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +45 -0
  2. package/package.json +6 -2
package/index.js CHANGED
@@ -16,7 +16,12 @@ var Semaphore = class {
16
16
  await new Promise((resolve) => this.queue.push(resolve));
17
17
  } else {
18
18
  this._running++;
19
+ let released = false;
19
20
  return () => {
21
+ if (released) {
22
+ return;
23
+ }
24
+ released = true;
20
25
  this._running--;
21
26
  if (this.queue.length > 0) {
22
27
  this.queue.shift()();
@@ -35,6 +40,45 @@ var Semaphore = class {
35
40
  }
36
41
  };
37
42
 
43
+ // packages/php-wasm/util/src/lib/join-paths.ts
44
+ function joinPaths(...paths) {
45
+ let path = paths.join("/");
46
+ const isAbsolute = path.charAt(0) === "/";
47
+ const trailingSlash = path.substring(path.length - 1) === "/";
48
+ path = normalizePathsArray(
49
+ path.split("/").filter((p) => !!p),
50
+ !isAbsolute
51
+ ).join("/");
52
+ if (!path && !isAbsolute) {
53
+ path = ".";
54
+ }
55
+ if (path && trailingSlash) {
56
+ path += "/";
57
+ }
58
+ return (isAbsolute ? "/" : "") + path;
59
+ }
60
+ function normalizePathsArray(parts, allowAboveRoot) {
61
+ let up = 0;
62
+ for (let i = parts.length - 1; i >= 0; i--) {
63
+ const last = parts[i];
64
+ if (last === ".") {
65
+ parts.splice(i, 1);
66
+ } else if (last === "..") {
67
+ parts.splice(i, 1);
68
+ up++;
69
+ } else if (up) {
70
+ parts.splice(i, 1);
71
+ up--;
72
+ }
73
+ }
74
+ if (allowAboveRoot) {
75
+ for (; up; up--) {
76
+ parts.unshift("..");
77
+ }
78
+ }
79
+ return parts;
80
+ }
81
+
38
82
  // packages/php-wasm/util/src/lib/php-vars.ts
39
83
  var literal = Symbol("literal");
40
84
  function phpVar(value) {
@@ -72,6 +116,7 @@ function phpVars(vars) {
72
116
  }
73
117
  export {
74
118
  Semaphore,
119
+ joinPaths,
75
120
  phpVar,
76
121
  phpVars
77
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/util",
3
- "version": "0.1.60",
3
+ "version": "0.2.0",
4
4
  "type": "commonjs",
5
5
  "typedoc": {
6
6
  "entryPoint": "./src/index.ts",
@@ -12,5 +12,9 @@
12
12
  "access": "public",
13
13
  "directory": "../../../dist/packages/php-wasm/util"
14
14
  },
15
- "gitHead": "3046803036b19d2c73c63cb01dfb37b1c222d847"
15
+ "gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7",
16
+ "engines": {
17
+ "node": ">=16.15.1",
18
+ "npm": ">=8.11.0"
19
+ }
16
20
  }