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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@item-enonic-types/lib-feature-toggles

v1.0.0

Published

Type definitions for lib-feature-toggles

Readme

Feature Toggles Lib

Library for creating Feature Toggles, and checking if they have been enabled/disabled by the Feature Toggles App. A feature toggle is is a boolean flag that can be used in your application to enable/disable functionality.

Common usages of feature toggles are:

  • Merging partially implemented features into your codebase, but not exposing them to the end users
  • A feature switch (kill switch?) that can be used by the admins/editors
  • Enable a feature on the "draft" branch, but not on "master".

[!TIP] We recommend that you use the Feature Toggle App to toggle feature flags instead of using this library to do it programmatically.

Installation

To install this library you need to add a new dependency to your app's build.gradle file.

Gradle

repositories {
  maven { url "https://repo.itemtest.no/releases" }
}

dependencies {
  include "no.item:lib-xp-feature-toggles:1.0.0"
}

TypeScript

Install the TypeScript-types with the following command:

npm install --save-dev @item-enonic-types/lib-features-toggles

By adding the following changes to your tsconfig.json you will get TypeScript-support for this library.

{
  "compilerOptions": {
    "paths": {
+     "/lib/feature-toggles": ["../../../node_modules/@item-enonic-types/lib-feature-toggles"],
    }
  }
}

Usage

isEnabled()

Checks if the feature is enabled for the current space. Where the space by default is your apps name. You can also name your own spaces if you want to configure it per site.

isEnabled will automatically create the space and the feature with a default value if it's called in a draft context.

import { isEnabled } from "/lib/feature-toggles";

const isMyFeatureEnabled1: boolean = isEnabled({
  featureKey: "my-feature",
  defaultValue: false,
  spaceKey: app.name,
});

// This shorthand will yield the the same result as the example above
const isMyFeatureEnabled2: boolean = isEnabled("my-feature");

create()

Creates spaces and features for your app. This should usually be run from your main.js file, to initialize spaces and features you're going use. Spaces and features will automatically be created by the isEnabled() function, but if you're using the companion app for this library, they won't show up there until someone hits that part of your code.

This will only create the spaces and features for "draft" contexts, and not "master", you'll have to use the companion app or publishFeature() for that.

This will not update features that already exists, for that you'll have to use update().

import { create } from "/lib/feature-toggles";

// Create a single new feature flag in the default space (`app.name`)
create({
  name: "my-feature",
  enabled: true,
});

// Create multiple new feature flags in the default space (`app.name`)
create([
  {
    name: "my-feature",
    enabled: false,
  },
  {
    name: "my-second-feature",
    enabled: true,
  },
]);

// Create feature flags in a different "space"
const siteBasedSpaceKey = getSite()._name;

create(
  [
    {
      name: "my-feature",
      enabled: false,
      spaceKey: siteBasedSpaceKey,
    },
    {
      name: "my-second-feature",
      enabled: true,
      spaceKey: siteBasedSpaceKey,
    },
  ],
);

update()

Enable/Disable a feature in draft

import { update } from "/lib/feature-toggles";

// Enable the feature "my-feature" in the default space (`app.name`)
update({
  name: "my-feature",
  enabled: true
});

// Disable the feature "my-feature" in a space based on the current site
const siteBasedSpaceKey = getSite()._name;

update(
  {
    name: "my-feature",
    enabled: false,
    spaceKey: siteBasedSpaceKey,
  },
);

publish()

Publishes feature from "draft" to "master".

import { publish } from "/lib/feature-toggles";

// Publish a feature with a given `id` to go live on your site
publish("9800b7a6-ebe6-4332-ac24-c70cd7ecf596");

// Publish a feature in the default space to go live
publish({
  featureKey: "my-feature",
  spaceKey: app.name,
})

// Publish to a different space then `app.name`
const siteBasedSpaceKey = getSite()._name;

publish({
  featureKey: "my-feature",
  spaceKey: siteBasedSpaceKey
})

Deploying

Building

To build the project run the following code

./gradlew build

Deploy locally

Deploy locally for testing purposes:

./gradlew publishToMavenLocal

Deploy to Maven

./gradlew publish -P com.enonic.xp.app.production=true