@turf/sample 7.2.0 → 7.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,9 +17,9 @@ function getRandomSubarray(arr, size) {
17
17
  }
18
18
  return shuffled.slice(min);
19
19
  }
20
- var turf_sample_default = sample;
20
+ var index_default = sample;
21
21
 
22
22
 
23
23
 
24
- exports.default = turf_sample_default; exports.sample = sample;
24
+ exports.default = index_default; exports.sample = sample;
25
25
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-sample/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACEA,wCAAkC;AAqBlC,SAAS,MAAA,CACP,EAAA,EACA,GAAA,EACsB;AACtB,EAAA,GAAA,CAAI,CAAC,EAAA,EAAI,MAAM,IAAI,KAAA,CAAM,gBAAgB,CAAA;AACzC,EAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,GAAQ,IAAA,IAAQ,KAAA,CAAA,EAAW,MAAM,IAAI,KAAA,CAAM,iBAAiB,CAAA;AACxE,EAAA,GAAA,CAAI,OAAO,IAAA,IAAQ,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,sBAAsB,CAAA;AACnE,EAAA,IAAI,MAAA,EAAQ,wCAAA,iBAAkB,CAAkB,EAAA,CAAG,QAAA,EAAU,GAAG,CAAC,CAAA;AACjE,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,iBAAA,CACP,GAAA,EACA,IAAA,EACA;AACA,EAAA,IAAI,SAAA,EAAW,GAAA,CAAI,KAAA,CAAM,CAAC,CAAA,EACxB,EAAA,EAAI,GAAA,CAAI,MAAA,EACR,IAAA,EAAM,EAAA,EAAI,IAAA,EACV,IAAA,EACA,KAAA;AACF,EAAA,MAAA,CAAO,CAAA,GAAA,EAAM,GAAA,EAAK;AAChB,IAAA,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAA,CAAO,EAAA,EAAI,CAAA,EAAA,EAAK,IAAA,CAAK,MAAA,CAAO,CAAC,CAAA;AAC1C,IAAA,KAAA,EAAO,QAAA,CAAS,KAAK,CAAA;AACrB,IAAA,QAAA,CAAS,KAAK,EAAA,EAAI,QAAA,CAAS,CAAC,CAAA;AAC5B,IAAA,QAAA,CAAS,CAAC,EAAA,EAAI,IAAA;AAAA,EAChB;AACA,EAAA,OAAO,QAAA,CAAS,KAAA,CAAM,GAAG,CAAA;AAC3B;AAGA,IAAO,oBAAA,EAAQ,MAAA;ADjCf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-sample/dist/cjs/index.cjs","sourcesContent":[null,"// http://stackoverflow.com/questions/11935175/sampling-a-random-subset-from-an-array\nimport { Feature, FeatureCollection, Geometry, GeometryObject } from \"geojson\";\nimport { featureCollection } from \"@turf/helpers\";\n\n/**\n * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.\n *\n * @function\n * @param {FeatureCollection} featurecollection set of input features\n * @param {number} num number of features to select\n * @returns {FeatureCollection} a FeatureCollection with `n` features\n * @example\n * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});\n *\n * var sample = turf.sample(points, 5);\n *\n * //addToMap\n * var addToMap = [points, sample]\n * turf.featureEach(sample, function (currentFeature) {\n * currentFeature.properties['marker-size'] = 'large';\n * currentFeature.properties['marker-color'] = '#000';\n * });\n */\nfunction sample<T extends GeometryObject>(\n fc: FeatureCollection<T>,\n num: number\n): FeatureCollection<T> {\n if (!fc) throw new Error(\"fc is required\");\n if (num === null || num === undefined) throw new Error(\"num is required\");\n if (typeof num !== \"number\") throw new Error(\"num must be a number\");\n var outFC = featureCollection(getRandomSubarray(fc.features, num));\n return outFC;\n}\n\nfunction getRandomSubarray<T extends Geometry>(\n arr: Feature<T>[],\n size: number\n) {\n var shuffled = arr.slice(0),\n i = arr.length,\n min = i - size,\n temp,\n index;\n while (i-- > min) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(min);\n}\n\nexport { sample };\nexport default sample;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-sample/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACEA,wCAAkC;AAqBlC,SAAS,MAAA,CACP,EAAA,EACA,GAAA,EACsB;AACtB,EAAA,GAAA,CAAI,CAAC,EAAA,EAAI,MAAM,IAAI,KAAA,CAAM,gBAAgB,CAAA;AACzC,EAAA,GAAA,CAAI,IAAA,IAAQ,KAAA,GAAQ,IAAA,IAAQ,KAAA,CAAA,EAAW,MAAM,IAAI,KAAA,CAAM,iBAAiB,CAAA;AACxE,EAAA,GAAA,CAAI,OAAO,IAAA,IAAQ,QAAA,EAAU,MAAM,IAAI,KAAA,CAAM,sBAAsB,CAAA;AACnE,EAAA,IAAI,MAAA,EAAQ,wCAAA,iBAAkB,CAAkB,EAAA,CAAG,QAAA,EAAU,GAAG,CAAC,CAAA;AACjE,EAAA,OAAO,KAAA;AACT;AAEA,SAAS,iBAAA,CACP,GAAA,EACA,IAAA,EACA;AACA,EAAA,IAAI,SAAA,EAAW,GAAA,CAAI,KAAA,CAAM,CAAC,CAAA,EACxB,EAAA,EAAI,GAAA,CAAI,MAAA,EACR,IAAA,EAAM,EAAA,EAAI,IAAA,EACV,IAAA,EACA,KAAA;AACF,EAAA,MAAA,CAAO,CAAA,GAAA,EAAM,GAAA,EAAK;AAChB,IAAA,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAA,CAAO,EAAA,EAAI,CAAA,EAAA,EAAK,IAAA,CAAK,MAAA,CAAO,CAAC,CAAA;AAC1C,IAAA,KAAA,EAAO,QAAA,CAAS,KAAK,CAAA;AACrB,IAAA,QAAA,CAAS,KAAK,EAAA,EAAI,QAAA,CAAS,CAAC,CAAA;AAC5B,IAAA,QAAA,CAAS,CAAC,EAAA,EAAI,IAAA;AAAA,EAChB;AACA,EAAA,OAAO,QAAA,CAAS,KAAA,CAAM,GAAG,CAAA;AAC3B;AAGA,IAAO,cAAA,EAAQ,MAAA;ADjCf;AACE;AACA;AACF,yDAAC","file":"/home/runner/work/turf/turf/packages/turf-sample/dist/cjs/index.cjs","sourcesContent":[null,"// http://stackoverflow.com/questions/11935175/sampling-a-random-subset-from-an-array\nimport { Feature, FeatureCollection, Geometry, GeometryObject } from \"geojson\";\nimport { featureCollection } from \"@turf/helpers\";\n\n/**\n * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.\n *\n * @function\n * @param {FeatureCollection} featurecollection set of input features\n * @param {number} num number of features to select\n * @returns {FeatureCollection} a FeatureCollection with `n` features\n * @example\n * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});\n *\n * var sample = turf.sample(points, 5);\n *\n * //addToMap\n * var addToMap = [points, sample]\n * turf.featureEach(sample, function (currentFeature) {\n * currentFeature.properties['marker-size'] = 'large';\n * currentFeature.properties['marker-color'] = '#000';\n * });\n */\nfunction sample<T extends GeometryObject>(\n fc: FeatureCollection<T>,\n num: number\n): FeatureCollection<T> {\n if (!fc) throw new Error(\"fc is required\");\n if (num === null || num === undefined) throw new Error(\"num is required\");\n if (typeof num !== \"number\") throw new Error(\"num must be a number\");\n var outFC = featureCollection(getRandomSubarray(fc.features, num));\n return outFC;\n}\n\nfunction getRandomSubarray<T extends Geometry>(\n arr: Feature<T>[],\n size: number\n) {\n var shuffled = arr.slice(0),\n i = arr.length,\n min = i - size,\n temp,\n index;\n while (i-- > min) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(min);\n}\n\nexport { sample };\nexport default sample;\n"]}
package/dist/esm/index.js CHANGED
@@ -17,9 +17,9 @@ function getRandomSubarray(arr, size) {
17
17
  }
18
18
  return shuffled.slice(min);
19
19
  }
20
- var turf_sample_default = sample;
20
+ var index_default = sample;
21
21
  export {
22
- turf_sample_default as default,
22
+ index_default as default,
23
23
  sample
24
24
  };
25
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["// http://stackoverflow.com/questions/11935175/sampling-a-random-subset-from-an-array\nimport { Feature, FeatureCollection, Geometry, GeometryObject } from \"geojson\";\nimport { featureCollection } from \"@turf/helpers\";\n\n/**\n * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.\n *\n * @function\n * @param {FeatureCollection} featurecollection set of input features\n * @param {number} num number of features to select\n * @returns {FeatureCollection} a FeatureCollection with `n` features\n * @example\n * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});\n *\n * var sample = turf.sample(points, 5);\n *\n * //addToMap\n * var addToMap = [points, sample]\n * turf.featureEach(sample, function (currentFeature) {\n * currentFeature.properties['marker-size'] = 'large';\n * currentFeature.properties['marker-color'] = '#000';\n * });\n */\nfunction sample<T extends GeometryObject>(\n fc: FeatureCollection<T>,\n num: number\n): FeatureCollection<T> {\n if (!fc) throw new Error(\"fc is required\");\n if (num === null || num === undefined) throw new Error(\"num is required\");\n if (typeof num !== \"number\") throw new Error(\"num must be a number\");\n var outFC = featureCollection(getRandomSubarray(fc.features, num));\n return outFC;\n}\n\nfunction getRandomSubarray<T extends Geometry>(\n arr: Feature<T>[],\n size: number\n) {\n var shuffled = arr.slice(0),\n i = arr.length,\n min = i - size,\n temp,\n index;\n while (i-- > min) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(min);\n}\n\nexport { sample };\nexport default sample;\n"],"mappings":";AAEA,SAAS,yBAAyB;AAqBlC,SAAS,OACP,IACA,KACsB;AACtB,MAAI,CAAC,GAAI,OAAM,IAAI,MAAM,gBAAgB;AACzC,MAAI,QAAQ,QAAQ,QAAQ,OAAW,OAAM,IAAI,MAAM,iBAAiB;AACxE,MAAI,OAAO,QAAQ,SAAU,OAAM,IAAI,MAAM,sBAAsB;AACnE,MAAI,QAAQ,kBAAkB,kBAAkB,GAAG,UAAU,GAAG,CAAC;AACjE,SAAO;AACT;AAEA,SAAS,kBACP,KACA,MACA;AACA,MAAI,WAAW,IAAI,MAAM,CAAC,GACxB,IAAI,IAAI,QACR,MAAM,IAAI,MACV,MACA;AACF,SAAO,MAAM,KAAK;AAChB,YAAQ,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC;AAC1C,WAAO,SAAS,KAAK;AACrB,aAAS,KAAK,IAAI,SAAS,CAAC;AAC5B,aAAS,CAAC,IAAI;AAAA,EAChB;AACA,SAAO,SAAS,MAAM,GAAG;AAC3B;AAGA,IAAO,sBAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["// http://stackoverflow.com/questions/11935175/sampling-a-random-subset-from-an-array\nimport { Feature, FeatureCollection, Geometry, GeometryObject } from \"geojson\";\nimport { featureCollection } from \"@turf/helpers\";\n\n/**\n * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.\n *\n * @function\n * @param {FeatureCollection} featurecollection set of input features\n * @param {number} num number of features to select\n * @returns {FeatureCollection} a FeatureCollection with `n` features\n * @example\n * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});\n *\n * var sample = turf.sample(points, 5);\n *\n * //addToMap\n * var addToMap = [points, sample]\n * turf.featureEach(sample, function (currentFeature) {\n * currentFeature.properties['marker-size'] = 'large';\n * currentFeature.properties['marker-color'] = '#000';\n * });\n */\nfunction sample<T extends GeometryObject>(\n fc: FeatureCollection<T>,\n num: number\n): FeatureCollection<T> {\n if (!fc) throw new Error(\"fc is required\");\n if (num === null || num === undefined) throw new Error(\"num is required\");\n if (typeof num !== \"number\") throw new Error(\"num must be a number\");\n var outFC = featureCollection(getRandomSubarray(fc.features, num));\n return outFC;\n}\n\nfunction getRandomSubarray<T extends Geometry>(\n arr: Feature<T>[],\n size: number\n) {\n var shuffled = arr.slice(0),\n i = arr.length,\n min = i - size,\n temp,\n index;\n while (i-- > min) {\n index = Math.floor((i + 1) * Math.random());\n temp = shuffled[index];\n shuffled[index] = shuffled[i];\n shuffled[i] = temp;\n }\n return shuffled.slice(min);\n}\n\nexport { sample };\nexport default sample;\n"],"mappings":";AAEA,SAAS,yBAAyB;AAqBlC,SAAS,OACP,IACA,KACsB;AACtB,MAAI,CAAC,GAAI,OAAM,IAAI,MAAM,gBAAgB;AACzC,MAAI,QAAQ,QAAQ,QAAQ,OAAW,OAAM,IAAI,MAAM,iBAAiB;AACxE,MAAI,OAAO,QAAQ,SAAU,OAAM,IAAI,MAAM,sBAAsB;AACnE,MAAI,QAAQ,kBAAkB,kBAAkB,GAAG,UAAU,GAAG,CAAC;AACjE,SAAO;AACT;AAEA,SAAS,kBACP,KACA,MACA;AACA,MAAI,WAAW,IAAI,MAAM,CAAC,GACxB,IAAI,IAAI,QACR,MAAM,IAAI,MACV,MACA;AACF,SAAO,MAAM,KAAK;AAChB,YAAQ,KAAK,OAAO,IAAI,KAAK,KAAK,OAAO,CAAC;AAC1C,WAAO,SAAS,KAAK;AACrB,aAAS,KAAK,IAAI,SAAS,CAAC;AAC5B,aAAS,CAAC,IAAI;AAAA,EAChB;AACA,SAAO,SAAS,MAAM,GAAG;AAC3B;AAGA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/sample",
3
- "version": "7.2.0",
4
- "description": "turf sample module",
3
+ "version": "7.3.1",
4
+ "description": "Takes a FeatureCollection and returns a FeatureCollection with given number of features at random.",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
7
7
  "bugs": {
@@ -47,23 +47,22 @@
47
47
  "bench": "tsx bench.ts",
48
48
  "build": "tsup --config ../../tsup.config.ts",
49
49
  "docs": "tsx ../../scripts/generate-readmes.ts",
50
- "test": "npm-run-all --npm-path npm test:*",
50
+ "test": "pnpm run /test:.*/",
51
51
  "test:tape": "tsx test.ts"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/benchmark": "^2.1.5",
55
- "@types/tape": "^4.13.4",
55
+ "@types/tape": "^5.8.1",
56
56
  "benchmark": "^2.1.4",
57
- "npm-run-all": "^4.1.5",
58
57
  "tape": "^5.9.0",
59
- "tsup": "^8.3.5",
60
- "tsx": "^4.19.2",
61
- "typescript": "^5.5.4"
58
+ "tsup": "^8.4.0",
59
+ "tsx": "^4.19.4",
60
+ "typescript": "^5.8.3"
62
61
  },
63
62
  "dependencies": {
64
- "@turf/helpers": "^7.2.0",
63
+ "@turf/helpers": "7.3.1",
65
64
  "@types/geojson": "^7946.0.10",
66
65
  "tslib": "^2.8.1"
67
66
  },
68
- "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
67
+ "gitHead": "b7f1b4eafb760431e03955499d8eac9489438219"
69
68
  }