@weborigami/async-tree 0.2.9 → 0.2.11

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/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@weborigami/async-tree",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "description": "Asynchronous tree drivers based on standard JavaScript classes",
5
5
  "type": "module",
6
6
  "main": "./main.js",
7
7
  "browser": "./browser.js",
8
8
  "types": "./index.ts",
9
9
  "devDependencies": {
10
- "@types/node": "22.13.5",
10
+ "@types/node": "22.13.13",
11
11
  "typescript": "5.8.2"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/types": "0.2.9"
14
+ "@weborigami/types": "0.2.11"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "node --test --test-reporter=spec",
@@ -13,9 +13,16 @@ export default class ObjectTree {
13
13
  /**
14
14
  * Create a tree wrapping a given plain object or array.
15
15
  *
16
- * @param {any} object The object/array to wrap.
16
+ * @param {object|any[]} object The object/array to wrap.
17
17
  */
18
18
  constructor(object) {
19
+ // Note: we use `typeof` here instead of `instanceof Object` to allow for
20
+ // objects such as Node's `Module` class for representing an ES module.
21
+ if (typeof object !== "object" || object === null) {
22
+ throw new TypeError(
23
+ `${this.constructor.name}: Expected an object or array.`
24
+ );
25
+ }
19
26
  this.object = object;
20
27
  this.parent = object[symbols.parent] ?? null;
21
28
  }
@@ -13,10 +13,10 @@ export default class SiteTree {
13
13
  /**
14
14
  * @param {string} href
15
15
  */
16
- constructor(href = window?.location.href) {
17
- if (href?.startsWith(".") && window?.location !== undefined) {
16
+ constructor(href = globalThis?.location.href) {
17
+ if (href?.startsWith(".") && globalThis?.location !== undefined) {
18
18
  // URL represents a relative path; concatenate with current location.
19
- href = new URL(href, window.location.href).href;
19
+ href = new URL(href, globalThis.location.href).href;
20
20
  }
21
21
 
22
22
  // Add trailing slash if not present; URL should represent a directory.