@adecore/utils 0.0.1 → 0.54.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @adecore/utils
2
2
 
3
- Small helpers without dependencies: atomic file writes, path containment, the order of async work and reading a thrown value. Each lives at its own subpath; `async`, `errors` and `record` run in a page, `fs` and `path` need Node or Bun.
3
+ Small helpers without dependencies: atomic file writes, path containment, the order of async work and reading a thrown value. Each lives at its own subpath; `async`, `errors`, `record` and `text` run in a page, `fs` and `path` need Node or Bun.
4
4
 
5
5
  ```sh
6
6
  bun add @adecore/utils
package/dist/async.js CHANGED
@@ -7,11 +7,20 @@ export { SingleFlight } from './single-flight.js';
7
7
  */
8
8
  export function wait(ms, signal) {
9
9
  return new Promise((resolve) => {
10
- const timer = setTimeout(resolve, ms);
11
- signal?.addEventListener('abort', () => {
10
+ if (signal?.aborted) {
11
+ resolve();
12
+ return;
13
+ }
14
+ const onAbort = () => {
12
15
  clearTimeout(timer);
13
16
  resolve();
14
- }, { once: true });
17
+ };
18
+ // A long-lived signal outlives many waits, so each one takes its listener back.
19
+ const timer = setTimeout(() => {
20
+ signal?.removeEventListener('abort', onAbort);
21
+ resolve();
22
+ }, ms);
23
+ signal?.addEventListener('abort', onAbort, { once: true });
15
24
  });
16
25
  }
17
26
  const SYSTEM_TIMER = {
package/dist/record.js CHANGED
@@ -1,4 +1,4 @@
1
- /* A plain object read off the wire or a file, whose fields are still unchecked; an array is not one. */
1
+ /* Any object but an array, such as one read off the wire or a file whose fields are still unchecked. A Date or a class instance passes too. */
2
2
  export function isRecord(value) {
3
3
  return typeof value === 'object' && value !== null && !Array.isArray(value);
4
4
  }
package/package.json CHANGED
@@ -1,65 +1,65 @@
1
1
  {
2
- "name": "@adecore/utils",
3
- "version": "0.0.1",
4
- "description": "Small helpers without dependencies: atomic file writes, path containment, async ordering and error reading.",
5
- "license": "FSL-1.1-MIT",
6
- "author": "Bas Milius",
7
- "repository": {
8
- "type": "git",
9
- "url": "git+https://github.com/basmilius/adecore.git",
10
- "directory": "packages/utils"
2
+ "name": "@adecore/utils",
3
+ "version": "0.54.1",
4
+ "description": "Small helpers without dependencies: atomic file writes, path containment, async ordering and error reading.",
5
+ "license": "FSL-1.1-MIT",
6
+ "author": "Bas Milius",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/basmilius/adecore.git",
10
+ "directory": "packages/utils"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/basmilius/adecore/issues"
14
+ },
15
+ "homepage": "https://adecore.dev/utils/",
16
+ "type": "module",
17
+ "sideEffects": false,
18
+ "files": [
19
+ "dist",
20
+ "src",
21
+ "!src/**/*.test.ts"
22
+ ],
23
+ "exports": {
24
+ "./async": {
25
+ "source": "./src/async.ts",
26
+ "types": "./dist/async.d.ts",
27
+ "default": "./dist/async.js"
11
28
  },
12
- "bugs": {
13
- "url": "https://github.com/basmilius/adecore/issues"
29
+ "./errors": {
30
+ "source": "./src/errors.ts",
31
+ "types": "./dist/errors.d.ts",
32
+ "default": "./dist/errors.js"
14
33
  },
15
- "homepage": "https://adecore.dev/utils/",
16
- "type": "module",
17
- "sideEffects": false,
18
- "files": [
19
- "dist",
20
- "src",
21
- "!src/**/*.test.ts"
22
- ],
23
- "exports": {
24
- "./async": {
25
- "source": "./src/async.ts",
26
- "types": "./dist/async.d.ts",
27
- "default": "./dist/async.js"
28
- },
29
- "./errors": {
30
- "source": "./src/errors.ts",
31
- "types": "./dist/errors.d.ts",
32
- "default": "./dist/errors.js"
33
- },
34
- "./fs": {
35
- "source": "./src/fs.ts",
36
- "types": "./dist/fs.d.ts",
37
- "default": "./dist/fs.js"
38
- },
39
- "./path": {
40
- "source": "./src/path.ts",
41
- "types": "./dist/path.d.ts",
42
- "default": "./dist/path.js"
43
- },
44
- "./record": {
45
- "source": "./src/record.ts",
46
- "types": "./dist/record.d.ts",
47
- "default": "./dist/record.js"
48
- },
49
- "./text": {
50
- "source": "./src/text.ts",
51
- "types": "./dist/text.d.ts",
52
- "default": "./dist/text.js"
53
- }
34
+ "./fs": {
35
+ "source": "./src/fs.ts",
36
+ "types": "./dist/fs.d.ts",
37
+ "default": "./dist/fs.js"
54
38
  },
55
- "scripts": {
56
- "build": "bun scripts/build.ts",
57
- "typecheck": "bun check --no-script",
58
- "test": "bun test --conditions=source"
39
+ "./path": {
40
+ "source": "./src/path.ts",
41
+ "types": "./dist/path.d.ts",
42
+ "default": "./dist/path.js"
59
43
  },
60
- "devDependencies": {
61
- "@types/bun": "^1.4.4",
62
- "@types/node": "^26.6.6",
63
- "typescript": "^7.0.2"
44
+ "./record": {
45
+ "source": "./src/record.ts",
46
+ "types": "./dist/record.d.ts",
47
+ "default": "./dist/record.js"
48
+ },
49
+ "./text": {
50
+ "source": "./src/text.ts",
51
+ "types": "./dist/text.d.ts",
52
+ "default": "./dist/text.js"
64
53
  }
54
+ },
55
+ "scripts": {
56
+ "build": "bun scripts/build.ts",
57
+ "typecheck": "bun check --no-script",
58
+ "test": "bun test --conditions=source"
59
+ },
60
+ "devDependencies": {
61
+ "@types/bun": "^1.4.4",
62
+ "@types/node": "^26.6.6",
63
+ "typescript": "^7.0.2"
64
+ }
65
65
  }
package/src/async.ts CHANGED
@@ -9,16 +9,24 @@ export { SingleFlight } from './single-flight.ts';
9
9
  */
10
10
  export function wait(ms: number, signal?: AbortSignal): Promise<void> {
11
11
  return new Promise((resolve) => {
12
- const timer = setTimeout(resolve, ms);
12
+ if (signal?.aborted) {
13
+ resolve();
13
14
 
14
- signal?.addEventListener(
15
- 'abort',
16
- () => {
17
- clearTimeout(timer);
18
- resolve();
19
- },
20
- { once: true }
21
- );
15
+ return;
16
+ }
17
+
18
+ const onAbort = (): void => {
19
+ clearTimeout(timer);
20
+ resolve();
21
+ };
22
+
23
+ // A long-lived signal outlives many waits, so each one takes its listener back.
24
+ const timer = setTimeout(() => {
25
+ signal?.removeEventListener('abort', onAbort);
26
+ resolve();
27
+ }, ms);
28
+
29
+ signal?.addEventListener('abort', onAbort, { once: true });
22
30
  });
23
31
  }
24
32
 
package/src/record.ts CHANGED
@@ -1,4 +1,4 @@
1
- /* A plain object read off the wire or a file, whose fields are still unchecked; an array is not one. */
1
+ /* Any object but an array, such as one read off the wire or a file whose fields are still unchecked. A Date or a class instance passes too. */
2
2
  export function isRecord(value: unknown): value is Record<string, unknown> {
3
3
  return typeof value === 'object' && value !== null && !Array.isArray(value);
4
4
  }