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

@turf/meta

Package Overview
Dependencies
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/meta - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

13

index.d.ts

@@ -14,3 +14,6 @@ import {

FeatureGeometryCollection,
ExtendedFeatureCollection
ExtendedFeatureCollection,
Properties,
BBox,
Id
} from '@turf/helpers';

@@ -38,3 +41,3 @@

*/
export function propEach<Props extends any>(
export function propEach<Props extends Properties>(
geojson: Feature<any> | FeatureCollection<any>,

@@ -47,3 +50,3 @@ callback: (currentProperties: Props, featureIndex: number) => void

*/
export function propReduce<Reducer extends any, Props extends any>(
export function propReduce<Reducer extends any, Props extends Properties>(
geojson: Feature<any> | FeatureCollection<any>,

@@ -90,3 +93,3 @@ callback: (previousValue: Reducer, currentProperties: Props, featureIndex: number) => Reducer,

geojson: Feature<Geom> | FeatureCollection<Geom> | Geom | GeometryCollection | FeatureGeometryCollection,
callback: (previousValue: Reducer, currentGeometry: Geom, featureIndex: number, currentProperties: any) => Reducer,
callback: (previousValue: Reducer, currentGeometry: Geom, featureIndex: number, currentProperties: Properties, currentBBox: BBox, currentId: Id) => Reducer,
initialValue?: Reducer

@@ -100,3 +103,3 @@ ): Reducer;

geojson: Feature<Geom> | FeatureCollection<Geom> | Geom | GeometryCollection | FeatureGeometryCollection,
callback: (currentGeometry: Geom, featureIndex: number, currentProperties: any) => void
callback: (currentGeometry: Geom, featureIndex: number, currentProperties: Properties, currentBBox: BBox, currentId: Id) => void
): void;

@@ -103,0 +106,0 @@

@@ -0,1 +1,3 @@

import { feature, lineString } from '@turf/helpers';
/**

@@ -393,5 +395,7 @@ * Callback for coordEach

* @param {Geometry} currentGeometry The current geometry being processed.
* @param {number} currentIndex The index of the current element being processed in the
* @param {number} featureIndex The index of the current element being processed in the
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} currentProperties The current feature properties being processed.
* @param {Object} featureProperties The current feature properties being processed.
* @param {Array<number>} featureBBox The current feature BBox being processed.
* @param {number|string} featureId The current feature Id being processed.
*/

@@ -421,3 +425,5 @@

isGeometryCollection,
geometryProperties,
featureProperties,
featureBBox,
featureId,
featureIndex = 0,

@@ -444,4 +450,8 @@ isFeatureCollection = geojson.type === 'FeatureCollection',

(isFeature ? geojson.geometry : geojson));
geometryProperties = (isFeatureCollection ? geojson.features[i].properties :
featureProperties = (isFeatureCollection ? geojson.features[i].properties :
(isFeature ? geojson.properties : {}));
featureBBox = (isFeatureCollection ? geojson.features[i].bbox :
(isFeature ? geojson.bbox : undefined));
featureId = (isFeatureCollection ? geojson.features[i].id :
(isFeature ? geojson.id : undefined));
isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;

@@ -456,3 +466,3 @@ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;

if (geometry === null) {
callback(null, featureIndex, geometryProperties);
callback(null, featureIndex, featureProperties, featureBBox, featureId);
continue;

@@ -467,3 +477,3 @@ }

case 'MultiPolygon': {
callback(geometry, featureIndex, geometryProperties);
callback(geometry, featureIndex, featureProperties, featureBBox, featureId);
break;

@@ -473,3 +483,3 @@ }

for (j = 0; j < geometry.geometries.length; j++) {
callback(geometry.geometries[j], featureIndex, geometryProperties);
callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId);
}

@@ -572,3 +582,3 @@ break;

export function flattenEach(geojson, callback) {
geomEach(geojson, function (geometry, featureIndex, properties) {
geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {
// Callback for single geometry

@@ -581,3 +591,3 @@ var type = (geometry === null) ? null : geometry.type;

case 'Polygon':
callback(feature(geometry, properties), featureIndex, 0);
callback(feature(geometry, properties, bbox, id), featureIndex, 0);
return;

@@ -785,42 +795,2 @@ }

/**
* Create Feature
*
* @private
* @param {Geometry} geometry GeoJSON Geometry
* @param {Object} properties Properties
* @returns {Feature} GeoJSON Feature
*/
function feature(geometry, properties) {
if (geometry === undefined) throw new Error('No geometry passed');
return {
type: 'Feature',
properties: properties || {},
geometry: geometry
};
}
/**
* Create LineString
*
* @private
* @param {Array<Array<number>>} coordinates Line Coordinates
* @param {Object} properties Properties
* @returns {Feature<LineString>} GeoJSON LineString Feature
*/
function lineString(coordinates, properties) {
if (!coordinates) throw new Error('No coordinates passed');
if (coordinates.length < 2) throw new Error('Coordinates must be an array of two or more positions');
return {
type: 'Feature',
properties: properties || {},
geometry: {
type: 'LineString',
coordinates: coordinates
}
};
}
/**
* Callback for lineEach

@@ -830,4 +800,5 @@ *

* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.
* @param {number} lineIndex The index of the current element being processed in the array, starts at index 0.
* @param {number} lineSubIndex The sub-index of the current line being processed at index 0
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0.
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0
* @param {number} lineIndex The current line being processed at index 0
*/

@@ -865,7 +836,7 @@

case 'LineString':
callback(coords, featureIndex, featureSubIndex, 0);
callback(feature, featureIndex, featureSubIndex, 0);
break;
case 'Polygon':
for (var lineIndex = 0; lineIndex < coords.length; lineIndex++) {
callback(coords[lineIndex], featureIndex, featureSubIndex, lineIndex);
callback(lineString(coords[lineIndex], feature.properties), featureIndex, featureSubIndex, lineIndex);
}

@@ -895,5 +866,5 @@ break;

* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.
* @param {number} lineIndex The index of the current element being processed in the
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} lineSubIndex The sub-index of the current line being processed at index 0
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0.
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0
* @param {number} lineIndex The current line being processed at index 0
*/

@@ -915,7 +886,8 @@

*
* turf.lineReduce(mtp, function (previousValue, currentLine, lineIndex, lineSubIndex) {
* turf.lineReduce(mtp, function (previousValue, currentLine, featureIndex, featureSubIndex, lineIndex) {
* //=previousValue
* //=currentLine
* //=featureIndex
* //=featureSubIndex
* //=lineIndex
* //=lineSubIndex
* return currentLine

@@ -926,7 +898,7 @@ * }, 2);

var previousValue = initialValue;
lineEach(geojson, function (currentLine, lineIndex, lineSubIndex) {
if (lineIndex === 0 && initialValue === undefined) previousValue = currentLine;
else previousValue = callback(previousValue, currentLine, lineIndex, lineSubIndex);
lineEach(geojson, function (currentLine, featureIndex, featureSubIndex, lineIndex) {
if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine;
else previousValue = callback(previousValue, currentLine, featureIndex, featureSubIndex, lineIndex);
});
return previousValue;
}

@@ -5,2 +5,4 @@ 'use strict';

var helpers = require('@turf/helpers');
/**

@@ -398,5 +400,7 @@ * Callback for coordEach

* @param {Geometry} currentGeometry The current geometry being processed.
* @param {number} currentIndex The index of the current element being processed in the
* @param {number} featureIndex The index of the current element being processed in the
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} currentProperties The current feature properties being processed.
* @param {object} featureProperties The current feature properties being processed.
* @param {Array<number>} featureBBox The current feature BBox being processed.
* @param {number|string} featureId The current feature Id being processed.
*/

@@ -426,3 +430,5 @@

isGeometryCollection,
geometryProperties,
featureProperties,
featureBBox,
featureId,
featureIndex = 0,

@@ -449,4 +455,8 @@ isFeatureCollection = geojson.type === 'FeatureCollection',

(isFeature ? geojson.geometry : geojson));
geometryProperties = (isFeatureCollection ? geojson.features[i].properties :
featureProperties = (isFeatureCollection ? geojson.features[i].properties :
(isFeature ? geojson.properties : {}));
featureBBox = (isFeatureCollection ? geojson.features[i].bbox :
(isFeature ? geojson.bbox : undefined));
featureId = (isFeatureCollection ? geojson.features[i].id :
(isFeature ? geojson.id : undefined));
isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;

@@ -461,3 +471,3 @@ stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;

if (geometry === null) {
callback(null, featureIndex, geometryProperties);
callback(null, featureIndex, featureProperties, featureBBox, featureId);
continue;

@@ -472,3 +482,3 @@ }

case 'MultiPolygon': {
callback(geometry, featureIndex, geometryProperties);
callback(geometry, featureIndex, featureProperties, featureBBox, featureId);
break;

@@ -478,3 +488,3 @@ }

for (j = 0; j < geometry.geometries.length; j++) {
callback(geometry.geometries[j], featureIndex, geometryProperties);
callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId);
}

@@ -577,3 +587,3 @@ break;

function flattenEach(geojson, callback) {
geomEach(geojson, function (geometry, featureIndex, properties) {
geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {
// Callback for single geometry

@@ -586,3 +596,3 @@ var type = (geometry === null) ? null : geometry.type;

case 'Polygon':
callback(feature(geometry, properties), featureIndex, 0);
callback(helpers.feature(geometry, properties, bbox, id), featureIndex, 0);
return;

@@ -611,3 +621,3 @@ }

};
callback(feature(geom, properties), featureIndex, featureSubIndex);
callback(helpers.feature(geom, properties), featureIndex, featureSubIndex);
});

@@ -709,14 +719,14 @@

function segmentEach(geojson, callback) {
flattenEach(geojson, function (feature, featureIndex, featureSubIndex) {
flattenEach(geojson, function (feature$$1, featureIndex, featureSubIndex) {
var segmentIndex = 0;
// Exclude null Geometries
if (!feature.geometry) return;
if (!feature$$1.geometry) return;
// (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
var type = feature.geometry.type;
var type = feature$$1.geometry.type;
if (type === 'Point' || type === 'MultiPoint') return;
// Generate 2-vertex line segments
coordReduce(feature, function (previousCoords, currentCoord) {
var currentSegment = lineString([previousCoords, currentCoord], feature.properties);
coordReduce(feature$$1, function (previousCoords, currentCoord) {
var currentSegment = helpers.lineString([previousCoords, currentCoord], feature$$1.properties);
callback(currentSegment, featureIndex, featureSubIndex, segmentIndex);

@@ -792,42 +802,2 @@ segmentIndex++;

/**
* Create Feature
*
* @private
* @param {Geometry} geometry GeoJSON Geometry
* @param {Object} properties Properties
* @returns {Feature} GeoJSON Feature
*/
function feature(geometry, properties) {
if (geometry === undefined) throw new Error('No geometry passed');
return {
type: 'Feature',
properties: properties || {},
geometry: geometry
};
}
/**
* Create LineString
*
* @private
* @param {Array<Array<number>>} coordinates Line Coordinates
* @param {Object} properties Properties
* @returns {Feature<LineString>} GeoJSON LineString Feature
*/
function lineString(coordinates, properties) {
if (!coordinates) throw new Error('No coordinates passed');
if (coordinates.length < 2) throw new Error('Coordinates must be an array of two or more positions');
return {
type: 'Feature',
properties: properties || {},
geometry: {
type: 'LineString',
coordinates: coordinates
}
};
}
/**
* Callback for lineEach

@@ -837,4 +807,5 @@ *

* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.
* @param {number} lineIndex The index of the current element being processed in the array, starts at index 0.
* @param {number} lineSubIndex The sub-index of the current line being processed at index 0
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0.
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0
* @param {number} lineIndex The current line being processed at index 0
*/

@@ -866,13 +837,13 @@

flattenEach(geojson, function (feature, featureIndex, featureSubIndex) {
if (feature.geometry === null) return;
var type = feature.geometry.type;
var coords = feature.geometry.coordinates;
flattenEach(geojson, function (feature$$1, featureIndex, featureSubIndex) {
if (feature$$1.geometry === null) return;
var type = feature$$1.geometry.type;
var coords = feature$$1.geometry.coordinates;
switch (type) {
case 'LineString':
callback(coords, featureIndex, featureSubIndex, 0);
callback(feature$$1, featureIndex, featureSubIndex, 0);
break;
case 'Polygon':
for (var lineIndex = 0; lineIndex < coords.length; lineIndex++) {
callback(coords[lineIndex], featureIndex, featureSubIndex, lineIndex);
callback(helpers.lineString(coords[lineIndex], feature$$1.properties), featureIndex, featureSubIndex, lineIndex);
}

@@ -902,5 +873,5 @@ break;

* @param {Feature<LineString>} currentLine The current LineString|LinearRing being processed.
* @param {number} lineIndex The index of the current element being processed in the
* array. Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} lineSubIndex The sub-index of the current line being processed at index 0
* @param {number} featureIndex The feature index of the current element being processed in the array, starts at index 0.
* @param {number} featureSubIndex The feature sub-index of the current line being processed at index 0
* @param {number} lineIndex The current line being processed at index 0
*/

@@ -907,0 +878,0 @@

{
"name": "@turf/meta",
"version": "5.0.1",
"version": "5.0.2",
"description": "turf meta module",

@@ -5,0 +5,0 @@ "main": "main",

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