source: imaps-frontend/node_modules/es-abstract/2023/CreateListFromArrayLike.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.4 KB
Line 
1'use strict';
2
3var callBound = require('call-bound');
4
5var $TypeError = require('es-errors/type');
6var $indexOf = callBound('Array.prototype.indexOf', true) || callBound('String.prototype.indexOf');
7var $push = callBound('Array.prototype.push');
8
9var Get = require('./Get');
10var IsArray = require('./IsArray');
11var LengthOfArrayLike = require('./LengthOfArrayLike');
12var ToString = require('./ToString');
13var Type = require('./Type');
14
15var isObject = require('../helpers/isObject');
16
17var defaultElementTypes = ['Undefined', 'Null', 'Boolean', 'String', 'Symbol', 'Number', 'BigInt', 'Object'];
18
19// https://262.ecma-international.org/11.0/#sec-createlistfromarraylike
20
21module.exports = function CreateListFromArrayLike(obj) {
22 var elementTypes = arguments.length > 1
23 ? arguments[1]
24 : defaultElementTypes;
25
26 if (!isObject(obj)) {
27 throw new $TypeError('Assertion failed: `obj` must be an Object');
28 }
29 if (!IsArray(elementTypes)) {
30 throw new $TypeError('Assertion failed: `elementTypes`, if provided, must be an array');
31 }
32 var len = LengthOfArrayLike(obj);
33 var list = [];
34 var index = 0;
35 while (index < len) {
36 var indexName = ToString(index);
37 var next = Get(obj, indexName);
38 var nextType = Type(next);
39 if ($indexOf(elementTypes, nextType) < 0) {
40 throw new $TypeError('item type ' + nextType + ' is not a valid elementType');
41 }
42 $push(list, next);
43 index += 1;
44 }
45 return list;
46};
Note: See TracBrowser for help on using the repository browser.