MCPcopy Index your code
hub / github.com/serverless/serverless / parse

Function parse

packages/serverless/lib/utils/fs/parse.js:17–36  ·  view source on GitHub ↗
(filePath, contents)

Source from the content-addressed store, hash-verified

15}
16
17function parse(filePath, contents) {
18 // Auto-parse JSON
19 if (filePath.endsWith('.json') || filePath.endsWith('.tfstate')) {
20 return jc.parse(contents)
21 } else if (filePath.endsWith('.yml') || filePath.endsWith('.yaml')) {
22 const options = {
23 filename: filePath,
24 }
25 let result = loadYaml(contents.toString(), options)
26 if (result.error && result.error.name === 'YAMLException') {
27 _.merge(options, { schema: cloudformationSchema })
28 result = loadYaml(contents.toString(), options)
29 }
30 if (result.error) {
31 throw result.error
32 }
33 return result.data
34 }
35 return contents.toString().trim()
36}
37
38export default parse

Callers 4

readFileFunction · 0.85
readFileSyncFunction · 0.85
valdiateSchemaMethod · 0.85

Calls 1

loadYamlFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…