<commit_before>import Symbol from 'es6-symbol';
import isNil from 'is-nil';
import isString from 'is-string';
import isFunction from 'is-function';
import forEach from 'for-each';
import Module from './module';
import path from './utils/path';

const MISSED_MODULE = 'Missed module';
const MISSED_MODULE_NAME = 'Missed module name';
const MISSED_NAMESPACE = 'Missed module namespace';
const MISSED_CALLBACK = 'Missed callback';
const INVALID_MODULE = 'Invalid module';
const INVALID_NAMESPACE = 'Invalid namespace';
const INVALID_MODULE_NAME = 'Invalid module name';
const INVALID_MODULE_PATH = 'Invalid module path';
const NAMESPACE_NOT_FOUND = 'Namespace was not found';
const MODULE_NOT_FOUND = 'Module with path was not found';

const FIELDS = {
    separator: Symbol('separator'),
    namespaces: Symbol('namespaces')
};

/**
 * Creates a new Storage.
 * @class
 * @classdesc Represents a modules storage.
 */
export default class Storage {
    constructor(pathSeparator = '/') {
        this[FIELDS.separator] = pathSeparator;
        this[FIELDS.namespaces] = {};
    }

    /**
     * Adds module to storage.
     * @param {Module} module - Target module to add.
     * @throws {Error} Throws an error if module with same path already exists.
     */
    addItem(module) {
        if (!module) {
            throw new Error(MISSED_MODULE);
        }

        if (!(module instanceof Module)) {
            throw new Error(INVALID_MODULE);
        }

        const namespace = module.getNamespace();

        if (!isString(namespace)) {
            throw new Error(INVALID_NAMESPACE);
        }

        const name = module.getName();

        if (!name) {
            throw new Error(MISSED_MODULE_NAME);
        }

        if (!isString(name)) {
            throw new Error(INVALID_MODULE_NAME);
        }

        if (!path.isValidName(this[FIELDS.separator], name)) {
            throw new Error(
                `${INVALID_MODULE_PATH} Module is now alllowed to contain namespace separators.`
            );
        }

        let registry = this[FIELDS.namespaces][namespace];

        if (!registry) {
            registry = {};
            this[FIELDS.namespaces][namespace] = registry;
        }

        if (registry.hasOwnProperty(name)) {
            throw new Error(`${name} is already registered.`);
        }<commit_msg>#8 Fixed typo<commit_after>import Symbol from 'es6-symbol';
import isNil from 'is-nil';
import isString from 'is-string';
import isFunction from 'is-function';
import forEach from 'for-each';
import Module from './module';
import path from './utils/path';

const MISSED_MODULE = 'Missed module';
const MISSED_MODULE_NAME = 'Missed module name';
const MISSED_NAMESPACE = 'Missed module namespace';
const MISSED_CALLBACK = 'Missed callback';
const INVALID_MODULE = 'Invalid module';
const INVALID_NAMESPACE = 'Invalid namespace';
const INVALID_MODULE_NAME = 'Invalid module name';
const INVALID_MODULE_PATH = 'Invalid module path';
const NAMESPACE_NOT_FOUND = 'Namespace was not found';
const MODULE_NOT_FOUND = 'Module with path was not found';

const FIELDS = {
    separator: Symbol('separator'),
    namespaces: Symbol('namespaces')
};

/**
 * Creates a new Storage.
 * @class
 * @classdesc Represents a modules storage.
 */
export default class Storage {
    constructor(pathSeparator = '/') {
        this[FIELDS.separator] = pathSeparator;
        this[FIELDS.namespaces] = {};
    }

    /**
     * Adds module to storage.
     * @param {Module} module - Target module to add.
     * @throws {Error} Throws an error if module with same path already exists.
     */
    addItem(module) {
        if (!module) {
            throw new Error(MISSED_MODULE);
        }

        if (!(module instanceof Module)) {
            throw new Error(INVALID_MODULE);
        }

        const namespace = module.getNamespace();

        if (!isString(namespace)) {
            throw new Error(INVALID_NAMESPACE);
        }

        const name = module.getName();

        if (!name) {
            throw new Error(MISSED_MODULE_NAME);
        }

        if (!isString(name)) {
            throw new Error(INVALID_MODULE_NAME);
        }

        if (!path.isValidName(this[FIELDS.separator], name)) {
            throw new Error(
                `${INVALID_MODULE_PATH} Module is not alllowed to contain namespace separators.`
            );
        }

        let registry = this[FIELDS.namespaces][namespace];

        if (!registry) {
            registry = {};
            this[FIELDS.namespaces][namespace] = registry;
        }

        if (registry.hasOwnProperty(name)) {
            throw new Error(`${name} is already registered.`);
        }
{'fraction_non_alphanumeric': 0.11080273270708796, 'fraction_numerical': 0.0006404782237403928, 'mean_word_length': 2.634600465477114, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2076416', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1305, 'n_words': 382}