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 🙏

© 2026 – Pkg Stats / Ryan Hefner

labelcontainer

v1.0.0

Published

A lightweight centralized label management utility for TypeScript/JavaScript applications

Readme

LabelContainer

test_workflow npm_github_publish_workflow npm_publish_workflow npm version

A lightweight centralized label management utility for TypeScript/JavaScript applications.
LabelContainer provides a structured way to store, retrieve, and localize UI labels across your app using a simple API and a built-in fallback mechanism.


✨ Features

  • 🧩 Centralized label storage — manage all text labels in one place
  • 🌐 Multi-language support — organize translations by language
  • 📄 Page-level scoping — manage labels per page or component
  • 🧠 Built-in fallbacks — automatic fallback to GLOBAL page or English (en) labels
  • ♻️ Singleton pattern — maintain one consistent label state throughout your app
  • 🧪 Full TypeScript support with included types (Labels, LangLabels, LabelBlock)

📦 Installation

npm install labelcontainer
# or
yarn add labelcontainer

🧠 Core Concepts

1. Labels Structure

Labels follow a two-level nested map:

  1. First layer → groups labels by page (e.g. HOME, DETAILS, SEARCH)
  2. Second layer → groups labels by language code (e.g. en, fr, sp)

Each language block (LabelBlock) is a simple object mapping label keys to string values.

import { Labels } from 'labelcontainer/build/types';

export const LABELS: Labels = {
  GLOBAL: {
    en: {
      title: "Test Title",
      card_msg: "Lorem ipsum dolor sit amet.",
    },
    sp: {
      title: "Título de la Prueba",
      card_msg: "Mensaje de ejemplo.",
    },
  },
  PAGE_A: {
    en: {
      title: "Page A Title",
      button_text: "Submit",
    },
  },
};

Tip: Always include English (en) as a fallback language to ensure coverage.

⚙️ Initialization

Since LabelContainer is a singleton, you only initialize it once:

import LabelContainer from 'labelcontainer';
import { LABELS } from './labels';

const labelInstance = LabelContainer.getInstance({
  labels: LABELS,
  page: 'PAGE_A',
  language: 'en',
});

Subsequent calls to getInstance() will return the same instance.

🗺️ Page and Language Management

You can update the current page or language anytime:

labelInstance.setPage('PAGE_A');
labelInstance.setLanguage('sp');

console.log(labelInstance.getPage());      // "PAGE_A"
console.log(labelInstance.getLanguage());  // "sp"

💬 Retrieving Labels

To fetch a label string, use:

labelInstance.getLabel('title'); // → "Título de la Prueba"

Fallback Behavior

When retrieving a label, LabelContainer automatically:

  1. Falls back to the GLOBAL page if the current page is not found.
  2. Falls back to en (English) if the requested language doesn’t exist.
  3. Returns the key itself if the label cannot be found anywhere.
labelInstance.setPage('UNKNOWN_PAGE');
labelInstance.setLanguage('de');
labelInstance.getLabel('title'); // → "Test Title" (from GLOBAL → en)

🔍 Checking Label Availability

You can check whether a label exists:

labelInstance.hasLabel('button_text'); // → true
labelInstance.hasLabel('missing_key'); // → false

🌐 Listing All Available Languages

Retrieve a list of all languages defined across your label set:

labelInstance.getAllLanguages(); 
// → ['en', 'sp']

🧪 Testing

Unit tests are written in Jest. To run them locally:

npm install
npm test

The test suite covers:

  • Singleton behavior
  • Page/language management
  • Label retrieval and fallbacks
  • Label existence and language listing

🧱 Type Definitions

| Type | Description | | ------------ | -------------------------------------------------------------------- | | LabelBlock | Record<string, string> – map of label keys to text | | LangLabels | Record<string, LabelBlock> – map of language codes to label blocks | | Labels | Record<string, LangLabels> – map of pages to language blocks |

🧭 Example Usage

import LabelContainer from 'labelcontainer';
import { LABELS } from './labels';

const labelInstance = LabelContainer.getInstance({ labels: LABELS });

labelInstance.setPage('PAGE_A');
labelInstance.setLanguage('en');

console.log(labelInstance.getLabel('title')); // "Page A Title"

labelInstance.setLanguage('sp');
console.log(labelInstance.getLabel('title')); // "Título de la Prueba"

🧩 Future Improvements

Planned enhancements for future versions:

  • mergeLabels() — merge new label sets dynamically
  • reset() — clear singleton instance for reinitialization (useful in testing or multi-app contexts)

📄 License

MIT © nordic96