Your digest.js can now import its first function from "./readings.js". Porting the rest of that file raises a question Dev never had to answer in Python: Which of its functions may Asha use?
In Python, the answer was all of them, without anyone deciding. In JavaScript, the module decides, and every file’s imports name exactly what it uses and where it comes from.
Mark What Leaves the File
Python shares every top-level name. Dev’s digest.py imports all three helpers, and nothing in readings.py has to allow it:
from readings import is_blank, parse_line, summarise
Even a name with a leading underscore, such as _is_blank, imports without complaint when you name it. The underscore only keeps it out of from readings import *, as __all__ does.
Both languages give each module its own scope, but a Python import reads any top-level name off the module, while a JavaScript import sees only the names marked with export. Here’s the port, with the loop in summarise() left out:
readings.js
export function isBlank(line) {
return line.trim() === "";
}
export function parseLine(line) {
const [time, temp] = line.trim().split(",");
return { time, temp: Number(temp) };
}
export function summarise(readings, threshold) {
// The loop that finds the peak and the readings over the limit
}