main | develop |
---|---|
The Unlaunch JavaScript Library provides JavaScript API to access Unlaunch feature flags and other features. Using this library, you can easily build JavaScript apps that can evaluate feature flags, dynamic configurations, and more.
- To create feature flags to use with JavaScript Library, login to your Unlaunch Console at https://app.unlaunch.io
- Official Guide - Read this first
- npmjs
The Unlaunch JavaScript library doesn't require or depend on any specific JavaScript framework. You can use it with your favorite framework like Angular. If you want to integrate with React, we have a separate React SDK available.
The Unlaunch Javascript Library can be used in all major browsers. However, some browsers may not support some features that the library uses, such as ES6 Promises. You may have to use polyfill if your target users use browsers that do not support ES6 Promise.
Here is a simple example.
First, add the library to your project. To load the JavaScript Library, include the following in the or tag of your webpage.
<script crossorigin="anonymous" src="https://unpkg.com/unlaunch-js-client-lib/dist/ulclient.min.js">
</script>
Or using, npm install
:
npm i unlaunch-js-client-lib
and then,
import * as ULClient from "unlaunch-js-client-lib";
Here's how you'd use JavaScript library in an HTML page.
const flag = '<YOUR_FLAG_KEY>'
const apiKey = '<PROVIDE_BROWSER_PUBLIC_KEY_FOR_YOUR_PROJECT>'
const identity = 'anonymous' // Use special anonymous identity which generates a unique UUID
const options = {
localStorage: true, // Use local storage
logLevel: 'debug' // Available logLevels are ['error','warn','info','debug','none']. Default logLevel is 'error'. To disable logging use 'none'. If empty ''
// loglevel is provided all logs are printed.
// Log levels severity are in the order ['error','warn','info','debug']. Error has high severity and debug has lowest.
// All logs which have high severity level then the level provided will be printed. So if logLevel info is selected 'error', 'warn' and
// 'info' logs are printed. If 'debug' is provided only debug logs are printed.
}
const ulclient = ULClient.initialize(
apiKey,
[flag],
identity,
null,
options
);
ulclient.on('ready', function () {
let variation = ulclient.variation(flag);
console.log(`[UL] Variation is ${variation}`)
const details = ulclient.variationDetail(flag);
console.log(`[UL] Evaluation reason is ${details.reason}`)
if (variation === 'on') {
// Show the feature
} else {
// Hide the feature
}
For more information, see the official guide.
- npm version 6.14.5 or higher
- node version 12.18.2 or higher
The library has dependency in javascript-sdk-common project. After cloning both the repos, follow these steps.
- Go to
javascript-sdk-common
directory and runnpm install
and then runnpm run build
- Go to
javascript-sdk-common
directory and runnpm link
. Then go to thejavascript-client-sd
k and typenpm link unlaunch-js-sdk-common
- Install
javascript-client-sdk
dependencies by runningnpm install
and then buildnpm run build
- Go to your project directory and run
npm link <path-to-js-client-sdk-directory>
- In your project directory run
npm install
- Import
unlaunch-js-client-lib
in your project or use the minified JavaScript library.
- npm login
- npm publish
You can use options to customize the client. For more information, see the official guide.
var options = {
localStorage: true,
offline: false,
requestTimeoutInMillis: 1000
}
You can start the SDK in offline mode for testing purposes. In offline mode, flags aren't downloaded from the server and no data is sent. All calls to variation()
or its variants will return control
. Read more in the official guide.
Please see CONTRIBUTING to find how you can contribute.
Licensed under the Apache License, Version 2.0. See: Apache License.
TODO
Unlaunch is a Feature Release Platform for engineering teams. Our mission is allow engineering teams of all sizes to release features safely and quickly to delight their customers. To learn more about Unlaunch, please visit www.unlaunch.io. You can sign up to get started for free at https://app.unlaunch.io/signup .
At Unlaunch, we are obsessed about making it easier for developers all over the world to release features safely and with confidence. If you have any questions or something isn't working as expected, please email unlaunch@gmail.com.