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

@godaddy/split-node-serializer

v2.0.10

Published

[![Join Slack](https://img.shields.io/badge/Join%20us%20on-Slack-e01563.svg)](https://godaddy-oss-slack.herokuapp.com/)

Downloads

21

Readme

Join Slack

split-node-serializer

Fetches split definitions and segments from Split.io and serializes them into a set of strings that the JavaScript SDK can consume.

Installation

Install via npm:

$ npm i @godaddy/split-node-serializer --save

Usage

Use this package in your server-side Node.js environment. The serializer exposes:

  1. a Poller that periodically requests raw experiment configuration data from Split.io. Requests happen in the background and the poller caches the latest data in local memory.
  2. a DataSerializer that reads from the poller's cache, serializes the data, and returns it in a script to be injected into a client's HTML.

Constructor

Create an instance of Poller and DataSerializer:

const { Poller, DataSerializer } = require('@godaddy/split-node-serializer')

const poller = new Poller({
  splitioApiKey: 'YOUR_API_KEY',
  pollingRateSeconds: 600,
  serializeSegments: false
})

const dataSerializer = new DataSerializer({ poller })

The following option properties are available to the Poller:

| Property | Description | |-------------------------------|-------------| | splitioApiKey | The Split.io SDK key for the environment your app is running in. (required) | | pollingRateSeconds | The interval at which to poll Split.io. Defaults to 300 (5 minutes). | | serializeSegments | Whether or not to fetch segment configuration data. Defaults to false. |

Serializing segments

Segments are pre-defined groups of customers that features can be targeted to. More info here.

Note: Requesting serialized segments will increase the size of your response. Segments can be very large if they include all company employees, for example.

Methods

start

Make an initial request for changes and start polling for raw configuration data every pollingRateSeconds:

poller.start()

stop

To stop the poller:

poller.stop()

The poller emits an error event on errors from the Split.io API.

generateSerializedDataScript

generateSerializedDataScript is an async method that will read the latest data from the cache and return a script that adds serialized data to the window.__splitCachePreload object. The serialized data will be used to determine cohort allocations.

generateSerializedDataScript accepts the following arguments:

| Property | Description | |-------------------------------|-------------| | splits | Array of strings that, if included, filters the splitsData (Optional) | | preloadLocation | The property on the window object where the data is stored. Defaults to __splitCachePreload (Optional) |

const serializedDataScript = await dataSerializer.generateSerializedDataScript()

console.log(serializedDataScript)

//<script>
//  window.__splitCachePreload = {
//    splitsData: {"split-1-name":'{"name":"split-1-name","status":"bar"}',"split-2-name":'{"name":"split-2-name","status":"baz"}'},
//    since: 1,
//    segmentsData: {"test-segment":'{"name":"test-segment","added":["foo","bar"]}'},
//    usingSegmentsCount: 2
//  };
//</script>

Note: Though this is an async method, there will only be a Split.io API call if you have serializeSegments set to true and are passing in a unique splits parameter that this instance's method has not received before.

Testing

Run the linter:

$ npm run lint

Run unit tests:

$ npm test

Generate a coverage report:

$ npm run coverage

License

MIT