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

@toggles/experiments

v1.1.0

Published

Create, update, and delete experiments and determine if they are active for users/audiences.

Downloads

7

Readme

@toggles/experiments

Create, update, and delete experiments and determine if they are active for users/audiences.

Install

Install with npm.

$ npm i @toggles/experiments

Usage

const toggles = require('@toggles/experiments');
const client = toggles({
  apiKey: 'KEY',
})

async function main() {
  const {uuid} = await toggles.createExperiment({name: 'foo'})
  
  await toggles.updateExperiment(uuid, {name: 'bar', percent: 100})

  const experiments = await toggles.getExperiments()
  const experiment = await toggles.getExperimentById(uuid)

  const active = await toggles.isExperimentActive(uuid, {uniqueId: '[email protected]'})
}

Client Methods

createExperimentClient

Creates a new experiment client.

const options = {
  apiKey: 'string', // This comes from the Settings tab of the Dashboard.
}
const client = toggles.createClient(options)

createExperiment

Create a new experiment.

const params = {
  name: 'string',
}

const experiment = await client.createExperiment(params)

console.log(experiment)

// {
//   description: 'string', 
//   enabled: boolean, 
//   name: 'string', 
//   percent: number, 
//   uuid: 'string',
// }

deleteExperiment

Delete an experiment.

const success = await client.createExperiment(experiment.uuid)

console.log(success) // boolean

getAPIKey

Returns the provided API Key.

const key = client.getAPIKey()

getAPIUrl

Returns the provided API Url.

const url = client.getAPIUrl()

getExperiment, getExperimentById

Returns an experiment provided an experiment id.

const experiment = await client.getExperiment(experiment.uuid)

console.log(experiment)

// {
//   description: 'string', 
//   enabled: boolean, 
//   name: 'string', 
//   percent: number, 
//   uuid: 'string',
// }

getExperiments

Returns a list of all of the user's experiments.

const experiments = await client.getExperiments()

console.log(experiment)

// [
//   {
//     description: 'string', 
//     enabled: boolean, 
//     name: 'string', 
//     percent: number, 
//     uuid: 'string',
//   },
// ]

getLocalExperiment, getLocalExperimentByUuid

Returns an experiment from the localized experiments cache, or the global state.

const experiment = client.getLocalExperiment(experiment.uuid)

console.log(experiment)

// {
//   description: 'string', 
//   enabled: boolean, 
//   name: 'string', 
//   percent: number, 
//   uuid: 'string',
// }

isExperimentActive

Used to determine whether an experiment is active for the current user. If this method is used in a response handler, it will not use cookies, or the global state, unless expressly passed.

const params = {
  uniqueId: 'string', // optional
}

const active = await client.isExperimentActive(experiment.uuid, params)

console.log(active) // boolean

setAPIKey

Sets the API Key used to make requests to the API.

client.setAPIKey('KEY')

updateExperiment

Updates an experiment provided an experiment id and an experiment payload.

const params = {
  description: 'string',
  enabled: true, 
  name: 'string',
  percent: 100,
}

const experiment = await client.updateExperiment(experiment.uuid, params)

console.log(experiment)

// {
//   description: 'string', 
//   enabled: boolean, 
//   name: 'string', 
//   percent: number, 
//   uuid: 'string',
// }

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

License

Copyright © 2019 [] Licensed under the MIT license.


This file was generated by readme-generator on June 21, 2019.