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:
639 bytes
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var CodePointAt = require('./CodePointAt');
|
---|
| 4 |
|
---|
| 5 | var $TypeError = require('es-errors/type');
|
---|
| 6 |
|
---|
| 7 | // https://262.ecma-international.org/13.0/#sec-isstringwellformedunicode
|
---|
| 8 |
|
---|
| 9 | module.exports = function IsStringWellFormedUnicode(string) {
|
---|
| 10 | if (typeof string !== 'string') {
|
---|
| 11 | throw new $TypeError('Assertion failed: `string` must be a String');
|
---|
| 12 | }
|
---|
| 13 | var strLen = string.length; // step 1
|
---|
| 14 | var k = 0; // step 2
|
---|
| 15 | while (k !== strLen) { // 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.