CodePointsToString.js 735 B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var UTF16EncodeCodePoint = require('./UTF16EncodeCodePoint');
  4. var IsArray = require('./IsArray');
  5. var forEach = require('../helpers/forEach');
  6. var isCodePoint = require('../helpers/isCodePoint');
  7. // https://262.ecma-international.org/12.0/#sec-codepointstostring
  8. module.exports = function CodePointsToString(text) {
  9. if (!IsArray(text)) {
  10. throw new $TypeError('Assertion failed: `text` must be a sequence of Unicode Code Points');
  11. }
  12. var result = '';
  13. forEach(text, function (cp) {
  14. if (!isCodePoint(cp)) {
  15. throw new $TypeError('Assertion failed: `text` must be a sequence of Unicode Code Points');
  16. }
  17. result += UTF16EncodeCodePoint(cp);
  18. });
  19. return result;
  20. };