es.string.raw.js 672 B

12345678910111213141516171819
  1. var $ = require('../internals/export');
  2. var toIndexedObject = require('../internals/to-indexed-object');
  3. var toLength = require('../internals/to-length');
  4. // `String.raw` method
  5. // https://tc39.es/ecma262/#sec-string.raw
  6. $({ target: 'String', stat: true }, {
  7. raw: function raw(template) {
  8. var rawTemplate = toIndexedObject(template.raw);
  9. var literalSegments = toLength(rawTemplate.length);
  10. var argumentsLength = arguments.length;
  11. var elements = [];
  12. var i = 0;
  13. while (literalSegments > i) {
  14. elements.push(String(rawTemplate[i++]));
  15. if (i < argumentsLength) elements.push(String(arguments[i]));
  16. } return elements.join('');
  17. }
  18. });