Svelte exposes a derived function to create derived stores.
The first argument is an existing store. The second is a function that calculates a value from its current data.
import { writable, derived } from 'svelte/store';
export const todos = writable([
{ task: 'Walk dog', completed: false },
]);
export const completedTodos = derived(
todos,
(items) => items.filter((todo) => todo.completed),
);