utilium 3.4.0 → 3.4.1

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/cache.js CHANGED
@@ -80,8 +80,10 @@ export class Resource {
80
80
  }
81
81
  return acc;
82
82
  }, []);
83
- // Extend buffer to include the new region
84
- current.data = extendBuffer(current.data, next.offset + next.data.byteLength);
83
+ // Extend buffer to include the new region. `current.data` starts at
84
+ // `current.offset`, so its length is measured from there (the `.set()`
85
+ // destination is already relative to `current.offset`).
86
+ current.data = extendBuffer(current.data, next.offset + next.data.byteLength - current.offset);
85
87
  current.data.set(next.data, next.offset - current.offset);
86
88
  // Remove the next region after merging
87
89
  this.regions.splice(i + 1, 1);
@@ -165,8 +167,10 @@ export class Resource {
165
167
  const end = offset + data.byteLength;
166
168
  const region = this.regionAt(offset);
167
169
  if (region) {
168
- region.data = extendBuffer(region.data, end);
169
- region.data.set(data, offset);
170
+ // `region.data` holds bytes starting at `region.offset`, so positions
171
+ // within it are relative to `region.offset` (not absolute resource offsets).
172
+ region.data = extendBuffer(region.data, end - region.offset);
173
+ region.data.set(data, offset - region.offset);
170
174
  region.ranges.push({ start: offset, end });
171
175
  region.ranges.sort((a, b) => a.start - b.start);
172
176
  this.collect();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utilium",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "Typescript utilities",
5
5
  "funding": {
6
6
  "type": "individual",
@@ -26,6 +26,8 @@
26
26
  "format:check": "prettier --check .",
27
27
  "format": "prettier --write .",
28
28
  "lint": "tsc --noEmit && eslint src",
29
+ "test": "tsx --test test/**/*.test.ts",
30
+ "build": "tsc -b",
29
31
  "prepublishOnly": "npx tsc"
30
32
  },
31
33
  "repository": {
@@ -66,5 +68,8 @@
66
68
  "printWidth": 120,
67
69
  "arrowParens": "avoid",
68
70
  "experimentalOperatorPosition": "start"
71
+ },
72
+ "allowScripts": {
73
+ "esbuild": true
69
74
  }
70
75
  }
package/scripts/lice.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { existsSync, globSync, readdirSync, readFileSync, statSync } from 'node:fs';
6
6
  import { readFile, writeFile } from 'node:fs/promises';
7
- import { dirname, join, matchesGlob, relative } from 'node:path';
7
+ import { dirname, extname, join, matchesGlob, relative } from 'node:path';
8
8
  import { parseArgs, styleText } from 'node:util';
9
9
 
10
10
  const { positionals: inputs, values: opts } = parseArgs({
@@ -45,9 +45,13 @@ function get_license() {
45
45
  if (!existsSync(pkgPath)) continue;
46
46
 
47
47
  const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'));
48
- if (pkg.spdx) return pkg.spdx;
49
- if (pkg.spdxLicense) return pkg.spdxLicense;
50
- if (pkg.license) return pkg.license;
48
+
49
+ const maybe = pkg.spdx || pkg.spdxLicense || pkg.license;
50
+
51
+ if (maybe) {
52
+ if (opts.verbose) console.log(styleText(['dim'], 'Auto-detected license:'), maybe);
53
+ return maybe;
54
+ }
51
55
  }
52
56
 
53
57
  return null;
@@ -60,6 +64,14 @@ if (opts.write && !expectedLicense) {
60
64
  process.exit(1);
61
65
  }
62
66
 
67
+ /** Some built-in extensions that we should never check */
68
+ const excludeExtensions = ['.json'];
69
+
70
+ /**
71
+ * @param {string} path
72
+ * @param {string} display
73
+ * @returns {boolean}
74
+ */
63
75
  function should_exclude(path, display) {
64
76
  for (const pattern of opts.exclude) {
65
77
  if (!matchesGlob(path, pattern)) continue;
@@ -67,11 +79,22 @@ function should_exclude(path, display) {
67
79
  return true;
68
80
  }
69
81
 
82
+ if (excludeExtensions.includes(extname(path))) return true;
83
+
70
84
  return false;
71
85
  }
72
86
 
73
87
  const licenseSpec = /^([\s\/*!-]*)SPDX-License-Identifier: (.+)$/im;
74
88
 
89
+ /**
90
+ * @typedef {('skipped'|'missing'|'with license'|'correct'|'mismatched')} CheckResult
91
+ */
92
+
93
+ /**
94
+ * @param {string} path
95
+ * @param {string} display
96
+ * @returns {Promise<CheckResult>}
97
+ */
75
98
  async function check_file(path, display) {
76
99
  if (should_exclude(path, display)) return 'skipped';
77
100
 
@@ -100,6 +123,15 @@ async function check_file(path, display) {
100
123
  return 'mismatched';
101
124
  }
102
125
 
126
+ /**
127
+ * @typedef {'correct' | 'skipped' | 'added' | 'overwritten'} WriteResult
128
+ */
129
+
130
+ /**
131
+ * @param {string} path
132
+ * @param {string} display
133
+ * @returns {Promise<WriteResult>}
134
+ */
103
135
  async function write_file(path, display) {
104
136
  if (should_exclude(path, display)) return 'skipped';
105
137
 
@@ -133,6 +165,12 @@ async function write_file(path, display) {
133
165
  return 'overwritten';
134
166
  }
135
167
 
168
+ /**
169
+ *
170
+ * @param {string} dir
171
+ * @param {string} display
172
+ * @returns {Generator<Promise<CheckResult | WriteResult>>}
173
+ */
136
174
  function* check_dir(dir, display) {
137
175
  if (should_exclude(dir, display)) return 'skipped';
138
176
 
@@ -204,7 +242,7 @@ try {
204
242
  .map(([key, value]) => `${key in styles ? styleText(styles[key], value.toString()) : value} ${key}`)
205
243
  .join(', ')
206
244
  );
207
- } catch (error) {
245
+ } catch (/** @type {any} */ error) {
208
246
  console.error(styleText('red', error.toString()));
209
247
  process.exit(1);
210
248
  }
@@ -2,6 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "checkJs": true,
4
4
  "noEmit": true,
5
+ "types": ["node"],
5
6
  "lib": ["ESNext"],
6
7
  "module": "NodeNext",
7
8
  "moduleResolution": "NodeNext"
@@ -1 +0,0 @@
1
- export {};
@@ -1,39 +0,0 @@
1
- // SPDX-License-Identifier: LGPL-3.0-or-later
2
- // Copyright (c) 2025 James Prevett
3
- // addition
4
- const add_positive = 3;
5
- const add_zero = 0;
6
- const add_diff_signs = -1;
7
- const add_negative = -3;
8
- const add_float = 1.6;
9
- // @ts-expect-error 2 + 2 != 5
10
- let fail = 5;
11
- fail = 4;
12
- // subtraction for sanity
13
- const subtract_normal = -18;
14
- const subtract_from_neg = -9;
15
- const subtract_both_neg = 5;
16
- const subtract_zero = -1;
17
- const subtract_floats = 3.1;
18
- // were doing multiplication in the type system now?!
19
- // yup.
20
- const multiply_normal = 6;
21
- const multiply_by_zero = 0;
22
- const multiply_negative = -12;
23
- const multiply_both_negative = 21;
24
- const multiply_large = 896;
25
- // division
26
- const divide_normal = 5;
27
- const divide_by_zero = NaN;
28
- const divide_negative = -4;
29
- const divide_both_negative = 6;
30
- // floor/fraction
31
- const int_normal = 3;
32
- const int_negative = -3;
33
- const fraction_normal = 0.1415;
34
- const fraction_negative = 0.1415;
35
- // With type variable
36
- const pi = 3.141;
37
- // @ts-expect-error 2589 — Recently this started to become too deep even though it worked in the past
38
- const octo_pi = 24.1128;
39
- export {};