UNPKG

@daiso-tech/core

Version:

The library offers flexible, framework-agnostic solutions for modern web applications, built on adaptable components that integrate seamlessly with popular frameworks like Next Js.

88 lines (87 loc) 1.97 kB
/** * @module Namespace */ import { type OneOrMore } from "../utilities/_module-exports.js"; /** * @internal */ type KeySettings = { prefixArr: Array<string>; key: string; delimeter: string; }; /** * * IMPORT_PATH: `"@daiso-tech/core/namespace"` */ export declare class Key { private readonly prefixArr; private readonly key; private readonly delimeter; /** * * @internal */ constructor(settings: KeySettings); get(): string; toString(): string; } /** * * IMPORT_PATH: `"@daiso-tech/core/namespace"` */ export type NamespaceSettings = { /** * @default ":" */ delimeter?: string; /** * @default "_rt" */ rootIdentifier?: string; }; /** * The `Namespace` class adds prefixes/suffixes to keys to avoid conflicts and group related items. * * IMPORT_PATH: `"@daiso-tech/core/namespace"` * * @example * ```ts * 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()); * * ``` */ export declare class Namespace { private readonly root; private readonly delimeter; private readonly rootIdentifier; constructor(root: OneOrMore<string>, settings?: NamespaceSettings); setDelimeter(delimeter: string): Namespace; setRootIdentifier(identifier: string): Namespace; appendRoot(str: OneOrMore<string>): Namespace; prependRoot(str: OneOrMore<string>): Namespace; private validate; private getKeyPrefixArray; toString(): string; create(key: string): Key; } export {};