@turf/sample 7.0.0 → 7.1.0-alpha.70

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,8 @@ Takes a [FeatureCollection][1] and returns a FeatureCollection with given number
8
8
 
9
9
  ### Parameters
10
10
 
11
- * `featurecollection` **[FeatureCollection][3]** set of input features
12
- * `num` **[number][4]** number of features to select
11
+ * `featurecollection` **[FeatureCollection][1]** set of input features
12
+ * `num` **[number][3]** number of features to select
13
13
 
14
14
  ### Examples
15
15
 
@@ -26,15 +26,13 @@ turf.featureEach(sample, function (currentFeature) {
26
26
  });
27
27
  ```
28
28
 
29
- Returns **[FeatureCollection][3]** a FeatureCollection with `n` features
29
+ Returns **[FeatureCollection][1]** a FeatureCollection with `n` features
30
30
 
31
31
  [1]: https://tools.ietf.org/html/rfc7946#section-3.3
32
32
 
33
33
  [2]: https://tools.ietf.org/html/rfc7946#section-3.2
34
34
 
35
- [3]: https://tools.ietf.org/html/rfc7946#section-3.3
36
-
37
- [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
35
+ [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
38
36
 
39
37
  <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
40
38
 
@@ -1,7 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
- // index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
5
2
  var _helpers = require('@turf/helpers');
6
3
  function sample(fc, num) {
7
4
  if (!fc)
@@ -13,7 +10,6 @@ function sample(fc, num) {
13
10
  var outFC = _helpers.featureCollection.call(void 0, getRandomSubarray(fc.features, num));
14
11
  return outFC;
15
12
  }
16
- __name(sample, "sample");
17
13
  function getRandomSubarray(arr, size) {
18
14
  var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
19
15
  while (i-- > min) {
@@ -24,7 +20,6 @@ function getRandomSubarray(arr, size) {
24
20
  }
25
21
  return shuffled.slice(min);
26
22
  }
27
- __name(getRandomSubarray, "getRandomSubarray");
28
23
  var turf_sample_default = sample;
29
24
 
30
25
 
@@ -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;AATS;AAWT,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;AAhBS;AAmBT,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":["../../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"]}
package/dist/esm/index.js CHANGED
@@ -1,6 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // index.ts
5
2
  import { featureCollection } from "@turf/helpers";
6
3
  function sample(fc, num) {
@@ -13,7 +10,6 @@ function sample(fc, num) {
13
10
  var outFC = featureCollection(getRandomSubarray(fc.features, num));
14
11
  return outFC;
15
12
  }
16
- __name(sample, "sample");
17
13
  function getRandomSubarray(arr, size) {
18
14
  var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
19
15
  while (i-- > min) {
@@ -24,7 +20,6 @@ function getRandomSubarray(arr, size) {
24
20
  }
25
21
  return shuffled.slice(min);
26
22
  }
27
- __name(getRandomSubarray, "getRandomSubarray");
28
23
  var turf_sample_default = sample;
29
24
  export {
30
25
  turf_sample_default as default,
@@ -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;AATS;AAWT,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;AAhBS;AAmBT,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 * @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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/sample",
3
- "version": "7.0.0",
3
+ "version": "7.1.0-alpha.70+948cdafaf",
4
4
  "description": "turf sample module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -61,8 +61,9 @@
61
61
  "typescript": "^5.2.2"
62
62
  },
63
63
  "dependencies": {
64
- "@turf/helpers": "^7.0.0",
64
+ "@turf/helpers": "^7.1.0-alpha.70+948cdafaf",
65
+ "@types/geojson": "^7946.0.10",
65
66
  "tslib": "^2.6.2"
66
67
  },
67
- "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
68
+ "gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
68
69
  }