-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
23 lines (19 loc) · 921 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'use strict';
const scan = require('./lib/scan');
const regexBuild = require('./lib/regex');
const transformation = require('./lib/transformation');
const render = require('./lib/render');
const oneTime = (template, params, leftDelimiter, rightDelimiter) => {
const stringified = (typeof template === 'string') ? template : JSON.stringify(template);
const subject = JSON.parse(stringified);
const regex = regexBuild(leftDelimiter, rightDelimiter);
const matched = scan(subject, regex);
const transformations = transformation(matched, regex.leftDelimiter, regex.rightDelimiter);
return render(subject, transformations, params);
};
module.exports = function(commonParams, leftDelimiter, rightDelimiter) {
return function(template, params) {
return oneTime(template, Object.assign({}, commonParams, params), leftDelimiter, rightDelimiter);
};
};
module.exports.oneTime = oneTime;