<commit_before>import { newRawValue } from "./history";
import { FormatAEntry, FormatAGroup, FormatBEntry, FormatBGroup, FormatBKeyValueObject, PropertyKeyValueObject } from "../../types";

export function convertFormatAEntry(entry: FormatAEntry): FormatBEntry {
    return {
        id: entry.id,
        a: flatKeyValueObjectToValuesObject(entry.attributes || {}),
        p: flatKeyValueObjectToValuesObject(entry.properties || {}),
        g: entry.parentID
    };
}

export function convertFormatAGroup(group: FormatAGroup): FormatBGroup {
    return {
        id: group.id,
        a: flatKeyValueObjectToValuesObject(group.attributes || {}),
        t: group.title,
        g: group.parentID
    };
}

function flatKeyValueObjectToValuesObject(obj: PropertyKeyValueObject): FormatBKeyValueObject {
    return Object.keys(obj).reduce((output, key) => Object.assign(output, {
        [key]: newRawValue(obj[key])
    }), {});
}

export function isFormatBEntry(entry: FormatAEntry | FormatBEntry): entry is FormatBEntry {
    return (<FormatBEntry>entry).g !== undefined;
}

export function isFormatBGroup(group: FormatAGroup | FormatBGroup): group is FormatBGroup {
    return (<FormatBGroup>group).g !== undefined;
}

export function valuesObjectToKeyValueObject(valuesObj: FormatBKeyValueObject): PropertyKeyValueObject {
    return Object.keys(valuesObj).reduce((output, key) => Object.assign(output, {
        [key]: valuesObj[key].value
    }), {});
}
<commit_msg>Add format a -> b vault conversion<commit_after>import { newRawValue } from "./history";
import { getDateString } from "../../tools/date";
import {
    getAllEntries as getAllFormatAEntries,
    getAllGroups as getAllFormatAGroups
} from "../formatA/tools";
import { FormatAEntry, FormatAGroup, FormatAVault, FormatBEntry, FormatBGroup, FormatBKeyValueObject, FormatBVault, PropertyKeyValueObject } from "../../types";

export function convertFormatAEntry(entry: FormatAEntry): FormatBEntry {
    return {
        id: entry.id,
        a: flatKeyValueObjectToValuesObject(entry.attributes || {}),
        p: flatKeyValueObjectToValuesObject(entry.properties || {}),
        g: entry.parentID
    };
}

export function convertFormatAGroup(group: FormatAGroup): FormatBGroup {
    return {
        id: group.id,
        a: flatKeyValueObjectToValuesObject(group.attributes || {}),
        t: group.title,
        g: group.parentID
    };
}

export function convertFormatAVault(vault: FormatAVault): FormatBVault {
    return {
        id: vault.id,
        a: flatKeyValueObjectToValuesObject(vault.attributes || {}),
        g: getAllFormatAGroups(vault).map(group => convertFormatAGroup(group)),
        e: getAllFormatAEntries(vault).map(entry => convertFormatAEntry(entry)),
        c: getDateString()
    };
}

function flatKeyValueObjectToValuesObject(obj: PropertyKeyValueObject): FormatBKeyValueObject {
    return Object.keys(obj).reduce((output, key) => Object.assign(output, {
        [key]: newRawValue(obj[key])
    }), {});
}

export function isFormatBEntry(entry: FormatAEntry | FormatBEntry): entry is FormatBEntry {
    return (<FormatBEntry>entry).g !== undefined;
}

export function isFormatBGroup(group: FormatAGroup | FormatBGroup): group is FormatBGroup {
    return (<FormatBGroup>group).g !== undefined;
}

export function valuesObjectToKeyValueObject(valuesObj: FormatBKeyValueObject): PropertyKeyValueObject {
    return Object.keys(valuesObj).reduce((output, key) => Object.assign(output, {
        [key]: valuesObj[key].value
    }), {});
}

{'fraction_non_alphanumeric': 0.12369387178763061, 'fraction_numerical': 0.0, 'mean_word_length': 4.278688524590164, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, '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': '4988359', 'n_tokens_mistral': 1019, 'n_tokens_neox': 1017, 'n_words': 206}