blob: fcbe05e0e372d126a6209bdfb3163e7cfe2ecc80 [file] [log] [blame]
Tim van der Lippebc3a0b72021-11-08 15:22:371'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bind/callBound');
5
6var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
Nikolay Vitkovd76576c2024-12-02 14:10:157var $TypeError = require('es-errors/type');
8var $charCodeAt = callBound('String.prototype.charCodeAt');
9var $push = callBound('Array.prototype.push');
Tim van der Lippebc3a0b72021-11-08 15:22:3710
11module.exports = function CharacterRange(A, B) {
12 if (A.length !== 1 || B.length !== 1) {
13 throw new $TypeError('Assertion failed: CharSets A and B contain exactly one character');
14 }
15
16 var a = A[0];
17 var b = B[0];
18
19 var i = $charCodeAt(a, 0);
20 var j = $charCodeAt(b, 0);
21
22 if (!(i <= j)) {
23 throw new $TypeError('Assertion failed: i is not <= j');
24 }
25
26 var arr = [];
27 for (var k = i; k <= j; k += 1) {
28 $push(arr, $fromCharCode(k));
29 }
30 return arr;
31};