|
'use strict'; |
|
|
|
var GetIntrinsic = require('get-intrinsic'); |
|
var CodePointAt = require('./CodePointAt'); |
|
|
|
var $TypeError = GetIntrinsic('%TypeError%'); |
|
|
|
var Type = require('./Type'); |
|
|
|
|
|
|
|
module.exports = function IsStringWellFormedUnicode(string) { |
|
if (Type(string) !== 'String') { |
|
throw new $TypeError('Assertion failed: `string` must be a String'); |
|
} |
|
var len = string.length; |
|
var k = 0; |
|
while (k < len) { |
|
var cp = CodePointAt(string, k); |
|
if (cp['[[IsUnpairedSurrogate]]']) { |
|
return false; |
|
} |
|
k += cp['[[CodeUnitCount]]']; |
|
} |
|
return true; |
|
}; |
|
|