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

@lagarsoft/lgsft-flags

v0.1.3

Published

React SDK for lgsft-flags — a self-hosted feature flag system. Wrap your app in FlagProvider and call useFlag() to toggle features per user without redeploying.

Readme

@lagarsoft/lgsft-flags

React SDK for lgsft-flags — a self-hosted feature flag system. Toggle features on or off per user without redeploying.

How it works

Your React app fetches all flags on mount via FlagProvider. The flags are evaluated server-side by the Lagarsoft flags dashboard against targeting rules (user lists, attribute conditions), and returned as a simple { flagKey: boolean } map. No business logic runs in the client.

React app  →  FlagProvider mounts
           →  GET {dashboardUrl}/api/flags?userId=alice&attr[plan]=pro
           →  Lagarsoft flags dashboard evaluates rules against DB
           →  returns { 'dark-mode': true, 'new-checkout': false, ... }
           →  useFlag('dark-mode') returns true

Requirements

Installation

npm install @lagarsoft/lgsft-flags
# or
pnpm add @lagarsoft/lgsft-flags

Quick start

1. Wrap your app in FlagProvider

import { FlagProvider } from '@lagarsoft/lgsft-flags'

export function App() {
  return (
    <FlagProvider
      apiUrl="https://your-Lagarsoft flags dashboard.example.com"
      apiKey="lf_your_api_key_here"
      userContext={{ userId: 'user_123' }}
    >
      <YourApp />
    </FlagProvider>
  )
}

2. Use flags in any component

import { useFlag } from '@lagarsoft/lgsft-flags'

function CheckoutButton() {
  const { value, loading } = useFlag('new-checkout-flow')

  if (loading) return null
  return value ? <NewCheckout /> : <LegacyCheckout />
}

API

<FlagProvider>

Fetches all flags on mount and provides them via React context. Re-fetches when apiUrl, apiKey, or userContext.userId changes.

| Prop | Type | Required | Description | |---|---|---|---| | apiUrl | string | Yes | Base URL of your Lagarsoft flags dashboard | | apiKey | string | Yes | API key created in the Lagarsoft flags dashboard | | userContext | UserContext | No | User info for targeted flag evaluation | | onError | (error: Error) => void | No | Called when the flags fetch fails | | children | ReactNode | Yes | Your app tree |

UserContext

type UserContext = {
  userId?: string                                    // matched by USER_LIST rules
  attributes?: Record<string, string | number | boolean>  // matched by ATTRIBUTE_MATCH rules
}

Example with attributes:

<FlagProvider
  apiUrl="https://your-Lagarsoft flags dashboard.example.com"
  apiKey="lf_your_api_key_here"
  userContext={{
    userId: currentUser.id,
    attributes: {
      plan: currentUser.plan,        // e.g. 'pro'
      country: currentUser.country,  // e.g. 'US'
      beta: currentUser.isBeta,      // e.g. true
    },
  }}
>
  <App />
</FlagProvider>

useFlag(key, defaultValue?)

Returns an object with the flag value plus loading and error states.

defaultValue (default: false) is returned while flags are loading or if the fetch fails.

const { value, loading, error } = useFlag('my-feature')
const { value } = useFlag('my-feature', true)  // default to true while loading

| Property | Type | Description | |---|---|---| | value | boolean | Flag value, or defaultValue while loading / on error | | loading | boolean | true while the initial fetch is in progress | | error | Error \| null | Set if the fetch failed, otherwise null |

Migration note: Prior to this version, useFlag returned a boolean directly. Update existing usages from const enabled = useFlag('key') to const { value: enabled } = useFlag('key').


useFlagContext()

Returns the full context object, useful when you need loading or error state.

const { flags, loading, error } = useFlagContext()

if (loading) return <Spinner />
if (error) return <ErrorBanner />

const isEnabled = flags['my-feature'] ?? false

| Property | Type | Description | |---|---|---| | flags | Record<string, boolean> | All flag values for the current user | | loading | boolean | true while the initial fetch is in progress | | error | Error \| null | Set if the fetch failed, otherwise null |

Getting an API key

  1. Open your lgsft-flags Lagarsoft flags dashboard
  2. Select a project and environment
  3. Go to API Keys → create a new key
  4. Copy the lf_... value — it is only shown once

Targeting rules

The Lagarsoft flags dashboard supports two rule types that are evaluated against the userContext you provide:

  • User list — match specific user IDs or emails (pass userContext.userId)
  • Attribute match — match users based on attribute values (pass userContext.attributes)

Rules are evaluated in order; the first match wins. If no rule matches, the flag falls back to its default enabled/disabled state.

TypeScript

The package ships with full type declarations built with tsup. No additional @types packages are needed.