source: frontend/node_modules/es-abstract/2025/CharacterRange.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[9af201e]1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bound');
5
6var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
7var $TypeError = require('es-errors/type');
8var $charCodeAt = callBound('String.prototype.charCodeAt');
9
10var CharSet = require('../helpers/CharSet').CharSet;
11
12// https://262.ecma-international.org/16.0/#sec-runtime-semantics-characterrange-abstract-operation
13
14module.exports = function CharacterRange(A, B) {
15 if (!(A instanceof CharSet) || !(B instanceof CharSet)) {
16 throw new $TypeError('Assertion failed: CharSets A and B are not both CharSets');
17 }
18
19 var a;
20 A.yield(function (c) {
21 if (typeof a !== 'undefined') {
22 throw new $TypeError('Assertion failed: CharSet A has more than one character');
23 }
24 a = c;
25 });
26
27 var b;
28 B.yield(function (c) {
29 if (typeof b !== 'undefined') {
30 throw new $TypeError('Assertion failed: CharSet B has more than one character');
31 }
32 b = c;
33 });
34
35 var i = $charCodeAt(a, 0);
36 var j = $charCodeAt(b, 0);
37
38 if (!(i <= j)) {
39 throw new $TypeError('Assertion failed: i is not <= j');
40 }
41
42 var arr = [];
43 for (var k = i; k <= j; k += 1) {
44 arr[arr.length] = $fromCharCode(k);
45 }
46 return arr;
47};
Note: See TracBrowser for help on using the repository browser.