edfcore 0.6.26 → 0.6.27

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.
@@ -109,5 +109,5 @@ export declare const SIGNAL_FIELD_BLOCK_OFFSETS: {
109
109
  readonly reserved: 224;
110
110
  };
111
111
  /** Published package version. Kept in sync with package.json by a test. */
112
- export declare const VERSION = "0.6.26";
112
+ export declare const VERSION = "0.6.27";
113
113
  //# sourceMappingURL=constants.d.ts.map
package/dist/constants.js CHANGED
@@ -79,5 +79,5 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
79
79
  reserved: 224,
80
80
  };
81
81
  /** Published package version. Kept in sync with package.json by a test. */
82
- export const VERSION = '0.6.26';
82
+ export const VERSION = '0.6.27';
83
83
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/header/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,SAAS,EAAE,CAGlF;AAMD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAgCjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAQpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAC3C,SAAS,SAAS,EAAE,CAKtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEjE"}
1
+ {"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../../src/header/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,SAAS,EAAE,CAGlF;AA6CD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAsCjF;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAQpE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,SAAS,EACjB,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,GAC3C,SAAS,SAAS,EAAE,CAKtB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,CAEjE"}
@@ -30,8 +30,43 @@ export function findSignals(header, label) {
30
30
  const wanted = trimEdfField(label);
31
31
  return Object.freeze(header.signals.filter((signal) => signal.label === wanted));
32
32
  }
33
- function quoteLabels(header) {
34
- return header.signals.map((signal) => JSON.stringify(signal.label)).join(', ');
33
+ /**
34
+ * Enough labels to recognise the file, few enough to read in a terminal.
35
+ *
36
+ * Every other listing this package prints is capped — 24 bytes of hex, 16 bytes of field evidence,
37
+ * twenty diagnostics — and this one was not, in the one message whose length grows with the file.
38
+ * A mistyped label on a 512-signal recording put five thousand characters on one line behind
39
+ * `edfcore: `, and `inspect.ts` names a 512-signal file as the realistic one. The full list is
40
+ * still on the error, as `availableLabels`, for a program that wants it.
41
+ */
42
+ const LABELS_SHOWN = 12;
43
+ /** The whole label list, capped, saying how many it withheld — never silently truncated. */
44
+ function quoteLabels(header, first) {
45
+ const labels = header.signals.map((signal) => signal.label);
46
+ const ordered = first === undefined ? labels : [first, ...labels.filter((label) => label !== first)];
47
+ const shown = ordered.slice(0, LABELS_SHOWN).map((label) => JSON.stringify(label));
48
+ const hidden = ordered.length - shown.length;
49
+ return hidden > 0 ? `${shown.join(', ')}, and ${hidden} more` : shown.join(', ');
50
+ }
51
+ /**
52
+ * `String.prototype.toLowerCase`, not `toLocaleLowerCase`: the second one folds `'I'` to a dotless
53
+ * `'ı'` under a Turkish locale, and this package's output is deterministic and locale-free.
54
+ */
55
+ const foldCase = (text) => trimEdfField(text).toLowerCase().replace(/\s+/g, ' ');
56
+ /**
57
+ * The label that differs from the selector only in case or in internal spacing, if there is one.
58
+ *
59
+ * The module note above says why matching is exact and case-sensitive: `'Fp1'` and `'FP1'` are
60
+ * written by different systems and edfcore has no montage vocabulary to decide they are the same
61
+ * electrode. That is a decision about MATCHING, not a reason to make the reader work out what
62
+ * happened — the message said "is case-sensitive" while holding the label that proves it is what
63
+ * bit them.
64
+ *
65
+ * Naming it changes nothing about which signal is returned. It is still refused.
66
+ */
67
+ function differsOnlyInCase(header, selector) {
68
+ const wanted = foldCase(selector);
69
+ return header.signals.find((signal) => foldCase(signal.label) === wanted)?.label;
35
70
  }
36
71
  /**
37
72
  * One signal, by index or by label.
@@ -53,9 +88,15 @@ export function getSignal(header, selector) {
53
88
  const matches = findSignals(header, selector);
54
89
  const first = matches[0];
55
90
  if (first === undefined) {
56
- throw new EdfChannelNotFoundError(`no signal is labelled ${JSON.stringify(trimEdfField(selector))} in this file. Labels, ` +
57
- `in signal order: ${quoteLabels(header)}. Matching is exact on the trimmed label and ` +
58
- 'is case-sensitive. Next: pass one of those labels, or select by index.', { selector, availableLabels: header.signals.map((signal) => signal.label) });
91
+ const near = differsOnlyInCase(header, selector);
92
+ throw new EdfChannelNotFoundError(`no signal is labelled ${JSON.stringify(trimEdfField(selector))} in this file. ` +
93
+ (near === undefined
94
+ ? ''
95
+ : `This file has ${JSON.stringify(near)}, which differs only in case or spacing. `) +
96
+ `Labels, in signal order: ${quoteLabels(header, near)}. Matching is exact on the ` +
97
+ 'trimmed label and is case-sensitive. Next: pass ' +
98
+ (near === undefined ? 'one of those labels' : `${JSON.stringify(near)}`) +
99
+ ', or select by index.', { selector, availableLabels: header.signals.map((signal) => signal.label) });
59
100
  }
60
101
  if (matches.length === 1)
61
102
  return first;
@@ -1 +1 @@
1
- {"version":3,"file":"lookup.js","sourceRoot":"","sources":["../../src/header/lookup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGjD;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,MAAM,OAAO,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,OAAO,OAAO,KAAK,qBAAqB,IAAI,OAAO,KAAK,qBAAqB,CAAC;AAChF,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,WAAW,CAAC,MAAiB,EAAE,KAAa;IAC1D,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;I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C,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClE,OAAO,MAAM,CAAC,MAAM,CAClB,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAChF,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,uBAAuB,CAAC,MAAiB;IACvD,OAAO,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AACjF,CAAC"}
package/docs/CHANGELOG.md CHANGED
@@ -6,6 +6,27 @@ alone does not tell you whether you were affected.
6
6
  edfcore is pre-1.0. Patch releases have carried behaviour changes where the old behaviour was a
7
7
  defect; those are called out below.
8
8
 
9
+ ## 0.6.27
10
+
11
+ - **Changed** the "no signal is labelled" refusal to name the label that differs only in case or
12
+ spacing. `lookup.ts` explains why matching is exact and case-sensitive — `'Fp1'` and `'FP1'` are
13
+ written by different systems and edfcore has no montage vocabulary to decide they are the same
14
+ electrode — and the message said "matching is exact on the trimmed label and is case-sensitive"
15
+ while holding the label that proves that is what went wrong, and printing it somewhere in a list
16
+ of every other label for the reader to spot.
17
+ - That decision is about which signal comes back, and it is unchanged: `getSignal(header, 'FP1')`
18
+ on a file with `'Fp1'` still throws. It was never a reason to make the reader do the comparison.
19
+ The near miss is named, put first in the list, and repeated in the `Next:` clause.
20
+ - **Changed** the list of labels to be capped at twelve, saying how many it withheld. Every other
21
+ listing this package prints is capped — 24 bytes of hex, 16 of field evidence, twenty
22
+ diagnostics, `--limit` events — and this was the one that was not, in the one message whose
23
+ length grows with the file. A mistyped label on a 512-signal recording put five thousand
24
+ characters on one line behind `edfcore: `, and `inspect.ts` names a 512-signal file as the
25
+ realistic one.
26
+ - `availableLabels` on the error still carries every label, so nothing a program reads was capped.
27
+ Case is folded with `toLowerCase` rather than `toLocaleLowerCase`, which would fold `'I'` to a
28
+ dotless `'ı'` under a Turkish locale and make this message depend on where it ran.
29
+
9
30
  ## 0.6.26
10
31
 
11
32
  - **Changed** `NOT_AN_EDF_FILE` to say which archive it was handed, when the first bytes say so.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "edfcore",
3
- "version": "0.6.26",
3
+ "version": "0.6.27",
4
4
  "description": "Modern, typed, zero-dependency reader for EDF, EDF+, BDF and BDF+ biosignal files. Works in browsers and Node with true random access.",
5
5
  "keywords": [
6
6
  "edf",
package/src/constants.ts CHANGED
@@ -93,4 +93,4 @@ export const SIGNAL_FIELD_BLOCK_OFFSETS = {
93
93
  } as const;
94
94
 
95
95
  /** Published package version. Kept in sync with package.json by a test. */
96
- export const VERSION = '0.6.26';
96
+ export const VERSION = '0.6.27';
@@ -35,8 +35,47 @@ export function findSignals(header: EdfHeader, label: string): readonly EdfSigna
35
35
  return Object.freeze(header.signals.filter((signal) => signal.label === wanted));
36
36
  }
37
37
 
38
- function quoteLabels(header: EdfHeader): string {
39
- return header.signals.map((signal) => JSON.stringify(signal.label)).join(', ');
38
+ /**
39
+ * Enough labels to recognise the file, few enough to read in a terminal.
40
+ *
41
+ * Every other listing this package prints is capped — 24 bytes of hex, 16 bytes of field evidence,
42
+ * twenty diagnostics — and this one was not, in the one message whose length grows with the file.
43
+ * A mistyped label on a 512-signal recording put five thousand characters on one line behind
44
+ * `edfcore: `, and `inspect.ts` names a 512-signal file as the realistic one. The full list is
45
+ * still on the error, as `availableLabels`, for a program that wants it.
46
+ */
47
+ const LABELS_SHOWN = 12;
48
+
49
+ /** The whole label list, capped, saying how many it withheld — never silently truncated. */
50
+ function quoteLabels(header: EdfHeader, first?: string): string {
51
+ const labels = header.signals.map((signal) => signal.label);
52
+ const ordered =
53
+ first === undefined ? labels : [first, ...labels.filter((label) => label !== first)];
54
+ const shown = ordered.slice(0, LABELS_SHOWN).map((label) => JSON.stringify(label));
55
+ const hidden = ordered.length - shown.length;
56
+ return hidden > 0 ? `${shown.join(', ')}, and ${hidden} more` : shown.join(', ');
57
+ }
58
+
59
+ /**
60
+ * `String.prototype.toLowerCase`, not `toLocaleLowerCase`: the second one folds `'I'` to a dotless
61
+ * `'ı'` under a Turkish locale, and this package's output is deterministic and locale-free.
62
+ */
63
+ const foldCase = (text: string): string => trimEdfField(text).toLowerCase().replace(/\s+/g, ' ');
64
+
65
+ /**
66
+ * The label that differs from the selector only in case or in internal spacing, if there is one.
67
+ *
68
+ * The module note above says why matching is exact and case-sensitive: `'Fp1'` and `'FP1'` are
69
+ * written by different systems and edfcore has no montage vocabulary to decide they are the same
70
+ * electrode. That is a decision about MATCHING, not a reason to make the reader work out what
71
+ * happened — the message said "is case-sensitive" while holding the label that proves it is what
72
+ * bit them.
73
+ *
74
+ * Naming it changes nothing about which signal is returned. It is still refused.
75
+ */
76
+ function differsOnlyInCase(header: EdfHeader, selector: string): string | undefined {
77
+ const wanted = foldCase(selector);
78
+ return header.signals.find((signal) => foldCase(signal.label) === wanted)?.label;
40
79
  }
41
80
 
42
81
  /**
@@ -62,10 +101,16 @@ export function getSignal(header: EdfHeader, selector: number | string): EdfSign
62
101
  const matches = findSignals(header, selector);
63
102
  const first = matches[0];
64
103
  if (first === undefined) {
104
+ const near = differsOnlyInCase(header, selector);
65
105
  throw new EdfChannelNotFoundError(
66
- `no signal is labelled ${JSON.stringify(trimEdfField(selector))} in this file. Labels, ` +
67
- `in signal order: ${quoteLabels(header)}. Matching is exact on the trimmed label and ` +
68
- 'is case-sensitive. Next: pass one of those labels, or select by index.',
106
+ `no signal is labelled ${JSON.stringify(trimEdfField(selector))} in this file. ` +
107
+ (near === undefined
108
+ ? ''
109
+ : `This file has ${JSON.stringify(near)}, which differs only in case or spacing. `) +
110
+ `Labels, in signal order: ${quoteLabels(header, near)}. Matching is exact on the ` +
111
+ 'trimmed label and is case-sensitive. Next: pass ' +
112
+ (near === undefined ? 'one of those labels' : `${JSON.stringify(near)}`) +
113
+ ', or select by index.',
69
114
  { selector, availableLabels: header.signals.map((signal) => signal.label) },
70
115
  );
71
116
  }