UNPKG

geotiff.js

Version:

GeoTIFF image decoding in JavaScript

79 lines (70 loc) 1.68 kB
export function assign(target, source) { for (const key in source) { if (source.hasOwnProperty(key)) { target[key] = source[key]; } } } export function chunk(iterable, length) { const results = []; const lengthOfIterable = iterable.length; for (let i = 0; i < lengthOfIterable; i += length) { const chunked = []; for (let ci = i; ci < i + length; ci++) { chunked.push(iterable[ci]); } results.push(chunked); } return results; } export function endsWith(string, expectedEnding) { if (string.length < expectedEnding.length) { return false; } const actualEnding = string.substr(string.length - expectedEnding.length); return actualEnding === expectedEnding; } export function forEach(iterable, func) { const { length } = iterable; for (let i = 0; i < length; i++) { func(iterable[i], i); } } export function invert(oldObj) { const newObj = {}; for (const key in oldObj) { if (oldObj.hasOwnProperty(key)) { const value = oldObj[key]; newObj[value] = key; } } return newObj; } export function range(n) { const results = []; for (let i = 0; i < n; i++) { results.push(i); } return results; } export function times(numTimes, func) { const results = []; for (let i = 0; i < numTimes; i++) { results.push(func(i)); } return results; } export function toArray(iterable) { const results = []; const { length } = iterable; for (let i = 0; i < length; i++) { results.push(iterable[i]); } return results; } export function toArrayRecursively(input) { if (input.length) { return toArray(input).map(toArrayRecursively); } return input; }