mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
add parse self-reference test add writeFile self-reference test add writeFileSync self-reference test
17 lines
415 B
JavaScript
17 lines
415 B
JavaScript
'use strict';
|
|
|
|
const jc = require('json-cycle');
|
|
const YAML = require('js-yaml');
|
|
|
|
function parse(filePath, contents) {
|
|
// Auto-parse JSON
|
|
if (filePath.endsWith('.json')) {
|
|
return jc.parse(contents);
|
|
} else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) {
|
|
return YAML.load(contents.toString(), { filename: filePath });
|
|
}
|
|
return contents.toString().trim();
|
|
}
|
|
|
|
module.exports = parse;
|