@turf/sample 7.1.0 → 7.3.0

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.
package/README.md CHANGED
@@ -8,8 +8,9 @@ Takes a [FeatureCollection][1] and returns a FeatureCollection with given number
8
8
 
9
9
  ### Parameters
10
10
 
11
- * `featurecollection` **[FeatureCollection][1]** set of input features
11
+ * `fc` **[FeatureCollection][1]\<T>**&#x20;
12
12
  * `num` **[number][3]** number of features to select
13
+ * `featurecollection` **[FeatureCollection][1]** set of input features
13
14
 
14
15
  ### Examples
15
16
 
@@ -1,12 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
2
  var _helpers = require('@turf/helpers');
3
3
  function sample(fc, num) {
4
- if (!fc)
5
- throw new Error("fc is required");
6
- if (num === null || num === void 0)
7
- throw new Error("num is required");
8
- if (typeof num !== "number")
9
- throw new Error("num must be a number");
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");
10
7
  var outFC = _helpers.featureCollection.call(void 0, getRandomSubarray(fc.features, num));
11
8
  return outFC;
12
9
  }
@@ -20,9 +17,9 @@ function getRandomSubarray(arr, size) {
20
17
  }
21
18
  return shuffled.slice(min);
22
19
  }
23
- var turf_sample_default = sample;
20
+ var index_default = sample;
24
21
 
25
22
 
26
23
 
27
- exports.default = turf_sample_default; exports.sample = sample;
24
+ exports.default = index_default; exports.sample = sample;
28
25
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAEA,SAAS,yBAAyB;AAqBlC,SAAS,OACP,IACA,KACsB;AACtB,MAAI,CAAC;AAAI,UAAM,IAAI,MAAM,gBAAgB;AACzC,MAAI,QAAQ,QAAQ,QAAQ;AAAW,UAAM,IAAI,MAAM,iBAAiB;AACxE,MAAI,OAAO,QAAQ;AAAU,UAAM,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","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 * @name sample\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"]}
@@ -3,7 +3,7 @@ import { GeometryObject, FeatureCollection } from 'geojson';
3
3
  /**
4
4
  * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.
5
5
  *
6
- * @name sample
6
+ * @function
7
7
  * @param {FeatureCollection} featurecollection set of input features
8
8
  * @param {number} num number of features to select
9
9
  * @returns {FeatureCollection} a FeatureCollection with `n` features
@@ -3,7 +3,7 @@ import { GeometryObject, FeatureCollection } from 'geojson';
3
3
  /**
4
4
  * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.
5
5
  *
6
- * @name sample
6
+ * @function
7
7
  * @param {FeatureCollection} featurecollection set of input features
8
8
  * @param {number} num number of features to select
9
9
  * @returns {FeatureCollection} a FeatureCollection with `n` features
package/dist/esm/index.js CHANGED
@@ -1,12 +1,9 @@
1
1
  // index.ts
2
2
  import { featureCollection } from "@turf/helpers";
3
3
  function sample(fc, num) {
4
- if (!fc)
5
- throw new Error("fc is required");
6
- if (num === null || num === void 0)
7
- throw new Error("num is required");
8
- if (typeof num !== "number")
9
- throw new Error("num must be a number");
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");
10
7
  var outFC = featureCollection(getRandomSubarray(fc.features, num));
11
8
  return outFC;
12
9
  }
@@ -20,9 +17,9 @@ function getRandomSubarray(arr, size) {
20
17
  }
21
18
  return shuffled.slice(min);
22
19
  }
23
- var turf_sample_default = sample;
20
+ var index_default = sample;
24
21
  export {
25
- turf_sample_default as default,
22
+ index_default as default,
26
23
  sample
27
24
  };
28
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 * @name sample\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;AAAI,UAAM,IAAI,MAAM,gBAAgB;AACzC,MAAI,QAAQ,QAAQ,QAAQ;AAAW,UAAM,IAAI,MAAM,iBAAiB;AACxE,MAAI,OAAO,QAAQ;AAAU,UAAM,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.1.0",
4
- "description": "turf sample module",
3
+ "version": "7.3.0",
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": {
@@ -52,18 +52,18 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/benchmark": "^2.1.5",
55
- "@types/tape": "^4.2.32",
55
+ "@types/tape": "^5.8.1",
56
56
  "benchmark": "^2.1.4",
57
57
  "npm-run-all": "^4.1.5",
58
- "tape": "^5.7.2",
59
- "tsup": "^8.0.1",
60
- "tsx": "^4.6.2",
61
- "typescript": "^5.2.2"
58
+ "tape": "^5.9.0",
59
+ "tsup": "^8.4.0",
60
+ "tsx": "^4.19.4",
61
+ "typescript": "^5.8.3"
62
62
  },
63
63
  "dependencies": {
64
- "@turf/helpers": "^7.1.0",
64
+ "@turf/helpers": "7.3.0",
65
65
  "@types/geojson": "^7946.0.10",
66
- "tslib": "^2.6.2"
66
+ "tslib": "^2.8.1"
67
67
  },
68
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
68
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
69
69
  }