/* IMPORT */
import { match } from 'reghex';
/* MAIN */
const Utils = {
    /* VARIABLES */
    tokenDelimiterTypes: new Set(['ArrayOpen', 'ArrayClose', 'ObjectOpen', 'ObjectClose']),
    tokenIgnoredTypes: new Set(['Newline', 'Whitespace', 'CommentLine', 'CommentBlock', 'Comma', 'CommaTrailing', 'Colon']),
    tokenLiteralTypes: new Set(['Null', 'True', 'False', 'Number', 'String', 'Array', 'Object']),
    /* API */
    isEven: (number) => {
        return !(number % 2);
    },
    isOdd: (number) => {
        return !Utils.isEven(number);
    },
    isString: (value) => {
        return typeof value === 'string';
    },
    isToken: (value) => {
        return !Utils.isString(value);
    },
    isTokenDelimiter: (token) => {
        return Utils.tokenDelimiterTypes.has(token.type);
    },
    isTokenIgnored: (token) => {
        return Utils.tokenIgnoredTypes.has(token.type);
    },
    isTokenLiteral: (token) => {
        return Utils.tokenLiteralTypes.has(token.type);
    },
    tokens2matchers: (tokens) => {
        const cache = new Map();
        return Object.keys(tokens).reduce((acc, type) => {
            const transformer = tokens[type];
            const matcher = transformer.unwrapped ? transformer : cache.get(transformer) || match(type, transformer);
            cache.set(transformer, matcher);
            acc[type] = matcher;
            return acc;
        }, {});
    }
};
/* EXPORT */
export default Utils;
