@jsenv/filesystem 4.15.22 → 4.15.24

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": "@jsenv/filesystem",
3
- "version": "4.15.22",
3
+ "version": "4.15.24",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@jsenv/abort": "4.3.1",
30
30
  "@jsenv/url-meta": "8.5.8",
31
- "@jsenv/urls": "2.9.12",
31
+ "@jsenv/urls": "2.9.13",
32
32
  "@jsenv/utils": "2.3.1"
33
33
  },
34
34
  "devDependencies": {
@@ -1,5 +1,5 @@
1
1
  import { comparePathnames } from "./compare_pathnames.js";
2
2
 
3
- export const compareFileUrls = (a, b) => {
4
- return comparePathnames(new URL(a).pathname, new URL(b).pathname);
3
+ export const compareFileUrls = (a, b, options) => {
4
+ return comparePathnames(new URL(a).pathname, new URL(b).pathname, options);
5
5
  };
@@ -1,4 +1,22 @@
1
- export const comparePathnames = (leftPathame, rightPathname) => {
1
+ /*
2
+ * Which of two pathnames comes first: directories before what is under them,
3
+ * deeper before shallower, then the names themselves.
4
+ *
5
+ * How a leading number reads is the caller's call, because the two readings are
6
+ * both right somewhere:
7
+ * - numeric (the default), where the number is a quantity: "9_x" then "10_x" —
8
+ * what a generated list wants, so a story numbered by hand stays in the order
9
+ * it happens;
10
+ * - { numeric: false }, where the number is part of the name: "10_x" right
11
+ * after "1_x" — the order the filesystem itself gives, and the one every file
12
+ * explorer above it shows, so a human reading a directory finds it in the
13
+ * order their editor already shows.
14
+ */
15
+ export const comparePathnames = (
16
+ leftPathame,
17
+ rightPathname,
18
+ { numeric = true } = {},
19
+ ) => {
2
20
  const leftPartArray = leftPathame.split("/");
3
21
  const rightPartArray = rightPathname.split("/");
4
22
 
@@ -34,7 +52,7 @@ export const comparePathnames = (leftPathame, rightPathname) => {
34
52
  i++;
35
53
  // local comparison comes first
36
54
  const comparison = leftPart.localeCompare(rightPart, undefined, {
37
- numeric: true,
55
+ numeric,
38
56
  sensitivity: "base",
39
57
  });
40
58
  if (comparison !== 0) {