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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@togglely/sdk-svelte

v1.2.4

Published

Svelte SDK for Togglely - Feature toggles with stores

Readme

Togglely Svelte SDK

Svelte stores and actions for Togglely feature flag management.

Features

  • 🎣 Svelte Stores - toggle, stringToggle, numberToggle, jsonToggle
  • 🎯 Actions - use:featureToggle for declarative UI
  • 💾 Offline Support - Built-in offline fallback
  • 🔒 TypeScript - Full type safety
  • Reactive - Automatic updates with Svelte's reactivity

Installation

npm install @togglely/sdk-svelte

Quick Start

<!-- App.svelte -->
<script>
  import { initTogglely, toggle } from '@togglely/sdk-svelte';
  
  // Initialize once (usually in your root layout)
  initTogglely({
    apiKey: 'your-api-key',
    project: 'my-project',
    environment: 'production',
    baseUrl: 'https://togglely.io',
  });
  
  // Use the store
  const isEnabled = toggle('new-feature', false);
</script>

{#if $isEnabled}
  <NewFeature />
{:else}
  <OldFeature />
{/if}

Initialization

import { initTogglely, getTogglelyClient, destroyTogglely } from '@togglely/sdk-svelte';

// Initialize
initTogglely({
  apiKey: 'your-api-key',
  project: 'my-project',
  environment: 'production',
  baseUrl: 'https://togglely.io',
  tenantId: 'brand-a',              // For multi-brand projects
  offlineJsonPath: '/toggles.json', // Offline fallback
});

// Access client directly
const client = getTogglelyClient();

// Cleanup on app destroy
destroyTogglely();

Stores

toggle

Boolean toggle store:

<script>
  import { toggle } from '@togglely/sdk-svelte';
  const isEnabled = toggle('new-feature', false);
</script>

{#if $isEnabled}
  <div>New Feature!</div>
{/if}

stringToggle

String toggle store:

<script>
  import { stringToggle } from '@togglely/sdk-svelte';
  const message = stringToggle('welcome-message', 'Hello!');
</script>

<h1>{$message}</h1>

numberToggle

Number toggle store:

<script>
  import { numberToggle } from '@togglely/sdk-svelte';
  const limit = numberToggle('max-items', 10);
</script>

<p>Max items: {$limit}</p>

jsonToggle

JSON toggle store:

<script>
  import { jsonToggle } from '@togglely/sdk-svelte';
  const config = jsonToggle('app-config', { theme: 'dark' });
</script>

<div data-theme={$config.theme}>
  Content
</div>

toggles

All toggles store:

<script>
  import { toggles } from '@togglely/sdk-svelte';
  const all = toggles();
</script>

{#each Object.entries($all) as [key, toggle]}
  <p>{key}: {toggle.enabled ? 'ON' : 'OFF'}</p>
{/each}

togglelyState

SDK state store:

<script>
  import { togglelyState } from '@togglely/sdk-svelte';
  const state = togglelyState();
</script>

{#if !$state.isReady}
  <p>Loading...</p>
{:else if $state.isOffline}
  <p>Offline mode</p>
{/if}

Actions

featureToggle

<script>
  import { featureToggle } from '@togglely/sdk-svelte';
</script>

<div use:featureToggle={'new-feature'}>
  Only visible when enabled
</div>

Context

import { setTogglelyContext, getTogglelyContext, clearTogglelyContext } from '@togglely/sdk-svelte';

// Set targeting context
setTogglelyContext({ userId: '123', country: 'DE' });

// Get current context
const context = getTogglelyContext();

// Clear context
clearTogglelyContext();

SSR (SvelteKit)

// src/lib/togglely.ts
import { initTogglely } from '@togglely/sdk-svelte';

export function loadTogglely() {
  initTogglely({
    apiKey: import.meta.env.VITE_TOGGLELY_APIKEY,
    project: 'my-project',
    environment: 'production',
    baseUrl: 'https://togglely.io',
  });
}
<!-- src/routes/+layout.svelte -->
<script>
  import { browser } from '$app/environment';
  import { initTogglely } from '@togglely/sdk-svelte';
  
  if (browser) {
    initTogglely({
      apiKey: import.meta.env.VITE_TOGGLELY_APIKEY,
      project: 'my-project',
      environment: 'production',
      baseUrl: 'https://togglely.io',
    });
  }
</script>

<slot />

Build-Time JSON Generation

{
  "scripts": {
    "build": "togglely-pull --apiKey=$TOGGLELY_APIKEY --project=my-project --environment=production --output=./static/toggles.json && vite build"
  }
}
// app.ts
initTogglely({
  apiKey: 'your-api-key',
  project: 'my-project',
  environment: 'production',
  baseUrl: 'https://togglely.io',
  offlineJsonPath: '/toggles.json',
});

FeatureToggle Component Example

Create your own wrapper component:

<!-- FeatureToggle.svelte -->
<script>
  import { toggle } from '@togglely/sdk-svelte';
  
  export let name;
  export let defaultValue = false;
  
  const isEnabled = toggle(name, defaultValue);
</script>

{#if $isEnabled}
  <slot />
{:else}
  <slot name="fallback" />
{/if}
<!-- Usage -->
<FeatureToggle name="new-feature">
  <NewVersion />
  <svelte:fragment slot="fallback">
    <OldVersion />
  </svelte:fragment>
</FeatureToggle>

License

MIT