@weborigami/async-tree 0.2.6 → 0.2.8

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@weborigami/async-tree",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Asynchronous tree drivers based on standard JavaScript classes",
5
5
  "type": "module",
6
6
  "main": "./main.js",
@@ -11,7 +11,7 @@
11
11
  "typescript": "5.7.2"
12
12
  },
13
13
  "dependencies": {
14
- "@weborigami/types": "0.2.6"
14
+ "@weborigami/types": "0.2.8"
15
15
  },
16
16
  "scripts": {
17
17
  "test": "node --test --test-reporter=spec",
package/src/extension.js CHANGED
@@ -89,7 +89,10 @@ export function match(key, ext) {
89
89
 
90
90
  // Key matches if it ends with the same extension
91
91
  const normalized = trailingSlash.remove(key);
92
- if (normalized.endsWith(ext)) {
92
+
93
+ if (ext === "") {
94
+ return normalized.includes(".") ? null : normalized;
95
+ } else if (normalized.endsWith(ext)) {
93
96
  const removed =
94
97
  ext.length > 0 ? normalized.slice(0, -ext.length) : normalized;
95
98
  return trailingSlash.toggle(removed, trailingSlash.has(key));
@@ -2,15 +2,14 @@ import * as extension from "../extension.js";
2
2
  import * as trailingSlash from "../trailingSlash.js";
3
3
 
4
4
  /**
5
- * Given a source resultExtension and a result resultExtension, return a pair of key
5
+ * Given a source extension and a result extension, return a pair of key
6
6
  * functions that map between them.
7
7
  *
8
8
  * The resulting `inverseKey` and `key` functions are compatible with those
9
9
  * expected by map and other transforms.
10
10
  *
11
11
  * @typedef {import("@weborigami/types").AsyncTree} AsyncTree
12
- * @param {{ resultExtension?: string, sourceExtension: string }}
13
- * options
12
+ * @param {{ resultExtension?: string, sourceExtension: string }} options
14
13
  */
15
14
  export default function keyFunctionsForExtensions({
16
15
  resultExtension,
@@ -42,7 +41,7 @@ export default function keyFunctionsForExtensions({
42
41
  function checkDeprecatedExtensionWithoutDot(extension) {
43
42
  if (extension && extension !== "/" && !extension.startsWith(".")) {
44
43
  throw new RangeError(
45
- `map: Warning: the extension "${extension}" should start with a period.`
44
+ `The extension "${extension}" must start with a period.`
46
45
  );
47
46
  }
48
47
  }
@@ -7,12 +7,13 @@ export function getRealmObjectPrototype(object: any): any;
7
7
  export const hiddenFileNames: string[];
8
8
  export function isPacked(obj: any): obj is Packed;
9
9
  export function isPlainObject(obj: any): obj is PlainObject;
10
+ export function isPrimitive(obj: any): boolean;
10
11
  export function isStringLike(obj: any): obj is StringLike;
11
12
  export function isUnpackable(obj): obj is { unpack: () => any };
12
13
  export function keysFromPath(path: string): string[];
13
14
  export const naturalOrder: (a: string, b: string) => number;
14
15
  export function pathFromKeys(keys: string[]): string;
15
16
  export function pipeline(start: any, ...functions: Function[]): Promise<any>;
16
- export function setParent(child: any, parent: AsyncTree): void;
17
+ export function setParent(child: any, parent: AsyncTree|null): void;
17
18
  export function toPlainValue(object: any): Promise<any>;
18
19
  export function toString(object: any): string;
package/src/utilities.js CHANGED
@@ -5,6 +5,8 @@ import * as trailingSlash from "./trailingSlash.js";
5
5
  const textDecoder = new TextDecoder();
6
6
  const TypedArray = Object.getPrototypeOf(Uint8Array);
7
7
 
8
+ /** @typedef {import("@weborigami/types").AsyncTree} AsyncTree */
9
+
8
10
  /**
9
11
  * Return the value as an object. If the value is already an object it will be
10
12
  * returned as is. If the value is a primitive, it will be wrapped in an object:
@@ -244,7 +246,7 @@ export async function pipeline(start, ...fns) {
244
246
  * set the `symbols.parent` property.
245
247
  *
246
248
  * @param {*} child
247
- * @param {*} parent
249
+ * @param {AsyncTree|null} parent
248
250
  */
249
251
  export function setParent(child, parent) {
250
252
  if (Tree.isAsyncTree(child)) {
@@ -19,6 +19,7 @@ describe("extension", () => {
19
19
  assert.equal(match("file.md", ".txt"), null);
20
20
  assert.equal(match("file.md/", ".md"), "file/");
21
21
  assert.equal(match("file", ""), "file");
22
+ assert.equal(match("file.md", ""), null);
22
23
  assert.equal(match("file", "/"), null);
23
24
  assert.equal(match("file/", "/"), "file");
24
25
  });