source: imaps-frontend/node_modules/es-abstract/2024/IsStringWellFormedUnicode.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 631 bytes
Line 
1'use strict';
2
3var CodePointAt = require('./CodePointAt');
4
5var $TypeError = require('es-errors/type');
6
7// https://262.ecma-international.org/14.0/#sec-isstringwellformedunicode
8
9module.exports = function IsStringWellFormedUnicode(string) {
10 if (typeof string !== 'string') {
11 throw new $TypeError('Assertion failed: `string` must be a String');
12 }
13 var len = string.length; // step 1
14 var k = 0; // step 2
15 while (k < len) { // step 3
16 var cp = CodePointAt(string, k); // step 3.a
17 if (cp['[[IsUnpairedSurrogate]]']) {
18 return false; // step 3.b
19 }
20 k += cp['[[CodeUnitCount]]']; // step 3.c
21 }
22 return true; // step 4
23};
Note: See TracBrowser for help on using the repository browser.