Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/center-mean

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/center-mean - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

main.mjs

17

index.js

@@ -33,3 +33,3 @@ import { geomEach, coordEach } from '@turf/meta';

var properties = options.properties;
var weight = options.weight;
var weightTerm = options.weight;

@@ -43,10 +43,11 @@ // Input validation

geomEach(geojson, function (geom, featureIndex, properties) {
var weightValue = properties[weight] || 1;
if (!isNumber(weightValue)) throw new Error('weight value must be a number for feature index ' + featureIndex);
weightValue = Number(weightValue);
if (weightValue > 0) {
var weight = properties[weightTerm];
weight = (weight === undefined || weight === null) ? 1 : weight;
if (!isNumber(weight)) throw new Error('weight value must be a number for feature index ' + featureIndex);
weight = Number(weight);
if (weight > 0) {
coordEach(geom, function (coord) {
sumXs += coord[0] * weightValue;
sumYs += coord[1] * weightValue;
sumNs += weightValue;
sumXs += coord[0] * weight;
sumYs += coord[1] * weight;
sumNs += weight;
});

@@ -53,0 +54,0 @@ }

@@ -33,8 +33,8 @@ 'use strict';

options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
if (!helpers.isObject(options)) { throw new Error('options is invalid'); }
var properties = options.properties;
var weight = options.weight;
var weightTerm = options.weight;
// Input validation
if (!geojson) throw new Error('geojson is required');
if (!geojson) { throw new Error('geojson is required'); }

@@ -45,10 +45,11 @@ var sumXs = 0;

meta.geomEach(geojson, function (geom, featureIndex, properties) {
var weightValue = properties[weight] || 1;
if (!helpers.isNumber(weightValue)) throw new Error('weight value must be a number for feature index ' + featureIndex);
weightValue = Number(weightValue);
if (weightValue > 0) {
var weight = properties[weightTerm];
weight = (weight === undefined || weight === null) ? 1 : weight;
if (!helpers.isNumber(weight)) { throw new Error('weight value must be a number for feature index ' + featureIndex); }
weight = Number(weight);
if (weight > 0) {
meta.coordEach(geom, function (coord) {
sumXs += coord[0] * weightValue;
sumYs += coord[1] * weightValue;
sumNs += weightValue;
sumXs += coord[0] * weight;
sumYs += coord[1] * weight;
sumNs += weight;
});

@@ -55,0 +56,0 @@ }

{
"name": "@turf/center-mean",
"version": "5.0.1",
"version": "5.1.0",
"description": "turf center-mean module",
"main": "main",
"module": "index",
"jsnext:main": "index",
"main": "main.js",
"module": "main.mjs",
"types": "index.d.ts",

@@ -12,3 +11,4 @@ "files": [

"index.d.ts",
"main.js"
"main.js",
"main.mjs"
],

@@ -18,3 +18,4 @@ "scripts": {

"test": "node -r @std/esm test.js",
"bench": "node -r @std/esm bench.js"
"bench": "node -r @std/esm bench.js",
"docs": "node ../../scripts/generate-readmes"
},

@@ -45,4 +46,4 @@ "repository": {

"@std/esm": "*",
"@turf/center": "*",
"@turf/truncate": "*",
"@turf/center": "^5.1.0",
"@turf/truncate": "^5.1.0",
"benchmark": "*",

@@ -52,2 +53,3 @@ "glob": "*",

"rollup": "*",
"rollup-plugin-buble": "*",
"tape": "*",

@@ -57,5 +59,5 @@ "write-json-file": "*"

"dependencies": {
"@turf/bbox": "^5.0.4",
"@turf/helpers": "^5.0.4",
"@turf/meta": "^5.0.4"
"@turf/bbox": "^5.1.0",
"@turf/helpers": "^5.1.0",
"@turf/meta": "^5.1.0"
},

@@ -62,0 +64,0 @@ "@std/esm": {

@@ -7,9 +7,9 @@ # @turf/center-mean

Takes a [Feature](http://geojson.org/geojson-spec.html#feature-objects) or [FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) and returns the mean center. Can be weighted.
Takes a [Feature](https://tools.ietf.org/html/rfc7946#section-3.2) or [FeatureCollection](https://tools.ietf.org/html/rfc7946#section-3.3) and returns the mean center. Can be weighted.
**Parameters**
- `geojson` **[GeoJSON](http://geojson.org/geojson-spec.html#geojson-objects)** GeoJSON to be centered
- `geojson` **[GeoJSON](https://tools.ietf.org/html/rfc7946#section-3)** GeoJSON to be centered
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`)
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object that is used as the [Feature](http://geojson.org/geojson-spec.html#feature-objects)'s properties (optional, default `{}`)
- `options.properties` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** an Object that is used as the [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)'s properties (optional, default `{}`)
- `options.weight` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** the property name used to weight the center

@@ -35,3 +35,3 @@

Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** a Point feature at the mean center point of all input features
Returns **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<[Point](https://tools.ietf.org/html/rfc7946#section-3.1.2)>** a Point feature at the mean center point of all input features

@@ -38,0 +38,0 @@ <!-- This file is automatically generated. Please don't edit it directly:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc