CodePointsToString.js 788 B

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