@turf/sample 7.0.0-alpha.1 → 7.0.0-alpha.111

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
@@ -36,26 +36,21 @@ Returns **[FeatureCollection][3]** a FeatureCollection with `n` features
36
36
 
37
37
  [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
38
38
 
39
- <!-- This file is automatically generated. Please don't edit it directly:
40
- if you find an error, edit the source file (likely index.js), and re-run
41
- ./scripts/generate-readmes in the turf project. -->
39
+ <!-- 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. -->
42
40
 
43
41
  ---
44
42
 
45
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
46
- module collection dedicated to geographic algorithms. It is maintained in the
47
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
48
- PRs and issues.
43
+ This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
49
44
 
50
45
  ### Installation
51
46
 
52
- Install this module individually:
47
+ Install this single module individually:
53
48
 
54
49
  ```sh
55
50
  $ npm install @turf/sample
56
51
  ```
57
52
 
58
- Or install the Turf module that includes it as a function:
53
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
59
54
 
60
55
  ```sh
61
56
  $ npm install @turf/turf
@@ -0,0 +1,33 @@
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
5
+ var _helpers = require('@turf/helpers');
6
+ function sample(fc, num) {
7
+ if (!fc)
8
+ throw new Error("fc is required");
9
+ if (num === null || num === void 0)
10
+ throw new Error("num is required");
11
+ if (typeof num !== "number")
12
+ throw new Error("num must be a number");
13
+ var outFC = _helpers.featureCollection.call(void 0, getRandomSubarray(fc.features, num));
14
+ return outFC;
15
+ }
16
+ __name(sample, "sample");
17
+ function getRandomSubarray(arr, size) {
18
+ var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
19
+ while (i-- > min) {
20
+ index = Math.floor((i + 1) * Math.random());
21
+ temp = shuffled[index];
22
+ shuffled[index] = shuffled[i];
23
+ shuffled[i] = temp;
24
+ }
25
+ return shuffled.slice(min);
26
+ }
27
+ __name(getRandomSubarray, "getRandomSubarray");
28
+ var turf_sample_default = sample;
29
+
30
+
31
+
32
+ exports.default = turf_sample_default; exports.sample = sample;
33
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +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"]}
@@ -0,0 +1,24 @@
1
+ import { GeometryObject, FeatureCollection } from 'geojson';
2
+
3
+ /**
4
+ * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.
5
+ *
6
+ * @name sample
7
+ * @param {FeatureCollection} featurecollection set of input features
8
+ * @param {number} num number of features to select
9
+ * @returns {FeatureCollection} a FeatureCollection with `n` features
10
+ * @example
11
+ * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});
12
+ *
13
+ * var sample = turf.sample(points, 5);
14
+ *
15
+ * //addToMap
16
+ * var addToMap = [points, sample]
17
+ * turf.featureEach(sample, function (currentFeature) {
18
+ * currentFeature.properties['marker-size'] = 'large';
19
+ * currentFeature.properties['marker-color'] = '#000';
20
+ * });
21
+ */
22
+ declare function sample<T extends GeometryObject>(fc: FeatureCollection<T>, num: number): FeatureCollection<T>;
23
+
24
+ export { sample as default, sample };
@@ -0,0 +1,24 @@
1
+ import { GeometryObject, FeatureCollection } from 'geojson';
2
+
3
+ /**
4
+ * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.
5
+ *
6
+ * @name sample
7
+ * @param {FeatureCollection} featurecollection set of input features
8
+ * @param {number} num number of features to select
9
+ * @returns {FeatureCollection} a FeatureCollection with `n` features
10
+ * @example
11
+ * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});
12
+ *
13
+ * var sample = turf.sample(points, 5);
14
+ *
15
+ * //addToMap
16
+ * var addToMap = [points, sample]
17
+ * turf.featureEach(sample, function (currentFeature) {
18
+ * currentFeature.properties['marker-size'] = 'large';
19
+ * currentFeature.properties['marker-color'] = '#000';
20
+ * });
21
+ */
22
+ declare function sample<T extends GeometryObject>(fc: FeatureCollection<T>, num: number): FeatureCollection<T>;
23
+
24
+ export { sample as default, sample };
@@ -0,0 +1,33 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { featureCollection } from "@turf/helpers";
6
+ function sample(fc, num) {
7
+ if (!fc)
8
+ throw new Error("fc is required");
9
+ if (num === null || num === void 0)
10
+ throw new Error("num is required");
11
+ if (typeof num !== "number")
12
+ throw new Error("num must be a number");
13
+ var outFC = featureCollection(getRandomSubarray(fc.features, num));
14
+ return outFC;
15
+ }
16
+ __name(sample, "sample");
17
+ function getRandomSubarray(arr, size) {
18
+ var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
19
+ while (i-- > min) {
20
+ index = Math.floor((i + 1) * Math.random());
21
+ temp = shuffled[index];
22
+ shuffled[index] = shuffled[i];
23
+ shuffled[i] = temp;
24
+ }
25
+ return shuffled.slice(min);
26
+ }
27
+ __name(getRandomSubarray, "getRandomSubarray");
28
+ var turf_sample_default = sample;
29
+ export {
30
+ turf_sample_default as default,
31
+ sample
32
+ };
33
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +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":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/sample",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.111+08576cb50",
4
4
  "description": "turf sample module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -22,38 +22,47 @@
22
22
  "sample",
23
23
  "turf"
24
24
  ],
25
- "main": "dist/js/index.js",
26
- "module": "dist/es/index.js",
25
+ "type": "commonjs",
26
+ "main": "dist/cjs/index.cjs",
27
+ "module": "dist/esm/index.mjs",
28
+ "types": "dist/cjs/index.d.ts",
27
29
  "exports": {
28
30
  "./package.json": "./package.json",
29
31
  ".": {
30
- "types": "./index.d.ts",
31
- "import": "./dist/es/index.js",
32
- "require": "./dist/js/index.js"
32
+ "import": {
33
+ "types": "./dist/esm/index.d.mts",
34
+ "default": "./dist/esm/index.mjs"
35
+ },
36
+ "require": {
37
+ "types": "./dist/cjs/index.d.ts",
38
+ "default": "./dist/cjs/index.cjs"
39
+ }
33
40
  }
34
41
  },
35
- "types": "index.d.ts",
36
42
  "sideEffects": false,
37
43
  "files": [
38
- "dist",
39
- "index.d.ts"
44
+ "dist"
40
45
  ],
41
46
  "scripts": {
42
- "bench": "tsx bench.js",
43
- "build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
44
- "docs": "tsx ../../scripts/generate-readmes",
45
- "test": "npm-run-all test:*",
46
- "test:tape": "tsx test.js"
47
+ "bench": "tsx bench.ts",
48
+ "build": "tsup --config ../../tsup.config.ts",
49
+ "docs": "tsx ../../scripts/generate-readmes.ts",
50
+ "test": "npm-run-all --npm-path npm test:*",
51
+ "test:tape": "tsx test.ts"
47
52
  },
48
53
  "devDependencies": {
49
- "benchmark": "*",
50
- "npm-run-all": "*",
51
- "rollup": "*",
52
- "tape": "*",
53
- "tsx": "*"
54
+ "@types/benchmark": "^2.1.5",
55
+ "@types/tape": "^4.2.32",
56
+ "benchmark": "^2.1.4",
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"
54
62
  },
55
63
  "dependencies": {
56
- "@turf/helpers": "^7.0.0-alpha.1"
64
+ "@turf/helpers": "^7.0.0-alpha.111+08576cb50",
65
+ "tslib": "^2.6.2"
57
66
  },
58
- "gitHead": "cf7a0c507b017ca066acffd0ce23bda5b393fb5a"
67
+ "gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
59
68
  }
package/dist/es/index.js DELETED
@@ -1,50 +0,0 @@
1
- import { featureCollection } from '@turf/helpers';
2
-
3
- // http://stackoverflow.com/questions/11935175/sampling-a-random-subset-from-an-array
4
-
5
- /**
6
- * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.
7
- *
8
- * @name sample
9
- * @param {FeatureCollection} featurecollection set of input features
10
- * @param {number} num number of features to select
11
- * @returns {FeatureCollection} a FeatureCollection with `n` features
12
- * @example
13
- * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});
14
- *
15
- * var sample = turf.sample(points, 5);
16
- *
17
- * //addToMap
18
- * var addToMap = [points, sample]
19
- * turf.featureEach(sample, function (currentFeature) {
20
- * currentFeature.properties['marker-size'] = 'large';
21
- * currentFeature.properties['marker-color'] = '#000';
22
- * });
23
- */
24
- function sample(featurecollection, num) {
25
- if (!featurecollection) throw new Error("featurecollection is required");
26
- if (num === null || num === undefined) throw new Error("num is required");
27
- if (typeof num !== "number") throw new Error("num must be a number");
28
-
29
- var outFC = featureCollection(
30
- getRandomSubarray(featurecollection.features, num)
31
- );
32
- return outFC;
33
- }
34
-
35
- function getRandomSubarray(arr, size) {
36
- var shuffled = arr.slice(0),
37
- i = arr.length,
38
- min = i - size,
39
- temp,
40
- index;
41
- while (i-- > min) {
42
- index = Math.floor((i + 1) * Math.random());
43
- temp = shuffled[index];
44
- shuffled[index] = shuffled[i];
45
- shuffled[i] = temp;
46
- }
47
- return shuffled.slice(min);
48
- }
49
-
50
- export default sample;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,53 +0,0 @@
1
- 'use strict';
2
-
3
- var helpers = require('@turf/helpers');
4
-
5
- // http://stackoverflow.com/questions/11935175/sampling-a-random-subset-from-an-array
6
-
7
- /**
8
- * Takes a {@link FeatureCollection} and returns a FeatureCollection with given number of {@link Feature|features} at random.
9
- *
10
- * @name sample
11
- * @param {FeatureCollection} featurecollection set of input features
12
- * @param {number} num number of features to select
13
- * @returns {FeatureCollection} a FeatureCollection with `n` features
14
- * @example
15
- * var points = turf.randomPoint(100, {bbox: [-80, 30, -60, 60]});
16
- *
17
- * var sample = turf.sample(points, 5);
18
- *
19
- * //addToMap
20
- * var addToMap = [points, sample]
21
- * turf.featureEach(sample, function (currentFeature) {
22
- * currentFeature.properties['marker-size'] = 'large';
23
- * currentFeature.properties['marker-color'] = '#000';
24
- * });
25
- */
26
- function sample(featurecollection, num) {
27
- if (!featurecollection) throw new Error("featurecollection is required");
28
- if (num === null || num === undefined) throw new Error("num is required");
29
- if (typeof num !== "number") throw new Error("num must be a number");
30
-
31
- var outFC = helpers.featureCollection(
32
- getRandomSubarray(featurecollection.features, num)
33
- );
34
- return outFC;
35
- }
36
-
37
- function getRandomSubarray(arr, size) {
38
- var shuffled = arr.slice(0),
39
- i = arr.length,
40
- min = i - size,
41
- temp,
42
- index;
43
- while (i-- > min) {
44
- index = Math.floor((i + 1) * Math.random());
45
- temp = shuffled[index];
46
- shuffled[index] = shuffled[i];
47
- shuffled[i] = temp;
48
- }
49
- return shuffled.slice(min);
50
- }
51
-
52
- module.exports = sample;
53
- module.exports.default = sample;
package/index.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { FeatureCollection, GeometryObject } from "geojson";
2
-
3
- /**
4
- * http://turfjs.org/docs/#sample
5
- */
6
- export default function sample<T extends GeometryObject>(
7
- features: FeatureCollection<T>,
8
- num: number
9
- ): FeatureCollection<T>;