Skip to content
Permalink
Newer
Older
100644 31 lines (24 sloc) 778 Bytes
Ignoring revisions in .git-blame-ignore-revs.
1
'use strict';
2
3
var GetIntrinsic = require('get-intrinsic');
4
var callBound = require('call-bind/callBound');
5
6
var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
7
var $TypeError = GetIntrinsic('%TypeError%');
8
var $charCodeAt = callBound('String.prototype.charCodeAt');
9
var $push = callBound('Array.prototype.push');
10
11
module.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
};