UNPKG

json-parser-yaml-converter

Version:
60 lines (53 loc) 1.12 kB
/** * This module exports the functions to build the AST. * * @module buildAst */ 'use strict'; /** * Builds an object. * @param {Array} pairs A list of pairs to build the object. * @returns {Object} The AST of the object. */ function buildObject(pairs) { return { type: 'object', properties: pairs }; } /** * Builds a pair. * @param {Object} key Key of the pair. * @param {Object} value Value of the pair. * @returns {Object} The AST of the pair. */ function buildPair(key, value) { return { type: 'pair', key: key.value, value }; } /** * Builds the value of a JSON file. * @param {Object} value Value to build. * @returns {Object} The AST of the value. */ function buildValue([value]) { return { type: 'value', value: value.value, }; } /** * Builds an array. * @param {Array} array Array to build. * @returns {Object} The AST of the array. */ function buildArray([array]) { return { type: 'array', elements: array }; } export { buildObject, buildPair, buildValue, buildArray };