index.js 802 B

12345678910111213141516171819202122232425
  1. // index.ts
  2. import { featureCollection } from "@turf/helpers";
  3. function sample(fc, num) {
  4. if (!fc) throw new Error("fc is required");
  5. if (num === null || num === void 0) throw new Error("num is required");
  6. if (typeof num !== "number") throw new Error("num must be a number");
  7. var outFC = featureCollection(getRandomSubarray(fc.features, num));
  8. return outFC;
  9. }
  10. function getRandomSubarray(arr, size) {
  11. var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
  12. while (i-- > min) {
  13. index = Math.floor((i + 1) * Math.random());
  14. temp = shuffled[index];
  15. shuffled[index] = shuffled[i];
  16. shuffled[i] = temp;
  17. }
  18. return shuffled.slice(min);
  19. }
  20. var turf_sample_default = sample;
  21. export {
  22. turf_sample_default as default,
  23. sample
  24. };
  25. //# sourceMappingURL=index.js.map