What is launchdarkly-js-sdk-common?
The launchdarkly-js-sdk-common package is a JavaScript SDK for LaunchDarkly, a feature management platform that allows developers to control the release of features to users. This SDK provides the core functionality for interacting with LaunchDarkly's feature flagging and experimentation capabilities.
What are launchdarkly-js-sdk-common's main functionalities?
Initialize the SDK
This feature allows you to initialize the LaunchDarkly client with your environment key and user information. The client can then be used to interact with LaunchDarkly's feature flags.
const { initialize } = require('launchdarkly-js-sdk-common');
const client = initialize('YOUR_ENVIRONMENT_KEY', { key: 'user_key' });
Evaluate Feature Flags
Once the client is ready, you can evaluate feature flags using the `variation` method. This method takes the feature flag key and a default value, returning the flag's value for the user.
client.on('ready', () => {
const showFeature = client.variation('your-feature-flag-key', false);
console.log('Feature flag value:', showFeature);
});
Track Custom Events
This feature allows you to track custom events in LaunchDarkly. You can send event data that can be used for analytics and experimentation purposes.
client.track('custom-event-key', { customData: 'value' });
Close the Client
This feature allows you to close the LaunchDarkly client, ensuring that all pending events are sent before the application exits.
client.close();
Other packages similar to launchdarkly-js-sdk-common
unleash-client
The unleash-client package is a feature management client for the Unleash feature flagging system. It provides similar functionality to LaunchDarkly, allowing developers to control feature releases and track feature usage. Unlike LaunchDarkly, Unleash is an open-source solution that can be self-hosted.
flagr
Flagr is an open-source feature flagging and A/B testing tool. The flagr-client package allows developers to interact with the Flagr API to evaluate feature flags and track events. Flagr provides a similar feature set to LaunchDarkly but is designed to be self-hosted and customizable.
LaunchDarkly SDK for JavaScript - Common Package
This file contains the launchdarkly-js-sdk-common
package, which is used by the LaunchDarkly JavaScript, React, and Electron SDKs. Applications should not need to refer to this package directly, as it is loaded automatically as a dependency of the SDK packages.
Note that the TypeScript declaration file typings.d.ts
in this directory describes only the types and methods that are provided by the common package. The typings.d.ts
file in ldclient-js
imports all of these definitions, so application code can just import launchdarkly-js-client-sdk
.