@turf/clusters 6.4.0 → 7.0.0-alpha.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
@@ -6,12 +6,12 @@
6
6
 
7
7
  Get Cluster
8
8
 
9
- **Parameters**
9
+ ### Parameters
10
10
 
11
- - `geojson` **[FeatureCollection][1]** GeoJSON Features
12
- - `filter` **any** Filter used on GeoJSON properties to get Cluster
11
+ * `geojson` **[FeatureCollection][1]** GeoJSON Features
12
+ * `filter` **any** Filter used on GeoJSON properties to get Cluster
13
13
 
14
- **Examples**
14
+ ### Examples
15
15
 
16
16
  ```javascript
17
17
  var geojson = turf.featureCollection([
@@ -44,11 +44,11 @@ Callback for clusterEach
44
44
 
45
45
  Type: [Function][2]
46
46
 
47
- **Parameters**
47
+ ### Parameters
48
48
 
49
- - `cluster` **[FeatureCollection][1]?** The current cluster being processed.
50
- - `clusterValue` **any?** Value used to create cluster being processed.
51
- - `currentIndex` **[number][3]?** The index of the current element being processed in the array.Starts at index 0
49
+ * `cluster` **[FeatureCollection][1]?** The current cluster being processed.
50
+ * `clusterValue` **any?** Value used to create cluster being processed.
51
+ * `currentIndex` **[number][3]?** The index of the current element being processed in the array.Starts at index 0
52
52
 
53
53
  Returns **void**
54
54
 
@@ -56,13 +56,13 @@ Returns **void**
56
56
 
57
57
  clusterEach
58
58
 
59
- **Parameters**
59
+ ### Parameters
60
60
 
61
- - `geojson` **[FeatureCollection][1]** GeoJSON Features
62
- - `property` **([string][4] \| [number][3])** GeoJSON property key/value used to create clusters
63
- - `callback` **[Function][2]** a method that takes (cluster, clusterValue, currentIndex)
61
+ * `geojson` **[FeatureCollection][1]** GeoJSON Features
62
+ * `property` **([string][4] | [number][3])** GeoJSON property key/value used to create clusters
63
+ * `callback` **[Function][2]** a method that takes (cluster, clusterValue, currentIndex)
64
64
 
65
- **Examples**
65
+ ### Examples
66
66
 
67
67
  ```javascript
68
68
  var geojson = turf.featureCollection([
@@ -107,37 +107,37 @@ on whether the reduce method has an initialValue argument.
107
107
 
108
108
  If an initialValue is provided to the reduce method:
109
109
 
110
- - The previousValue argument is initialValue.
111
- - The currentValue argument is the value of the first element present in the array.
110
+ * The previousValue argument is initialValue.
111
+ * The currentValue argument is the value of the first element present in the array.
112
112
 
113
113
  If an initialValue is not provided:
114
114
 
115
- - The previousValue argument is the value of the first element present in the array.
116
- - The currentValue argument is the value of the second element present in the array.
115
+ * The previousValue argument is the value of the first element present in the array.
116
+ * The currentValue argument is the value of the second element present in the array.
117
117
 
118
118
  Type: [Function][2]
119
119
 
120
- **Parameters**
120
+ ### Parameters
121
121
 
122
- - `previousValue` **any?** The accumulated value previously returned in the last invocation
122
+ * `previousValue` **any?** The accumulated value previously returned in the last invocation
123
123
  of the callback, or initialValue, if supplied.
124
- - `cluster` **[FeatureCollection][1]?** The current cluster being processed.
125
- - `clusterValue` **any?** Value used to create cluster being processed.
126
- - `currentIndex` **[number][3]?** The index of the current element being processed in the
124
+ * `cluster` **[FeatureCollection][1]?** The current cluster being processed.
125
+ * `clusterValue` **any?** Value used to create cluster being processed.
126
+ * `currentIndex` **[number][3]?** The index of the current element being processed in the
127
127
  array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
128
128
 
129
129
  ## clusterReduce
130
130
 
131
131
  Reduce clusters in GeoJSON Features, similar to Array.reduce()
132
132
 
133
- **Parameters**
133
+ ### Parameters
134
134
 
135
- - `geojson` **[FeatureCollection][1]** GeoJSON Features
136
- - `property` **([string][4] \| [number][3])** GeoJSON property key/value used to create clusters
137
- - `callback` **[Function][2]** a method that takes (previousValue, cluster, clusterValue, currentIndex)
138
- - `initialValue` **any?** Value to use as the first argument to the first call of the callback.
135
+ * `geojson` **[FeatureCollection][1]** GeoJSON Features
136
+ * `property` **([string][4] | [number][3])** GeoJSON property key/value used to create clusters
137
+ * `callback` **[Function][2]** a method that takes (previousValue, cluster, clusterValue, currentIndex)
138
+ * `initialValue` **any?** Value to use as the first argument to the first call of the callback.
139
139
 
140
- **Examples**
140
+ ### Examples
141
141
 
142
142
  ```javascript
143
143
  var geojson = turf.featureCollection([
package/dist/es/index.js CHANGED
@@ -208,9 +208,9 @@ export function createBins(geojson, property) {
208
208
  var bins = {};
209
209
  featureEach(geojson, function (feature, i) {
210
210
  var properties = feature.properties || {};
211
- if (properties.hasOwnProperty(String(property))) {
211
+ if (Object.prototype.hasOwnProperty.call(properties, String(property))) {
212
212
  var value = properties[property];
213
- if (bins.hasOwnProperty(value))
213
+ if (Object.prototype.hasOwnProperty.call(bins, value))
214
214
  bins[value].push(i);
215
215
  else
216
216
  bins[value] = [i];
@@ -232,7 +232,7 @@ export function applyFilter(properties, filter) {
232
232
  var filterType = typeof filter;
233
233
  // String & Number
234
234
  if (filterType === "number" || filterType === "string")
235
- return properties.hasOwnProperty(filter);
235
+ return Object.prototype.hasOwnProperty.call(properties, filter);
236
236
  // Array
237
237
  else if (Array.isArray(filter)) {
238
238
  for (var i = 0; i < filter.length; i++) {
@@ -287,7 +287,7 @@ export function filterProperties(properties, keys) {
287
287
  var newProperties = {};
288
288
  for (var i = 0; i < keys.length; i++) {
289
289
  var key = keys[i];
290
- if (properties.hasOwnProperty(key))
290
+ if (Object.prototype.hasOwnProperty.call(properties, key))
291
291
  newProperties[key] = properties[key];
292
292
  }
293
293
  return newProperties;
@@ -1,4 +1,4 @@
1
- import { FeatureCollection } from "@turf/helpers";
1
+ import { FeatureCollection, GeometryObject } from "geojson";
2
2
  /**
3
3
  * Get Cluster
4
4
  *
@@ -28,7 +28,7 @@ import { FeatureCollection } from "@turf/helpers";
28
28
  * turf.getCluster(clustered, {'marker-symbol': 'square'}).length;
29
29
  * //= 1
30
30
  */
31
- export declare function getCluster<G extends any, P = any>(geojson: FeatureCollection<G, P>, filter: any): FeatureCollection<G, P>;
31
+ export declare function getCluster<G extends GeometryObject, P = any>(geojson: FeatureCollection<G, P>, filter: any): FeatureCollection<G, P>;
32
32
  /**
33
33
  * Callback for clusterEach
34
34
  *
@@ -77,7 +77,7 @@ export declare function getCluster<G extends any, P = any>(geojson: FeatureColle
77
77
  * values.push(clusterValue);
78
78
  * });
79
79
  */
80
- export declare function clusterEach<G = any, P = any>(geojson: FeatureCollection<G, P>, property: number | string, callback: (cluster?: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void): void;
80
+ export declare function clusterEach<G extends GeometryObject, P = any>(geojson: FeatureCollection<G, P>, property: number | string, callback: (cluster: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void): void;
81
81
  /**
82
82
  * Callback for clusterReduce
83
83
  *
@@ -141,7 +141,7 @@ export declare function clusterEach<G = any, P = any>(geojson: FeatureCollection
141
141
  * return previousValue.concat(clusterValue);
142
142
  * }, []);
143
143
  */
144
- export declare function clusterReduce<G = any, P = any>(geojson: FeatureCollection<G, P>, property: number | string, callback: (previousValue?: any, cluster?: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void, initialValue?: any): void;
144
+ export declare function clusterReduce<G extends GeometryObject, P = any>(geojson: FeatureCollection<G, P>, property: number | string, callback: (previousValue: any | undefined, cluster: FeatureCollection<G, P>, clusterValue?: any, currentIndex?: number) => void, initialValue?: any): void;
145
145
  /**
146
146
  * Create Bins
147
147
  *
@@ -168,7 +168,7 @@ export declare function createBins(geojson: FeatureCollection<any>, property: st
168
168
  * @param {*} filter Filter
169
169
  * @returns {boolean} applied Filter to properties
170
170
  */
171
- export declare function applyFilter(properties: any, filter: any): any;
171
+ export declare function applyFilter(properties: any, filter: any): boolean;
172
172
  /**
173
173
  * Properties contains filter (does not apply deepEqual operations)
174
174
  *
package/dist/js/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var meta_1 = require("@turf/meta");
4
- var helpers_1 = require("@turf/helpers");
3
+ const meta_1 = require("@turf/meta");
4
+ const helpers_1 = require("@turf/helpers");
5
5
  /**
6
6
  * Get Cluster
7
7
  *
@@ -213,9 +213,9 @@ function createBins(geojson, property) {
213
213
  var bins = {};
214
214
  meta_1.featureEach(geojson, function (feature, i) {
215
215
  var properties = feature.properties || {};
216
- if (properties.hasOwnProperty(String(property))) {
216
+ if (Object.prototype.hasOwnProperty.call(properties, String(property))) {
217
217
  var value = properties[property];
218
- if (bins.hasOwnProperty(value))
218
+ if (Object.prototype.hasOwnProperty.call(bins, value))
219
219
  bins[value].push(i);
220
220
  else
221
221
  bins[value] = [i];
@@ -238,7 +238,7 @@ function applyFilter(properties, filter) {
238
238
  var filterType = typeof filter;
239
239
  // String & Number
240
240
  if (filterType === "number" || filterType === "string")
241
- return properties.hasOwnProperty(filter);
241
+ return Object.prototype.hasOwnProperty.call(properties, filter);
242
242
  // Array
243
243
  else if (Array.isArray(filter)) {
244
244
  for (var i = 0; i < filter.length; i++) {
@@ -295,7 +295,7 @@ function filterProperties(properties, keys) {
295
295
  var newProperties = {};
296
296
  for (var i = 0; i < keys.length; i++) {
297
297
  var key = keys[i];
298
- if (properties.hasOwnProperty(key))
298
+ if (Object.prototype.hasOwnProperty.call(properties, key))
299
299
  newProperties[key] = properties[key];
300
300
  }
301
301
  return newProperties;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/clusters",
3
- "version": "6.4.0",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "turf clusters module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -15,6 +15,7 @@
15
15
  "type": "git",
16
16
  "url": "git://github.com/Turfjs/turf.git"
17
17
  },
18
+ "funding": "https://opencollective.com/turf",
18
19
  "publishConfig": {
19
20
  "access": "public"
20
21
  },
@@ -47,7 +48,7 @@
47
48
  "docs": "node ../../scripts/generate-readmes",
48
49
  "test": "npm-run-all test:*",
49
50
  "test:tape": "ts-node -r esm test.js",
50
- "test:types": "tsc --esModuleInterop --noEmit types.ts"
51
+ "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@types/tape": "*",
@@ -59,8 +60,9 @@
59
60
  "typescript": "*"
60
61
  },
61
62
  "dependencies": {
62
- "@turf/helpers": "^6.4.0",
63
- "@turf/meta": "^6.4.0"
63
+ "@turf/helpers": "^7.0.0-alpha.0",
64
+ "@turf/meta": "^7.0.0-alpha.0",
65
+ "tslib": "^2.3.0"
64
66
  },
65
- "gitHead": "1e62773cfc88c627cca8effcb5c14cfb65a905ac"
67
+ "gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189"
66
68
  }