1 | 'use strict';
|
2 | var uncurryThis = require('../internals/function-uncurry-this');
|
3 | var toIndexedObject = require('../internals/to-indexed-object');
|
4 | var toString = require('../internals/to-string');
|
5 | var lengthOfArrayLike = require('../internals/length-of-array-like');
|
6 |
|
7 | var $TypeError = TypeError;
|
8 | var push = uncurryThis([].push);
|
9 | var join = uncurryThis([].join);
|
10 |
|
11 |
|
12 |
|
13 | module.exports = function cooked(template /* , ...substitutions */) {
|
14 | var cookedTemplate = toIndexedObject(template);
|
15 | var literalSegments = lengthOfArrayLike(cookedTemplate);
|
16 | if (!literalSegments) return '';
|
17 | var argumentsLength = arguments.length;
|
18 | var elements = [];
|
19 | var i = 0;
|
20 | while (true) {
|
21 | var nextVal = cookedTemplate[i++];
|
22 | if (nextVal === undefined) throw new $TypeError('Incorrect template');
|
23 | push(elements, toString(nextVal));
|
24 | if (i === literalSegments) return join(elements, '');
|
25 | if (i < argumentsLength) push(elements, toString(arguments[i]));
|
26 | }
|
27 | };
|