inferred-types 0.36.2 → 0.37.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.
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # Inferred Types
2
2
 
3
- A collection of Typescript utilities which try to preserve as much strong and narrow typing as is possible. The repo's `src/` directory ia broken into a set of **runtime** utilities as well as pure **design-type** type utilities.
3
+ A collection of Typescript utilities which try to preserve as much strong and narrow typing as is possible. The repo's `src/` directory ia broken into a set of **runtime** utilities as well as pure **design-time** type utilities.
4
4
 
5
5
  All utilities are tested for runtime and design-time correctness.
package/package.json CHANGED
@@ -1,25 +1,27 @@
1
1
  {
2
2
  "name": "inferred-types",
3
- "version": "0.36.2",
3
+ "version": "0.37.0",
4
4
  "description": "Functions which provide useful type inference on TS projects",
5
5
  "license": "MIT",
6
6
  "author": "Ken Snyder<ken@ken.net>",
7
- "main": "dist/index.js",
8
- "module": "dist/index.mjs",
7
+ "module": "dist/index.js",
9
8
  "typings": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "type": "module",
10
15
  "repository": {
11
16
  "url": "https://github.com/inocan-group/inferred-types"
12
17
  },
13
18
  "sideEffects": false,
14
19
  "scripts": {
15
20
  "about": "tokei src",
16
- "autoindex": "npx dd autoindex",
17
- "build": "run-s clean autoindex lint build:bundle",
18
- "build:force": "run-s clean autoindex build:bundle",
19
- "build:bundle": "npx tsup src/index.ts --dts --format=esm --clean",
21
+ "build": "run-s lint build:bundle",
22
+ "build:bundle": "tsup src/index.ts --dts --format=esm --clean",
20
23
  "watch": "run-p watch:*",
21
- "watch:autoindex": "npx dd autoindex --watch",
22
- "watch:bundle": "npx tsup src/index.ts --dts --format=esm --watch",
24
+ "watch:bundle": "tsup src/index.ts --dts --format=esm --watch",
23
25
  "clean": "rimraf dist/**/*",
24
26
  "lint": "eslint src/**/*.ts --fix && tsc --noEmit ",
25
27
  "lint:full": "eslint src/**/*.ts && eslint tests/**/*.ts && tsc --noEmit",
@@ -40,7 +42,6 @@
40
42
  "bumpp": "^8.2.1",
41
43
  "common-types": "^1.33.2",
42
44
  "cross-env": "^7.0.3",
43
- "dd": "^0.25.4",
44
45
  "dotenv": "^16.0.3",
45
46
  "eslint": "^8.29.0",
46
47
  "eslint-config-prettier": "^8.5.0",
@@ -51,7 +52,6 @@
51
52
  "pathe": "^1.0.0",
52
53
  "prettier": "~2.8.1",
53
54
  "rimraf": "^3.0.2",
54
- "sharp": "^0.31.2",
55
55
  "tsup": "^6.5.0",
56
56
  "typescript": "^4.9.4",
57
57
  "vite": "^3.2.5",
@@ -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
@@ -94,6 +94,7 @@ export type ConverterCoverage = "string" | "number" | "boolean" | "object";
94
94
  /**
95
95
  * Extracts the coverage provided by a `StrongMap` as a Tuple
96
96
  */
97
+ // eslint-disable-next-line no-use-before-define
97
98
  export type MapCoverage<T extends StrongMap<ConverterCoverage>> = T extends StrongMap<
98
99
  infer Coverage
99
100
  >
@@ -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
  });