src/2.0/generator-api/generator.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 1

Size

Lines of Code 20
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 0
c 1
b 1
f 0
nc 1
dl 0
loc 20
rs 10
wmc 3
mnd 0
bc 3
fnc 3
bpm 1
cpm 1
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A Handlebars.registerHelper(ꞌtoLowerCaseꞌ) 0 3 1
A Handlebars.registerHelper(ꞌbracketsꞌ) 0 3 1
A module.exports 0 5 1
1
/**
2
 * @author Donii Sergii <[email protected]>
3
 */
4
const Handlebars = require('handlebars')
5
const fs = require('fs')
6
const path = require('path')
7
const beautify = require('js-beautify').js_beautify
8
const apiTemplate = fs.readFileSync(path.join(__dirname, '/../../../js-template/api.hbs'), 'utf-8')
9
const methods = fs.readFileSync(path.join(__dirname, '/../../../js-template/methods.hbs'), 'utf-8')
10
const method = fs.readFileSync(path.join(__dirname, '/../../../js-template/method.hbs'), 'utf-8')
11
Handlebars.registerPartial('methods', methods)
12
Handlebars.registerPartial('method', method)
13
Handlebars.registerHelper('toLowerCase', function (word) {
14
    return word.toLowerCase()
15
})
16
Handlebars.registerHelper('brackets', function (word) {
17
    return `{${word}}`
18
})
19
module.exports = function (data) {
20
    let template = Handlebars.compile(apiTemplate)(data)
21
    template = beautify(template, {indent_size: 2, max_preserve_newlines: -1})
22
    return template
23
}