pick

A helpful utility to pick data from a store by keys. If only one key is specified the derivative will be the value else the derivative will a partial record of the store value.

Demo

Store data:
{
  "name": "Svelte",
  "author": "Rich",
  "createdAt": 1695166985464
}
			
Picked Data 'name':
"Svelte"
			
Picked Data 'name' and 'createdAt':
{
  "name": "Svelte",
  "createdAt": 1695166985464
}
			

Usage

<script lang="ts">
import { pick } from "svelte-legos";
import { writable } from "svelte/store";

const data = writable({
	name: "Svelte",
	author: "Rich",
	createdAt: Date.now(),
});

const name = pick(data, "name"); // $name => "Svelte"

const nameAndAuthor = pick(data, "name", "author");
// $nameAndCreatedAt => { name: "Svelte", author: "Rich" }

</script>