<commit_before>'use strict';

const debug = require('debug')('@bem/sdk.deps');
const decl = require('@bem/sdk.decl');

/**
 * @param {Array<{entity: BemEntityName, scope: {entity, tech: String}, data: *}>} depsData - List of deps
 * @returns {Array<*>}
 */
module.exports = function parse(depsData) {
    const mustDeps = [];
    const shouldDeps = [];
    const mustDepsIndex = {};
    const shouldDepsIndex = {};

    depsData.forEach(record => {
        const scope = record.scope || { entity: record.entity };

        if (!record.data) {
            return;
        }
        const data = [].concat(record.data);

        data.forEach(dep => {
            const subscope = decl.assign({
                entity: { block: dep.block, elem: dep.elem, mod: dep.mod && { name: dep.mod, val: dep.val } },
                tech: dep.tech
            }, scope);
            const subscopeKey = subscope.id;

            if (dep.mustDeps) {
                decl.normalize(dep.mustDeps, {format: 'v2', scope: subscope}).forEach(function (nd) {
                    nd = decl.assign(nd, subscope);
                    const key = nd.id;
                    const indexKey = subscopeKey + '→' + key;
                    if (!mustDepsIndex[indexKey]) {
                        subscopeKey === key ||
                            mustDeps.push({ vertex: subscope, dependOn: nd, ordered: true, path: record.path });
                        mustDepsIndex[indexKey] = true;<commit_msg>fix(deps): allow to pass object into format parser<commit_after>'use strict';

const debug = require('debug')('@bem/sdk.deps');
const decl = require('@bem/sdk.decl');

/**
 * @typedef {Object} DepsData
 * @property {BemCell} [scope] - Scope cell object
 * @property {BemEntityName} [entity] - Entity to use if no scope passed
 * @property {Array<DepsChunk>} data - Deps data
 */

/**
 * @typedef {(string|Object)} DepsChunk
 * @property {string} [block]
 * @property {(DepsChunk|Array<DepsChunk>)} [elem]
 * @property {string} [mod]
 * @property {string} [val]
 * @property {string} [tech]
 * @property {(DepsChunk|Array<DepsChunk>)} [elems]
 * @property {Object} [mods]
 * @property {(DepsChunk|Array<DepsChunk>)} [mustDeps]
 * @property {(DepsChunk|Array<DepsChunk>)} [shouldDeps]
 */

/**
 * @typedef {Object} DepsLink
 * @property {BemCell} vertex
 * @property {BemCell} dependOn
 * @property {boolean} [ordered] - `mustDeps` if set to true
 * @property {string} [path] - path to deps.js file if exists
 */

/**
 * @param {(Array<DepsData>|DepsData)} depsData - List of deps
 * @returns {Array<DepsLink>}
 */
module.exports = function parse(depsData) {
    const mustDeps = [];
    const shouldDeps = [];
    const mustDepsIndex = {};
    const shouldDepsIndex = {};

    [].concat(depsData).forEach(record => {
        const scope = record.scope || { entity: record.entity };

        if (!record.data) {
            return;
        }
        const data = [].concat(record.data);

        data.forEach(dep => {
            const subscope = decl.assign({
                entity: { block: dep.block, elem: dep.elem, mod: dep.mod && { name: dep.mod, val: dep.val } },
                tech: dep.tech
            }, scope);
            const subscopeKey = subscope.id;

            if (dep.mustDeps) {
                decl.normalize(dep.mustDeps, {format: 'v2', scope: subscope}).forEach(function (nd) {
                    nd = decl.assign(nd, subscope);
                    const key = nd.id;
                    const indexKey = subscopeKey + '→' + key;
                    if (!mustDepsIndex[indexKey]) {
                        subscopeKey === key ||
                            mustDeps.push({ vertex: subscope, dependOn: nd, ordered: true, path: record.path });
                        mustDepsIndex[indexKey] = true;
{'fraction_non_alphanumeric': 0.1518586870551015, 'fraction_numerical': 0.0005272871078302136, 'mean_word_length': 2.234441602728048, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 16, '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': '7139684', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1143, 'n_words': 280}