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

vanity

v0.5.1

Published

Vanity Node.js client

Downloads

21

Readme

Vanity.js Node Client

Vanity(options)

Options are:

  • host - Host name of vanity server (may include port, e.g. "vanity.interna:443")
  • token - Access token
var Vanity = require("vanity"),
    vanity = new Vanity({ host: "vanity.internal:443", token: "secret token" });

vanity.activity({ actor: "Assaf", verb: "shared", object: "http://bit.ly/GLUa9S" })

Activity Stream

vanity.activity(activity)

  • id - Unique activity identifier. Optional.
  • actor - Activity actor is either a name (string) or an object.
  • verb - Activity performed.
  • object - Object associated with the activity, either display name (string) or an object. Optional.
  • location - Location name. Optional.
  • label - Labels. Optional.

Actor may specify id and/or displayName, and optionally also url (to profile) and image. If you don't have a displayName, just pass the id, and Vanity will make up a name for you. If you only have the display name, you can pass it directly as a string argument.

Object may specify url and/or displayName, and optionally also an image. If you don't have a displayName, url will be shown as the object descriptor. If you only have the display name, you can pass it directly as a string argument.

Image must specify url and may specify height and width in pixels.

For example:

vanity.activity({ actor: "Assaf", verb: "shared", object: "http://bit.ly/GLUa9S" })

vanity.activity({
  actor: {
    id: "assaf",
    displayName: "Assaf",
    url: "http://labnotes.org/"
  },
  verb: "shared",
  object: {
    displayName: "hjkl",
    url: "http://t.co/dKh54pQK",
    image: {
      url: "http://bit.ly/yq14vJ"
    }
  },
  location: "San Francisco, CA",
  labels: ["funny"]
})

Split Testing

vanity.split(id)

Returns a split test (SplitTest).

Arguments are:

  • id - Test identifier (alphanumeric/underscore/hyphen)

Returns a SplitTest object.

splittest.show(participant, alternative, callback)

Use this when choosing which alternative to show.

If you want Vanity to pick up which alternative to show, call with one argument (participant identifier) and it will return an alternative number. This request updates the server but returns immediately without waiting for response.

Example:

if (split.show(userId))
  render("optionB"); // Alternative 1 that we're testing
else
  render("optionA"); // Alternative 0, our base line

You can also call with participant and callback. This will contact the server, wait for response, and return the actual alternative number. This is the safest way to get the alternative.

Example:

split.show(userId, function(error, alternative) {
  if (alternative)
    render("optionB"); // Alternative 1 that we're testing
  else
    render("optionA"); // Alternative 0, our base line
})

You can also force a particular alternative by calling with participant, alternative number and optional callback. Note that an alternative can be set only once. With a callback, you'll get the alternative stored on the server, which may differ from the one passed as argument.

Example:

// These users always sees the second option
if (user.beta)
  split.show(userId, 1);
split.show(userId, function(error, alternative) {
  . . .
})

splittest.completed(participant, outcome, callback)

Use this to record conversion (goal completion).

Example:

split.completed(userId)

If you want to wait for response from the server, pass a callback as the second argument.

You can call this method multiple times for a given participant, only the first call has any affect. You can call this method without first calling show, and it will also add the participant to the experiment.

splittest.get(participant, callback)

Retrieve all that is known about a participant.

Arguments are:

  • participant - Participant identifier
  • callback - Call with error and result (null if no participant)

Result contains:

  • participant - Participant identifier
  • alternative - Alternative number
  • joined - When participant joined the test (Date)
  • outcome - Outcome
  • completed - When participant completed the test (Date)