es.string.raw.js 976 B

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