main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 2 weeks ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1023 bytes
|
Rev | Line | |
---|
[79a0317] | 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 | // `String.cooked` method
|
---|
| 12 | // https://tc39.es/proposal-string-cooked/
|
---|
| 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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.