UTF16DecodeString.js 676 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var callBound = require('call-bind/callBound');
  4. var $push = callBound('Array.prototype.push');
  5. var CodePointAt = require('./CodePointAt');
  6. // https://262.ecma-international.org/11.0/#sec-utf16decodestring
  7. module.exports = function UTF16DecodeString(string) {
  8. if (typeof string !== 'string') {
  9. throw new $TypeError('Assertion failed: `string` must be a String');
  10. }
  11. var codePoints = [];
  12. var size = string.length;
  13. var position = 0;
  14. while (position < size) {
  15. var cp = CodePointAt(string, position);
  16. $push(codePoints, cp['[[CodePoint]]']);
  17. position += cp['[[CodeUnitCount]]'];
  18. }
  19. return codePoints;
  20. };