/
readAmlSync.js
28 lines (27 loc) · 1 KB
/
readAmlSync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import readDataSync from '../readers/readDataSync'
import parserAml from '../parsers/aml'
/**
* Synchronously read an ArchieML file. Returns an empty object if file is empty.
*
* @function readAmlSync
* @param {String} filePath Input file path
* @param {Function} [map] Optional map function. Takes the parsed file (usually an object) and must return the modified file. See example below.
* @returns {Object} The parsed file
*
* @example
* var data = io.readAmlSync('path/to/data.aml')
* console.log(data) // json data
*
* var data = io.readAmlSync('path/to/data-with-comments.aml', function (amlFile) {
* amlFile.height = amlFile.height * 2
* return amlFile
* })
* console.log(data) // json data with height multiplied by 2
*/
export default function readAmlSync (filePath, opts_) {
var parserOptions
if (typeof opts_ !== 'undefined') {
parserOptions = typeof opts_ === 'function' ? {map: opts_} : opts_
}
return readDataSync(filePath, {parser: parserAml, parserOptions: parserOptions})
}