Storage

Storage

Represents a modules storage.

Constructor

new Storage(separatoropt, panicopt)

Creates a new instance of Storage.
Parameters
Name Type Attributes Default Description
separator string <optional>
/ Namespace separator.
panic boolean <optional>
true Indicates whether it needs to throw an error when module not found.

Methods

addItem(module) → {Storage}

Adds a module to a storage.
Parameters
Name Type Description
module Module Target module to add.
Throws
Error
If a module with a same path already exists.
Returns
Returns current instance of Storage.
Type
Storage

clear(namespaceopt) → {Storage}

Clears a storage. If namespace name is passed - clears a namespace by a given name.
Parameters
Name Type Attributes Default Description
namespace string <optional>
null Namespace name to clear.
Returns
Returns current instance of Storage.
Type
Storage

contains(path) → {boolean}

Determines whether a module exists by a given path.
Parameters
Name Type Description
path string Module full path.
Returns
Value that determines whether a module exists by a given path.
Type
boolean

forEachIn(namespace) → {Storage}

Iterates over modules in a given namespace.
Parameters
Name Type Description
namespace string Namespace name.
Throws
Error
If panic="true" and namespace not found.
Returns
Returns current instance on Storage.
Type
Storage

getItem(fullPath) → {Module}

Finds a module by a given path.
Parameters
Name Type Description
fullPath string Module full path.
Throws
Error
If panic="true" and module not found.
Returns
Found module.
Type
Module

namespaces(parentopt) → {Array}

Returns an array of registered namespaces.
Parameters
Name Type Attributes Description
parent string <optional>
Parent namespace.
Returns
An array of registered namespaces.
Type
Array

size(namespaceopt) → {number}

Returns size of a storage or namespace. If namespace was given, count of items inside this namespace will be returned.
Parameters
Name Type Attributes Description
namespace string <optional>
Namespace name
Returns
Size of a storage/namespace.
Type
number