MCPcopy
hub / github.com/SparkPost/heml / heml

Function heml

packages/heml/src/index.js:17–57  ·  view source on GitHub ↗

* renders the given HEML string with the config provided * @param {String} HEML the heml to render * @param {Object} options the options * @return {Object} { metadata, html, errors }

(contents, options = {})

Source from the content-addressed store, hash-verified

15 * @return {Object} { metadata, html, errors }
16 */
17async function heml (contents, options = {}) {
18 const results = {}
19 const {
20 beautify: beautifyOptions = {},
21 validate: validateOption = 'soft'
22 } = options
23
24 options.elements = flattenDeep(toArray(coreElements).concat(options.elements || []))
25
26 /** parse it ✂️ */
27 const $heml = parse(contents, options)
28
29 /** validate it 🕵 */
30 const errors = validate($heml, options)
31 if (validateOption.toLowerCase() === 'strict' && errors.length > 0) { throw errors[0] }
32 if (validateOption.toLowerCase() === 'soft') { results.errors = errors }
33
34 /** render it 🤖 */
35 const {
36 $: $html,
37 metadata
38 } = await render($heml, options)
39
40 /** inline it ✍️ */
41 inline($html, options)
42
43 /** beautify it 💅 */
44 results.html = condition.replace(beautify($html.html(), {
45 indent_size: 2,
46 indent_inner_html: true,
47 preserve_newlines: false,
48 extra_liners: [],
49 ...beautifyOptions }))
50
51 /** final touches 👌 */
52 metadata.size = `${(byteLength(results.html) / 1024).toFixed(2)}kb`
53 results.metadata = metadata
54
55 /** send it back 🎉 */
56 return results
57}
58
59/** module.exports for commonjs */
60module.exports = heml

Callers 2

renderHemlFileFunction · 0.85
snapshot.spec.jsFile · 0.85

Calls 4

parseFunction · 0.85
validateFunction · 0.85
inlineFunction · 0.85
renderFunction · 0.50

Tested by

no test coverage detected