@turf/sample 7.1.0 → 7.2.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 +2 -1
- package/dist/cjs/index.cjs +3 -6
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +3 -6
- package/dist/esm/index.js.map +1 -1
- package/package.json +9 -9
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
|
-
* `
|
|
11
|
+
* `fc` **[FeatureCollection][1]\<T>** 
|
|
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
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -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
|
-
|
|
6
|
-
if (num
|
|
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
|
}
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-sample/dist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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/cjs/index.d.cts
CHANGED
|
@@ -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
|
-
* @
|
|
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.d.ts
CHANGED
|
@@ -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
|
-
* @
|
|
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
|
-
|
|
6
|
-
if (num
|
|
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
|
}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -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 * @
|
|
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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/sample",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "turf sample module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@types/benchmark": "^2.1.5",
|
|
55
|
-
"@types/tape": "^4.
|
|
55
|
+
"@types/tape": "^4.13.4",
|
|
56
56
|
"benchmark": "^2.1.4",
|
|
57
57
|
"npm-run-all": "^4.1.5",
|
|
58
|
-
"tape": "^5.
|
|
59
|
-
"tsup": "^8.
|
|
60
|
-
"tsx": "^4.
|
|
61
|
-
"typescript": "^5.
|
|
58
|
+
"tape": "^5.9.0",
|
|
59
|
+
"tsup": "^8.3.5",
|
|
60
|
+
"tsx": "^4.19.2",
|
|
61
|
+
"typescript": "^5.5.4"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@turf/helpers": "^7.
|
|
64
|
+
"@turf/helpers": "^7.2.0",
|
|
65
65
|
"@types/geojson": "^7946.0.10",
|
|
66
|
-
"tslib": "^2.
|
|
66
|
+
"tslib": "^2.8.1"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
|
|
69
69
|
}
|