-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
38 lines (32 loc) · 952 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(function(context) {
// tagged literal function receives two parameters
// tokens - string tokens, around the placeholders
// values - list of values to replace in string literal placeholders
function capitalize(tokens = [], ...values) {
return tokens.reduce((acc, x, i) => {
return acc + x + `${values[i] || ''}`.toUpperCase();
}, '');
}
function demo() {
console.log('\n\nTEMPLATE LITERALS');
const person = {
firstName: 'John',
lastName: 'Doe',
age: 27
}
const { firstName, lastName, age } = person;
const output = `
First Name: ${firstName}\n
Last Name: ${lastName}\n
Age: ${age}
`;
console.log(output);
const outputTaggedTemplate = capitalize`
First Name: ${firstName}\n
Last Name: ${lastName}\n
Age: ${age}
`;
console.log(outputTaggedTemplate);
};
(context || this).demoLibs['template-literals'] = demo;
})(window);