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 🙏

© 2024 – Pkg Stats / Ryan Hefner

osff-js-sdk

v1.0.7

Published

This is a client-side api to compliment a feature-flagging backend service that I have made as part of a personal project. This package is not recommended for production-level/enterprise environments.

Downloads

9

Readme

OSFT Client API

Javascript SDK for opensourcefeaturetoggles.com

Other Repositories that are a part of this project

React SDK

Admin Website

Node Backend

How to Use

1. Installations

npm install osff-js-sdk
# or 
yarn add osff-js-sdk 

2. Initialize the SDK

Somewhere in your application, instantiate the FeaureToggleClient with your apiKey and preferred refreshRate (in seconds). Then call start to send the inital request for flags and start pinging the server for subsequent updates.

import FeatureToggleClient from "osff-js-sdk"

const client = new FeatureToggleClient({
    apiKey : 'YOUR-API-KEY',
    refreshRate : '5s',
})

// Send initial request and continue pinging server for updates
client.start()

3. Let the client synchronize

You should wait for the client's ready event to be fired before attempting to check for active features on the client. Attempting to check for flags before the client is initialized could lead to the consumer reading invalid flag data.

client.addEventListener('ready', () => {
    if (client.getFlag('feature.variable')) {
        console.log('feature.variable is enabled!')
    }
    else {
        console.log('feature.variable is disabled!')
    }
})

Listening for events

The client emits 4 events.

  • ready - The client has loaded the initial flags from the server and is ready to serve up to date flags
  • update - The server has notified the client that there has been an update to one or more of the flags
  • error - The client has encountered an error while attmepting to retrieve data from the server
  • end - The client has been turned off and will no longer attempt to fetch data from the server. Whatever data was received in its final request before the end event is emitted is the data that the client will use until it is reconnected to the server.

The FeatureToggleClient extends the EventTarget class, which means that you can listen to events by using client.addEventListener('event-name', callBack).