UNPKG

molstar

Version:

A comprehensive macromolecular library.

56 lines 1.84 kB
"use strict"; /** * Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info. * * from https://github.com/dsehnal/CIFTools.js * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.arrayGetCtor = exports.arrayPickIndices = exports.createRangeArray = exports.iterableToArray = exports.arrayFind = void 0; function arrayFind(array, f) { for (var i = 0, _i = array.length; i < _i; i++) { if (f(array[i])) return array[i]; } return void 0; } exports.arrayFind = arrayFind; function iterableToArray(it) { if (Array.from) return Array.from(it); var ret = []; while (true) { var _a = it.next(), done = _a.done, value = _a.value; if (done) break; ret[ret.length] = value; } return ret; } exports.iterableToArray = iterableToArray; /** Fills the array so that array[0] = start and array[array.length - 1] = end */ function createRangeArray(start, end, ctor) { var len = end - start + 1; var array = ctor ? new ctor(len) : new Int32Array(len); for (var i = 0; i < len; i++) { array[i] = i + start; } return array; } exports.createRangeArray = createRangeArray; function arrayPickIndices(array, indices) { var ret = new (arrayGetCtor(array))(indices.length); for (var i = 0, _i = indices.length; i < _i; i++) { ret[i] = array[indices[i]]; } return ret; } exports.arrayPickIndices = arrayPickIndices; function arrayGetCtor(data) { var ret = data.constructor; if (!ret) throw new Error('data does not define a constructor and it should'); return ret; } exports.arrayGetCtor = arrayGetCtor; //# sourceMappingURL=array.js.map