npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@humanspeak/svelte-keyed

v3.1.0

Published

[![NPM version](https://img.shields.io/npm/v/@humanspeak/svelte-keyed.svg)](https://www.npmjs.com/package/@humanspeak/svelte-keyed) [![Build Status](https://github.com/humanspeak/svelte-keyed/actions/workflows/npm-publish.yml/badge.svg)](https://github.co

Downloads

91

Readme

svelte-keyed

NPM version Build Status

License

Downloads CodeQL

TypeScript Types Maintenance

A writable derived store for objects and arrays with TypeScript support!

const user = writable({ name: { first: 'Rich', last: 'Harris' } })
const firstName = keyed(user, 'name.first')

$firstName = 'Bryan'

console.log($user) // { name: { first: 'Bryan', last: 'Harris' } };

Installation

npm i -D @humanspeak/svelte-keyed

Since Svelte automatically bundles all required dependencies, you only need to install this package as a dev dependency with the -D flag.

API

keyed takes a writable store and a keypath, and returns a writable store whose changes are reflected on the original store. The keypath can target nested properties in objects or elements in arrays.

Properties are accessed with dot notation, and arrays can be indexed with bracket notation:

const email = keyed(settings, 'profiles[0].email')
const firstItem = keyed(list, '[0]')

Nullable parents

If the parent store is nullable, then the child store will also be nullable:

type User = {
    name: {
        first: string
        last: string
    }
    relations: {
        partner?: User
    }
}

const maybeUser = writable<User | undefined>(undefined)
// Writable<string | undefined>
const firstName = keyed(maybeUser, 'name.first')

Nullable properties

Properties are accessed with optional chaining behavior:

const user = writable(initUser)
// Writable<Name | undefined>
const partnerName = keyed(user, 'relations.partner.name')

Array Operations

The store supports array operations through bracket notation:

const list = writable(['a', 'b', 'c'])
const firstItem = keyed(list, '[0]')
const lastItem = keyed(list, '[-1]') // Access last element

TypeScript

keyed provides full TypeScript support with type inference from the keypath:

const user = writable(initUser)
// Writable<string>
const firstName = keyed(user, 'name.first')

Type hints are provided for keypaths up to a depth of 3:

keyed(user, '...');
            ┌───────────────────────────────┐
            │ • name                        │
            │ • name.first                  │
            │ • name.last                   │
            │ • relations                   │
            │ • relations.partner           │
            │ • relations.partner.name      │
            └───────────────────────────────┘

Note: The depth limit is due to TypeScript's requirement that structured types be generated statically. While deeper paths will work, they won't show in autocomplete.

Use Cases

Context Stores

Perfect for setting store properties in component context:

<!-- Settings.svelte -->
<script>
    setContext('profileSettings', keyed(settings, 'profile'))
</script>

<GeneralSettings />
<ProfileSettings />

Action Parameters

Ideal for passing store segments to Svelte actions:

<!-- Settings.svelte -->
<script>
    const stats = writable({ userClicks: 0, userTaps: 0 })
    const clicks = keyed(stats, 'userClicks')
</script>

<div use:trackClicks={clicks} />

Store Composition

Combine with other store operations for complex state management:

const settings = writable({ theme: 'light', fontSize: 16 })
const theme = keyed(settings, 'theme')
const isDarkMode = derived(theme, $theme => $theme === 'dark')