@ima/core
Version:
IMA.js framework for isomorphic javascript application
62 lines • 2.35 kB
TypeScript
/**
* Namespace creation, manipulation and traversal utility. This utility is used
* to create semi-global shared namespaces for registering references to
* interfaces, classes and constants of the application to provide access to
* each other more easily than by using the ES6 import/export mechanism.
*/
export declare class Namespace {
#private;
[key: PropertyKey]: any;
/**
* Initializes the namespace provider.
*
* This is a private constructor, you should use the exported `ns`
* instance to create and use namespaces (see the examples).
*
* @private
* @example
* import { ns } from '@ima/core';
* ns.namespace('ima.core');
* ns.has('ima.core');
*/
/**
* Verifies that the specified path in namespace exists, creates it if it
* does not, and returns the value at the specified path in the namespace.
*
* The method recursively creates all path parts in the namespaces as empty
* plain objects for all path parts that do not exist yet, including the
* last one. This means, that if called with a non-existing namespace path
* as an argument, the return value will be the last created namespace
* object.
*
* @param path The namespace path.
* @return The value at the specified path in the namespace.
*/
namespace<V = any>(path: string): V;
/**
* Verifies that the specified namespace path point to an existing
* namespace or terminal value.
*
* @param path The namespace path to test.
* @return `true` if the namespace or terminal value exists
* at the specified path.
*/
has(path: string): boolean;
/**
* Return value for the specified namespace path point or undefined if path is not type of string
*
* @param path The namespace path to get.
* @return The value at the specified path in the namespace or undefined for any non-string path
*/
get<V = any>(path: string): V | undefined;
/**
* Set value for the specified namespace path point.
*
* @param path The namespace path to set.
* @param value
*/
set<V>(path: string, value: V): void;
}
export declare const ns: Namespace;
export declare function getNamespace(): Namespace;
//# sourceMappingURL=Namespace.d.ts.map