source: imaps-frontend/node_modules/es-abstract/2016/CharacterRange.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: 776 bytes
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4var callBound = require('call-bind/callBound');
5
6var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
7var $TypeError = require('es-errors/type');
8var $charCodeAt = callBound('String.prototype.charCodeAt');
9var $push = callBound('Array.prototype.push');
10
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};
Note: See TracBrowser for help on using the repository browser.