package.modules.es.string.is-well-formed.js Maven / Gradle / Ivy
The newest version!
'use strict';
var $ = require('../internals/export');
var uncurryThis = require('../internals/function-uncurry-this');
var requireObjectCoercible = require('../internals/require-object-coercible');
var toString = require('../internals/to-string');
var charCodeAt = uncurryThis(''.charCodeAt);
// `String.prototype.isWellFormed` method
// https://tc39.es/ecma262/#sec-string.prototype.iswellformed
$({ target: 'String', proto: true }, {
isWellFormed: function isWellFormed() {
var S = toString(requireObjectCoercible(this));
var length = S.length;
for (var i = 0; i < length; i++) {
var charCode = charCodeAt(S, i);
// single UTF-16 code unit
if ((charCode & 0xF800) !== 0xD800) continue;
// unpaired surrogate
if (charCode >= 0xDC00 || ++i >= length || (charCodeAt(S, i) & 0xFC00) !== 0xDC00) return false;
} return true;
}
});
© 2015 - 2024 Weber Informatics LLC | Privacy Policy