inferred-types 0.36.2 → 0.36.4

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.
package/dist/index.d.ts CHANGED
@@ -2146,7 +2146,7 @@ type StripLeading<T extends string, U extends string> = IfLiteral<T, string exte
2146
2146
  * `EnsureStarting<T>`, and `StripStarting<T>` to further shape
2147
2147
  * the type.
2148
2148
  */
2149
- type PathJoin<T extends string, U extends string | readonly string[]> = U extends readonly string[] ? PathMultiJoin<PathJoin<T, "">, [...U]> : U extends string ? IfLiteral<T, IfLiteral<U, `${StripTrailing<T, "/">}/${StripLeading<U, "/">}`, `${StripTrailing<T, "/">}/${string}`>, IfLiteral<U, `${string}${U}`, string>> : never;
2149
+ type PathJoin<T extends string, U extends string | readonly string[]> = [] extends U ? T : U extends readonly string[] ? PathMultiJoin<PathJoin<T, "">, [...U]> : U extends string ? IfLiteral<T, IfLiteral<U, `${StripTrailing<T, "/">}/${StripLeading<U, "/">}`, `${StripTrailing<T, "/">}/${string}`>, IfLiteral<U, `${string}${U}`, string>> : never;
2150
2150
  type PathMultiJoin<TProcessed extends string, TRemaining extends readonly string[]> = [] extends TRemaining ? TProcessed : PathMultiJoin<PathJoin<TProcessed, First<TRemaining>>, AfterFirst<TRemaining>>;
2151
2151
 
2152
2152
  type Consonant = "b" | "c" | "d" | "f" | "g" | "h" | "j" | "k" | "l" | "m" | "n" | "p" | "q" | "r" | "s" | "t" | "v" | "w" | "x" | "z" | "y";
package/dist/index.mjs CHANGED
@@ -763,9 +763,9 @@ function stripLeading(content, strip) {
763
763
 
764
764
  // src/runtime/literals/pathJoin.ts
765
765
  function pathJoin(begin, ...rest) {
766
- const start = ensureTrailing(begin, "/");
767
- const end = ensureLeading(rest.slice(-1)[0], "/");
768
- const middle = rest.slice(0, rest.length - 1).map((i) => stripLeading(stripTrailing(i, "/"), '"'));
766
+ const start = rest.length > 0 ? ensureTrailing(begin, "/") : begin;
767
+ const end = rest.length > 0 ? ensureLeading(rest.slice(-1)[0], "/") : "";
768
+ const middle = rest.length > 1 ? rest.slice(0, rest.length - 1).map((i) => stripLeading(stripTrailing(i, "/"), '"')) : [];
769
769
  const midString = stripTrailing(stripLeading(middle.join("/"), "/"), "/");
770
770
  return rest.length > 1 ? `${start}${midString}${end}` : `${start}${stripLeading(end, "/")}`;
771
771
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.36.2",
3
+ "version": "0.36.4",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",
@@ -19,11 +19,12 @@ export function pathJoin<T extends string, U extends readonly string[]>(
19
19
  begin: T,
20
20
  ...rest: U
21
21
  ): PathJoin<T, U> {
22
- const start = ensureTrailing(begin, "/");
23
- const end = ensureLeading(rest.slice(-1)[0], "/");
24
- const middle = rest
25
- .slice(0, rest.length - 1)
26
- .map((i) => stripLeading(stripTrailing(i, "/"), '"'));
22
+ const start = rest.length > 0 ? ensureTrailing(begin, "/") : begin;
23
+ const end = rest.length > 0 ? ensureLeading(rest.slice(-1)[0], "/") : "";
24
+ const middle =
25
+ rest.length > 1
26
+ ? rest.slice(0, rest.length - 1).map((i) => stripLeading(stripTrailing(i, "/"), '"'))
27
+ : [];
27
28
  const midString = stripTrailing(stripLeading(middle.join("/"), "/"), "/");
28
29
 
29
30
  return (
@@ -21,7 +21,9 @@ export type PathJoin<
21
21
  T extends string,
22
22
  // trailing string or strings
23
23
  U extends string | readonly string[]
24
- > = U extends readonly string[]
24
+ > = [] extends U
25
+ ? T
26
+ : U extends readonly string[]
25
27
  ? // eslint-disable-next-line no-use-before-define
26
28
  PathMultiJoin<PathJoin<T, "">, [...U]>
27
29
  : U extends string
@@ -91,4 +91,21 @@ describe("pathJoin() runtime util", () => {
91
91
  expect(t3).toBe("/foo/bar/baz");
92
92
  expect(t4).toBe("foo/bar/baz/");
93
93
  });
94
+
95
+ it("singular value", () => {
96
+ const t1 = pathJoin("foo");
97
+ const t2 = pathJoin("foo/");
98
+
99
+ // runtime
100
+ expect(t1).toBe("foo");
101
+ expect(t2).toBe("foo/");
102
+
103
+ // design time
104
+ type cases = [
105
+ //
106
+ Expect<Equal<typeof t1, "foo">>,
107
+ Expect<Equal<typeof t2, "foo/">>
108
+ ];
109
+ const cases: cases = [true, true];
110
+ });
94
111
  });