The Namespace class adds prefixes/suffixes to keys to avoid conflicts and group related items.

IMPORT_PATH: "@daiso-tech/core/namespace"

import { Namespace } from "@daiso-tech/core/namspace";

const namespace = new Namespace("@my-namespace");

// Logs "@my-namespace:_rt"
console.log(namespace.toString());

const key = namespace.create("my-key");

// Logs "my-key"
console.log(key.get())

// Logs "@my-namespace:_rt:my-key"
console.log(key.toString())

// You can extend the root
const newNamespace = namespace.appendRoot("sub");

// Logs "@my-namespace:sub:_rt"
console.log(newNamespace.toString());

Implements

Constructors

Methods

  • Creates a new IKey object within this namespace. The returned key will include this namespace's prefix.

    Parameters

    • key: string

      The raw key string (namespace prefix will be added automatically)

    Returns IKey

    A new namespaced key instance

  • Gets the namespace prefix string. This prefix is automatically prepended to all keys created by this namespace.

    Returns string

    The namespace prefix