-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathstringtemplatearray.jsdoc
More file actions
47 lines (37 loc) · 1.43 KB
/
Copy pathstringtemplatearray.jsdoc
File metadata and controls
47 lines (37 loc) · 1.43 KB
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
39
40
41
42
43
44
45
46
47
StringTemplateArray : Array<String>
A StringTemplateArray is the parameter passed to tagged template functions. In addition
to being an array of Strings, it contains the "raw" strings before escaping is
applied.
See %%/String#raw|String.raw%% for a built in tagged template function.
Spec:
https://tc39.es/ecma262/#sec-gettemplateobject
----
instance.raw : Array<String>
Returns the template parts in **this** as written in the source code. For
example, if the template string is **`\n`**, **this[0]** will be a string of
length **1** containing the new line character whereas **this.raw[0]** will
be a string of length **2** containing **'\'** followed by **'n'**.
<example>
const join = (strings) => "['" + strings.join("', '") + "']";
// The following mimics the normal template string behavior with logging
const myTemplate = (stringTemplateArray, ...parts) => {
console.log('raw: ', join(stringTemplateArray.raw));
console.log('cooked:', join(stringTemplateArray));
console.log('parts: ', join(parts));
let result = stringTemplateArray[0];
for (let i = 1; i < stringTemplateArray.length; i++) {
result += parts[i - 1] + stringTemplateArray[i];
}
return result;
};
console.log('result:', myTemplate`\n`);
console.log();
console.log('result:', myTemplate`
`);
console.log();
console.log('result:', myTemplate`a\tb`);
console.log();
console.log('result:', myTemplate`A string\twith ${2}\tparts${'!'}`);
</example>
ReadOnly:
true