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

turf-filter

Package Overview
Dependencies
Maintainers
8
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-filter - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

82

index.js
var featureCollection = require('turf-featurecollection');
/**
* Takes a {@link FeatureCollection} and filters it by a given property and value
*
* @module turf/filter
* @category data
* @param {FeatureCollection} features input FeatureCollection of any type
* @param {String} key the property on which to filter
* @param {String} value the value of that property on which to filter
* @return {FeatureCollection} a filtered collection with only features that match input `key` and `value`
* @example
* var features = {
* "type": "FeatureCollection",
* "features": [
* {
* "type": "Feature",
* "properties": {
* "species": "oak"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-72.581777, 44.260875]
* }
* }, {
* "type": "Feature",
* "properties": {
* "species": "birch"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-72.570018, 44.260691]
* }
* }, {
* "type": "Feature",
* "properties": {
* "species": "oak"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-72.576284, 44.257925]
* }
* }, {
* "type": "Feature",
* "properties": {
* "species": "redwood"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-72.56916, 44.254605]
* }
* }, {
* "type": "Feature",
* "properties": {
* "species": "maple"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-72.581691, 44.24858]
* }
* }, {
* "type": "Feature",
* "properties": {
* "species": "oak"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [-72.583837, 44.255773]
* }
* }
* ]
* };
*
* var key = "species";
* var value = "oak";
*
* var filtered = turf.filter(features, key, value);
*
* //=features
*
* //=filtered
*/
module.exports = function(collection, key, val) {

@@ -11,2 +91,2 @@ var newFC = featureCollection([]);

return newFC;
}
};

17

package.json
{
"name": "turf-filter",
"version": "1.0.0",
"version": "1.0.1",
"description": "turf filter module",
"main": "index.js",
"scripts": {
"test": "node test.js"
"test": "node test.js",
"doc": "dox -r < index.js | doxme --readme > README.md"
},
"repository": {
"type": "git",
"url": "https://github.com/morganherlocker/turf-filter.git"
"url": "https://github.com/Turfjs/turf-filter.git"
},

@@ -21,10 +22,12 @@ "keywords": [

"bugs": {
"url": "https://github.com/morganherlocker/turf-filter/issues"
"url": "https://github.com/Turfjs/turf-filter/issues"
},
"homepage": "https://github.com/morganherlocker/turf-filter",
"homepage": "https://github.com/Turfjs/turf-filter",
"devDependencies": {
"benchmark": "^1.0.0",
"tape": "^3.0.3",
"tape": "^3.5.0",
"turf-featurecollection": "^1.0.0",
"turf-point": "^1.2.0"
"turf-point": "^2.0.0",
"dox": "^0.6.1",
"doxme": "^1.4.3"
},

@@ -31,0 +34,0 @@ "dependencies": {

@@ -1,46 +0,57 @@

turf-filter
===========
[![Build Status](https://travis-ci.org/Turfjs/turf-filter.svg)](https://travis-ci.org/Turfjs/turf-filter)
# turf-filter
Keeps any features from a feature collection that match a property value.
[![build status](https://secure.travis-ci.org/Turfjs/turf-filter.png)](http://travis-ci.org/Turfjs/turf-filter)
###Install
turf filter module
```sh
npm install turf-filter
```
###Parameters
### `turf.filter(features, key, value)`
|name|description|
|---|---|
|fc|A FeatureCollection|
|property|Property to check|
|value|Value for features to keep|
Takes a FeatureCollection and filters it by a given property and value
###Usage
### Parameters
| parameter | type | description |
| ---------- | ----------------- | --------------------------------------------- |
| `features` | FeatureCollection | input FeatureCollection of any type |
| `key` | String | the property on which to filter |
| `value` | String | the value of that property on which to filter |
### Example
```js
filter(fc, property, value)
var features = turf.featurecollection([
turf.point([-72.581777, 44.260875], {species: 'oak'}),
turf.point([-72.570018, 44.260691], {species: 'birch'}),
turf.point([-72.576284, 44.257925], {species: 'oak'}),
turf.point([-72.56916, 44.254605], {species: 'redwood'}),
turf.point([-72.581691, 44.24858], {species: 'maple'}),
turf.point([-72.583837, 44.255773], {species: 'oak'})
]);
var key = 'species';
var value = 'oak';
var filtered = turf.filter(features, key, value);
//=features
//=filtered
```
###Example
## Installation
```js
var filter = require('turf-filter')
var point = require('turf-point')
var featurecollection = require('turf-featurecollection')
Requires [nodejs](http://nodejs.org/).
var trees = featurecollection([
point(1,2, {species: 'oak'}),
point(2,1, {species: 'birch'}),
point(3,1, {species: 'oak'}),
point(2,2, {species: 'redwood'}),
point(2,3, {species: 'maple'}),
point(4,2, {species: 'oak'})
])
```sh
$ npm install turf-filter
```
var filtered = filter(trees, 'species', 'oak')
console.log(filtered)
```
## Tests
```sh
$ npm test
```

@@ -10,8 +10,8 @@ var test = require('tape');

var points = featureCollection(
[point(1,2, {team: 'Red Sox'}),
point(2,1, {team: 'Yankees'}),
point(3,1, {team: 'Nationals'}),
point(2,2, {team: 'Yankees'}),
point(2,3, {team: 'Red Sox'}),
point(4,2, {team: 'Yankees'})]);
[point([1,2], {team: 'Red Sox'}),
point([2,1], {team: 'Yankees'}),
point([3,1], {team: 'Nationals'}),
point([2,2], {team: 'Yankees'}),
point([2,3], {team: 'Red Sox'}),
point([4,2], {team: 'Yankees'})]);

@@ -22,2 +22,2 @@ newFC = filter(points, 'team', 'Nationals');

t.equal(newFC.features[0].properties.team, 'Nationals', 'feature team property should be Nationals');
});
});
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