Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
datafilter
Advanced tools
Readme
Simple filtering for collections of objects
With npm do:
npm install datafilter
To run the test suite, run the following command from the datafilter directory:
npm test
Add a condition to the filter. This method is chainable.
Options :
Example :
dataFilter.add('author.name', 'not equal', 'Proust');
dataFilter.add('theme', 'equal', ['philosophy', 'science']);
dataFilter.add('pageNumber', '>', 150);
var isLonger = function(fieldValue, filterValue) {
return fieldValue.length > filterValue.length;
};
dataFilter.add('author.name', isLonger, 'Proust');
Remove all the conditions previously added to the filter. This method is chainable.
Remove all the conditions previously added to the filter matching the criteria. This method is chainable.
Options :
Apply the conditions of the filter on a collection of objects and returns all the matching elements as an array.
Options :
Examples :
var filteredBooks = dataFilter.match(books);
var filteredBooks = dataFilter.match(books, DataFilter.BLACKLIST);
Apply the conditions of the filter on a collection of objects and return the first matching element, if any. Return null otherwise.
Options :
Examples :
var oneBook = dataFilter.first(books);
var oneBook = dataFilter.first(books, DataFilter.BLACKLIST);
Apply the conditions of the filter on a single object and returns whether the element passes all the conditions.
Options :
Add an operator to the global operator list. Returns true in case of success, false otherwise.
Options :
Create an alias for an existing operator. Returns true in case of success, false otherwise.
Options :
var instagramData = ...; //get data from instagram somehow
var filter = new DataFilter();
filter.add('likes.count', '>', 0).add('tags', 'has', ['videogame', 'game']);
var filtered = filter.match(instagramData);
Filter the posts retrieved from instagram to get only those having at least one like and tagged as videogame or game.
var instagramData = ...; //get data from instagram somehow
var filtered = DataFilter.filter(
instagramData,
[
['likes.count', '>', 0],
['tags', 'has', ['videogame', 'game']]
]
);
Do exactly the same thing with an alternative syntax.
var instagramData = ...; //get data from instagram somehow
var filter = new DataFilter().add('tags', 'has', ['selfie']);
var selfies = filter.match(instagramData);
var relevantData = filter.match(instagramData, DataFilter.BLACKLIST);
Separate the data retrieved from Instagram in two arrays, one with the photos tagged as selfie and one with those who are more likely to be of interest (not tagged as selfie).
There are two ways of using custom operators.
DataFilter.Operators.add(
'is longer than',
function(fieldValue, filterValue) {
return (fieldValue.length > filterValue.length);
}
);
var filter = new DataFilter();
filter.add('name', 'is longer than', 'Proust');
Declares an operator globally, useful if you want to handle operators as strings only, store them in a database, etc.
DataFilter.Operators.alias('is longer than', 'L>');
var filter = new DataFilter();
filter.add('name', 'L>', 'Proust');
Declares an alias for our new operator
var isLonger = function(fieldValue, filterValue) {
return (fieldValue.length > filterValue.length);
};
var filter = new DataFilter();
filter.add('name', isLonger, 'Proust');
Use a custom function as an operator, useful for single-use operators.
regexp
was renamed as matches
.array contains
was renamed as has
.greater than equal
and lower than equal
were renamed as greater than or equal
and lower than or equal
.starts with
and ends with
were implemented.evaluateFieldValue()
, evaluateExpression()
and evaludatePartialExpression()
were declared as protected.addOperator()
and addOperatorAlias()
were moved to Operators.add()
and Operators.alias()
.MIT
FAQs
Simple filtering for collections of objects
The npm package datafilter receives a total of 9 weekly downloads. As such, datafilter popularity was classified as not popular.
We found that datafilter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.