https://github.com/unlaunch/javascript-sdk
Unlaunch JavaScript Library
https://github.com/unlaunch/javascript-sdk
feature-flags javascript-sdk
Last synced: 3 months ago
JSON representation
Unlaunch JavaScript Library
- Host: GitHub
- URL: https://github.com/unlaunch/javascript-sdk
- Owner: unlaunch
- Created: 2020-12-08T04:21:48.000Z (over 5 years ago)
- Default Branch: develop
- Last Pushed: 2021-02-24T04:45:45.000Z (about 5 years ago)
- Last Synced: 2025-10-25T04:49:53.494Z (5 months ago)
- Topics: feature-flags, javascript-sdk
- Language: JavaScript
- Homepage: https://docs.unlaunch.io/docs/sdks/javascript-library
- Size: 1.69 MB
- Stars: 5
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# Unlaunch JavaScript Library
| main | develop |
|---------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| [](https://travis-ci.com/unlaunch/javascript-sdk) | [](https://travis-ci.com/unlaunch/javascript-sdk) |
## Overview
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.
### Important Links
- To create feature flags to use with JavaScript Library, login to your Unlaunch Console at [https://app.unlaunch.io](https://app.unlaunch.io)
- [Official Guide - Read this first](https://docs.unlaunch.io/docs/sdks/javascript-library)
- [npmjs](https://www.npmjs.com/package/unlaunch-js-client-lib)
### Compatibility
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.
#### Browser Support
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.
## Getting Started
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.
### Embed directly in your HTML
```javascript
```
### Integrate with a JavaScript framework
Or using, `npm install`:
```
npm i unlaunch-js-client-lib
```
and then,
```javascript
import * as ULClient from "unlaunch-js-client-lib";
```
Here's how you'd use JavaScript library in an HTML page.
```javascript
const flag = ''
const apiKey = ''
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](https://docs.unlaunch.io/docs/sdks/javascript-library).
## Build instructions
### Requirements
- npm version 6.14.5 or higher
- node version 12.18.2 or higher
The library has dependency in [javascript-sdk-common](https://github.com/unlaunch/javascript-sdk-common) project. After cloning both the repos, follow these steps.
1. Go to `javascript-sdk-common` directory and run `npm install` and then run `npm run build`
2. Go to `javascript-sdk-common` directory and run `npm link`. Then go to the `javascript-client-sd`k and type `npm link unlaunch-js-sdk-common`
3. Install `javascript-client-sdk` dependencies by running `npm install` and then build `npm run build`
4. Go to your project directory and run `npm link `
5. In your project directory run `npm install`
6. Import `unlaunch-js-client-lib` in your project or use the minified JavaScript library.
### Publish to npm
- npm login
- npm publish
## Customization
You can use options to customize the client. For more information, see the [official guide](https://docs.unlaunch.io/docs/sdks/javascript-library#client-configuration).
```javascript
var options = {
localStorage: true,
offline: false,
requestTimeoutInMillis: 1000
}
```
### Offline Mode
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](https://docs.unlaunch.io/docs/sdks/javascript-library#offline).
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) to find how you can contribute.
## License
Licensed under the Apache License, Version 2.0. See: [Apache License](LICENSE.md).
## Publish Releases on npmjs
TODO
## About Unlaunch
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](https://unlaunch.io). You can sign up to get started for free at [https://app.unlaunch.io/signup
](https://app.unlaunch.io/signup).
## More Questions?
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**.