@murky-web/typebuddy 1.4.0 → 2.0.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
@@ -93,6 +93,19 @@ modules.
93
93
 
94
94
  If you want the `typebuddy` utility types globally, opt in once in your project:
95
95
 
96
+ ```jsonc
97
+ // tsconfig.json
98
+ {
99
+ "compilerOptions": {
100
+ "types": ["@murky-web/typebuddy/globals"]
101
+ }
102
+ }
103
+ ```
104
+
105
+ `types` is replaced, not merged, when a tsconfig `extends` another one, so a
106
+ config that sets its own `types` has to list the entry again. A side-effect
107
+ import in any `.d.ts` file the program includes works as well:
108
+
96
109
  ```typescript
97
110
  import type {} from "@murky-web/typebuddy/globals";
98
111
  ```
package/dist/parse.js CHANGED
@@ -69,7 +69,7 @@ function parseDomainName(url, defaultValue) {
69
69
  let urlCandidate = normalizedValue;
70
70
  if (!normalizedValue.includes("://")) urlCandidate = `https://${normalizedValue}`;
71
71
  try {
72
- const { hostname } = new URL(urlCandidate);
72
+ const { hostname } = new globalThis.URL(urlCandidate);
73
73
  const [domainName] = hostname.replace(/^www\d?\./i, "").split(".");
74
74
  if (domainName === void 0 || domainName === "") return defaultValue;
75
75
  return domainName;
package/jsr.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "$schema": "https://jsr.io/schema/config-file.v1.json",
3
3
  "name": "@murky-web/typebuddy",
4
- "version": "1.4.0",
4
+ "version": "2.0.0",
5
5
  "license": "ISC",
6
6
  "exports": {
7
7
  ".": "./src/index.ts",
8
- "./biome": "./biome/index.ts",
9
8
  "./oxlint": "./oxlint/index.ts"
10
9
  },
11
10
  "publish": {
@@ -13,15 +12,12 @@
13
12
  "README.md",
14
13
  "src/**/*.ts",
15
14
  "oxlint/**/*.ts",
16
- "rules/**/*.ts",
17
- "biome/**/*.ts",
18
- "biome/*.grit",
19
- "biome/*.gritt"
15
+ "rules/**/*.ts"
20
16
  ],
21
17
  "exclude": [
22
18
  "tests/**",
23
19
  "smoke/**",
24
- "globals.ts",
20
+ "globals.d.ts",
25
21
  "dist/**",
26
22
  "node_modules/**"
27
23
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@murky-web/typebuddy",
3
- "version": "1.4.0",
3
+ "version": "2.0.0",
4
4
  "description": "Your new best friend for simple typescript guards every project needs.",
5
5
  "private": false,
6
6
  "main": "./dist/index.js",
@@ -43,32 +43,25 @@
43
43
  "default": "./dist/collections.js"
44
44
  },
45
45
  "./globals": {
46
- "types": "./globals.ts",
47
- "import": "./dist/globals.js",
48
- "default": "./dist/globals.js"
46
+ "types": "./globals.d.ts"
49
47
  },
50
48
  "./oxlint": {
51
49
  "types": "./oxlint/index.ts",
52
50
  "import": "./dist/oxlint.js",
53
51
  "default": "./dist/oxlint.js"
54
52
  },
55
- "./biome": {
56
- "types": "./biome/index.ts",
57
- "import": "./dist/biome.js",
58
- "default": "./dist/biome.js"
59
- },
60
53
  "./package.json": "./package.json"
61
54
  },
62
55
  "scripts": {
63
56
  "test": "vitest run",
64
57
  "build:local": "bun run build",
65
- "build": "bun run clean && tsdown && cp ./biome/*.grit ./dist/ && cp ./biome/*.gritt ./dist/",
58
+ "build": "bun run clean && tsdown",
66
59
  "clean": "rm -rf dist",
67
- "lint": "oxlint -c ./.oxlintrc.jsonc --tsconfig ./tsconfig.lint.json --type-aware src biome tsdown.config.ts vitest.config.ts",
68
- "lint:fix": "oxlint -c ./.oxlintrc.jsonc --tsconfig ./tsconfig.lint.json --type-aware --fix src biome tsdown.config.ts vitest.config.ts",
69
- "format": "oxfmt -c ../config/oxc/.oxfmtrc.jsonc src rules biome tests tsdown.config.ts vitest.config.ts",
70
- "format:check": "oxfmt -c ../config/oxc/.oxfmtrc.jsonc --check src rules biome tests tsdown.config.ts vitest.config.ts",
71
- "smoke:globals": "bun run build && tsc --project ./smoke/globals/tsconfig.json --noEmit",
60
+ "lint": "oxlint -c ./.oxlintrc.jsonc --tsconfig ./tsconfig.lint.json --type-aware src tsdown.config.ts vitest.config.ts",
61
+ "lint:fix": "oxlint -c ./.oxlintrc.jsonc --tsconfig ./tsconfig.lint.json --type-aware --fix src tsdown.config.ts vitest.config.ts",
62
+ "format": "oxfmt -c ../../config/oxc/.oxfmtrc.jsonc src rules tests tsdown.config.ts vitest.config.ts",
63
+ "format:check": "oxfmt -c ../../config/oxc/.oxfmtrc.jsonc --check src rules tests tsdown.config.ts vitest.config.ts",
64
+ "smoke:globals": "bun run build && tsc --project ./smoke/globals/tsconfig.json --noEmit && mkdir -p ./smoke/globals/node_modules/@murky-web && ln -sfn ../../../.. ./smoke/globals/node_modules/@murky-web/typebuddy && tsc --project ./smoke/globals/tsconfig.types.json --noEmit",
72
65
  "smoke:oxlint": "bun run build && bun ./smoke/oxlint/run-smoke.ts",
73
66
  "smoke:oxlint:fix": "bun run build && bun ./smoke/oxlint/run-fix-smoke.ts",
74
67
  "smoke:subpath": "bun run build && bun ./smoke/subpath/run.ts",
@@ -76,9 +69,8 @@
76
69
  "typecheck": "tsc --project ./tsconfig.json --noEmit && tsc --project ./tsconfig.vitest.json --noEmit"
77
70
  },
78
71
  "files": [
79
- "biome",
80
72
  "dist",
81
- "globals.ts",
73
+ "globals.d.ts",
82
74
  "jsr.json",
83
75
  "oxlint/index.ts",
84
76
  "rules",
@@ -101,7 +93,6 @@
101
93
  "provenance": true
102
94
  },
103
95
  "devDependencies": {
104
- "@murky-web/config": "workspace:*",
105
96
  "@types/node": "^25.5.0"
106
97
  }
107
98
  }
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  // program that imports this package, so the global helpers need no
3
3
  // tsconfig entry of their own. The empty brace form is the only way to say
4
4
  // "load this module for its ambient declarations" without importing a value,
5
- // and `globals.ts` sits at the package root because it is a published entry
5
+ // and `globals.d.ts` sits at the package root because it is a published entry
6
6
  // point (`@murky-web/typebuddy/globals`).
7
7
  // oxlint-disable-next-line no-empty-named-blocks, no-relative-parent-imports, require-module-specifiers
8
8
  import type {} from "../globals.js";
package/src/parse.ts CHANGED
@@ -192,7 +192,7 @@ function parseDomainName(url: string, defaultValue?: string): Optional<string> {
192
192
  // Everything that depends on a parseable URL stays inside the `try`, so
193
193
  // there is no binding that has to be declared before it can be assigned.
194
194
  try {
195
- const { hostname } = new URL(urlCandidate);
195
+ const { hostname } = new globalThis.URL(urlCandidate);
196
196
  const normalizedHostname = hostname.replace(/^www\d?\./i, "");
197
197
  const [domainName] = normalizedHostname.split(".");
198
198
  if (domainName === undefined || domainName === "") {
package/biome/index.ts DELETED
@@ -1,6 +0,0 @@
1
- const resolveAsset = (asset: string): string =>
2
- decodeURIComponent(new URL(asset, import.meta.url).pathname);
3
-
4
- export const MaybePromiseRule: string = resolveAsset("./maybe_promise_rule.grit");
5
- export const OptionalRule: string = resolveAsset("./optional_rule.gritt");
6
- export const TryCatchAsyncRule: string = resolveAsset("./require-try-catch-async.grit");
@@ -1,15 +0,0 @@
1
- or {
2
- // 1. Replace Promise with MaybePromise in return types
3
- `: Promise<$type>` => `: MaybePromise<$type>`,
4
-
5
- // 2. Wrap return values in try blocks with { value, isError: false }
6
- `try { $tryBody } catch ($err) { $catchBody }` where {
7
- $tryBody <: contains `return $value` and {
8
- $value <: not contains `{ isError: $isErrorValue }`
9
- }
10
- } => `try { $tryBody <: replace `return $value` => `return { value: $value, isError: false }` } catch ($err) { $catchBody }`,
11
-
12
- // 3. Handle empty return statements in try blocks
13
- `try { $tryBody } catch ($err) { $catchBody }` where {
14
- $tryBody <: contains `return;`
15
- } => `try { $tryBody <: replace `return;` => `return { value: undefined, isError: false };` } catch ($err) { $catchBody }`,
@@ -1,11 +0,0 @@
1
- or {
2
- // T | null -> Maybe<T>
3
- `$type | null` where {
4
- $type <: not contains `null | undefined`
5
- } => `Maybe<$type>`,
6
-
7
- // T | null | undefined -> Nullable<T>
8
- `$type | null | undefined` where {
9
- $type <: not contains `null | undefined`
10
- } => `Nullable<$type>`
11
- }
@@ -1,3 +0,0 @@
1
- `$type | null | undefined` where {
2
- $type <: not contains `null | undefined`
3
- } => `Nullable<$type>`
@@ -1,8 +0,0 @@
1
- or {
2
- // T | null -> Maybe<T>
3
- `$type | null` where { $type <: not contains `null | undefined` } => `Maybe<$type>`,
4
- // T | null | undefined -> Nullable<T>
5
- `$type | null | undefined` where { $type <: not contains `null | undefined` } => `Nullable<$type>`,
6
- // T | undefined -> Optional<T>
7
- `$type | undefined` where { $type <: not contains `undefined` } => `Optional<$type>`
8
- }
@@ -1,5 +0,0 @@
1
- or {
2
- `async function $name($params) { $body }` where { $body <: not contains `try { $tryBody } catch ($err) { $catchBody }` } => `async function $name($params) { try { $body } catch (err) { // handle error } }`,
3
- `(async function($params) { $body })` where { $body <: not contains `try { $tryBody } catch ($err) { $catchBody }` } => `(async function($params) { try { $body } catch (err) { // handle error } })`,
4
- `(async ($params) => { $body })` where { $body <: not contains `try { $tryBody } catch ($err) { $catchBody }` } => `(async ($params) => { try { $body } catch (err) { // handle error } })`
5
- }
package/dist/biome.js DELETED
@@ -1,7 +0,0 @@
1
- //#region biome/index.ts
2
- const resolveAsset = (asset) => decodeURIComponent(new URL(asset, import.meta.url).pathname);
3
- const MaybePromiseRule = resolveAsset("./maybe_promise_rule.grit");
4
- const OptionalRule = resolveAsset("./optional_rule.gritt");
5
- const TryCatchAsyncRule = resolveAsset("./require-try-catch-async.grit");
6
- //#endregion
7
- export { MaybePromiseRule, OptionalRule, TryCatchAsyncRule };
package/dist/globals.js DELETED
File without changes
@@ -1,15 +0,0 @@
1
- or {
2
- // 1. Replace Promise with MaybePromise in return types
3
- `: Promise<$type>` => `: MaybePromise<$type>`,
4
-
5
- // 2. Wrap return values in try blocks with { value, isError: false }
6
- `try { $tryBody } catch ($err) { $catchBody }` where {
7
- $tryBody <: contains `return $value` and {
8
- $value <: not contains `{ isError: $isErrorValue }`
9
- }
10
- } => `try { $tryBody <: replace `return $value` => `return { value: $value, isError: false }` } catch ($err) { $catchBody }`,
11
-
12
- // 3. Handle empty return statements in try blocks
13
- `try { $tryBody } catch ($err) { $catchBody }` where {
14
- $tryBody <: contains `return;`
15
- } => `try { $tryBody <: replace `return;` => `return { value: undefined, isError: false };` } catch ($err) { $catchBody }`,
@@ -1,11 +0,0 @@
1
- or {
2
- // T | null -> Maybe<T>
3
- `$type | null` where {
4
- $type <: not contains `null | undefined`
5
- } => `Maybe<$type>`,
6
-
7
- // T | null | undefined -> Nullable<T>
8
- `$type | null | undefined` where {
9
- $type <: not contains `null | undefined`
10
- } => `Nullable<$type>`
11
- }
@@ -1,3 +0,0 @@
1
- `$type | null | undefined` where {
2
- $type <: not contains `null | undefined`
3
- } => `Nullable<$type>`
@@ -1,8 +0,0 @@
1
- or {
2
- // T | null -> Maybe<T>
3
- `$type | null` where { $type <: not contains `null | undefined` } => `Maybe<$type>`,
4
- // T | null | undefined -> Nullable<T>
5
- `$type | null | undefined` where { $type <: not contains `null | undefined` } => `Nullable<$type>`,
6
- // T | undefined -> Optional<T>
7
- `$type | undefined` where { $type <: not contains `undefined` } => `Optional<$type>`
8
- }
@@ -1,5 +0,0 @@
1
- or {
2
- `async function $name($params) { $body }` where { $body <: not contains `try { $tryBody } catch ($err) { $catchBody }` } => `async function $name($params) { try { $body } catch (err) { // handle error } }`,
3
- `(async function($params) { $body })` where { $body <: not contains `try { $tryBody } catch ($err) { $catchBody }` } => `(async function($params) { try { $body } catch (err) { // handle error } })`,
4
- `(async ($params) => { $body })` where { $body <: not contains `try { $tryBody } catch ($err) { $catchBody }` } => `(async ($params) => { try { $body } catch (err) { // handle error } })`
5
- }
File without changes