https://github.com/cheminfo/smart-array-filter
Filter an array of objects
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.1%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Filter an array of objects
Basic Info
Statistics
- Stars: 11
- Watchers: 5
- Forks: 4
- Open Issues: 3
- Releases: 27
Topics
Metadata Files
README.md
smart-array-filter
Filter an array of objects
Installation
npm install smart-array-filter
Documentation
Basic usage
js
const array = [
{
name: 'Cheetah',
lifeExpectancy: 10,
taxonomy: {
phylum: 'Chordata',
class: 'Mammalia',
order: 'Carnivora',
family: 'Felidae',
},
characteristics: {
prey: 'Gazelle, Wildebeest, Hare',
distinctiveFeature: 'Yellowish fur covered in small black spots',
},
locations: ['Africa', 'Asia', 'Eurasia'],
},
{
name: 'Gorilla',
lifeExpectancy: 40,
taxonomy: {
phylum: 'Chordata',
class: 'Mammalia',
order: 'Primates',
family: 'Hominidae',
},
locations: ['Africa'],
},
];
const filteredData = filter(array, {
keywords: 'gorilla', // search for any field that contains the "gorilla" string
});
Options
| Option | Type | Default | Description |
| --------------- | ---------------------- | ---------- | --------------------------------------------------------- |
| keywords | string or string[] | [] | The list of keywords to search for. |
| limit | number | Infinity | The maximum number of results to return. |
| caseSensitive | boolean | false | Whether the search should be case sensitive. |
| predicate | "AND" or "OR" | "AND" | The predicate to use to combine matches between keywords. |
| includePaths | string[] | [] | The paths to include when searching for matches. |
| ignorePaths | string[] | [] | The paths to ignore when searching for matches. |
Search within specific fields
To search within a specific key, you can prefix your search term with the field's key followed by a colon.
name:Gorilla will match the name field of the Gorilla entry.
order:Primates will match the taxonomy.order field of the Gorilla entry.
taxonomy.order will match the taxonomy.order field of the Gorilla entry.
You can use the includePaths or the ignorePaths options to define which fields should be included or ignored when finding search matches.
Keywords
The keywords option can be a string or an array of strings.
If it's a string it will be split by space / newlines and each part will be considered as a keyword. When searching for content with spaces or newlines, the content must be enclosed in double quotes.
- 🚫
{ keywords: 'distinctiveFeature:black spots' }this creates 2 keywords - ✅
{ keywords: 'distinctiveFeature:"black spots"' }
If keywords is an array of strings, each string will be considered as a keyword and there is no need for enclosing spaces in double quotes.
✅ { keywords: [ 'distinctiveFeature:black spots' ] }
Operators
- No operator:
name:Goriwill match the Gorilla entry because the name contains"Gori". - Strict equality:
name:=Gorillawill match thename, but notname:=Gorill. - Range operators
>,>=,<,<=. Example:lifeExpectancy:>=40..to define a range. Example:lifeExpectancy:10..40- The range operators also work with strings, using the ascii code.
- Negation:
-name:Gorillawill match all entries except the ones which matchname:Gorilla. This operator can be combined with other operators:-name:=Gorilla. - Presence of a property:
is:phylumwill match all entries that has a property calledphylum. This operator can also be negated-is:phylum
Search within arrays
Arrays are traversed like objects, but inherit their parent's field name. For example in the Cheetah example, locations: ['Africa', 'Asia', 'Eurasia'] behaves as if there were 3 different properties but all with the locations name.
Any of those keywords will match the Cheetah entry:
locations:Africa, locations:Asia, locations:Eurasia
Search predicate
By default, the search using the "AND" predicate, which is returning the intersection of the matches across all keywords. You can change this behavior by setting the predicate option to "OR".
js
filter(animals, {
keywords: ['Gorilla', 'Cheetah'],
predicate: 'OR', // will return the union of the matches on the "Gorilla" and "Cheetah" keywords
});
License
Owner
- Name: Cheminfo
- Login: cheminfo
- Kind: organization
- Website: https://www.cheminfo.org/
- Repositories: 242
- Profile: https://github.com/cheminfo
GitHub Events
Total
- Create event: 4
- Commit comment event: 1
- Issues event: 1
- Release event: 2
- Watch event: 2
- Delete event: 3
- Issue comment event: 5
- Push event: 9
- Pull request review comment event: 2
- Pull request review event: 3
- Pull request event: 6
- Fork event: 1
Last Year
- Create event: 4
- Commit comment event: 1
- Issues event: 1
- Release event: 2
- Watch event: 2
- Delete event: 3
- Issue comment event: 5
- Push event: 9
- Pull request review comment event: 2
- Pull request review event: 3
- Pull request event: 6
- Fork event: 1
Committers
Last synced: over 3 years ago
All Time
- Total Commits: 132
- Total Committers: 10
- Avg Commits per committer: 13.2
- Development Distribution Score (DDS): 0.735
Top Committers
| Name | Commits | |
|---|---|---|
| Luc Patiny | l****c@p****m | 35 |
| Michaël Zasso | m****e@g****m | 30 |
| Daniel Kostro | k****d@g****m | 26 |
| cheminfo bot | a****n@c****g | 16 |
| cheminfo-bot | 1****t@u****m | 9 |
| Michaël Zasso | t****s@p****m | 7 |
| Luc Patiny | l****y@L****l | 4 |
| Luc Patiny | l****y@u****m | 3 |
| Wadjih Bencheikh | 5****8@u****m | 1 |
| Océane Patiny | o****e@p****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 21
- Total pull requests: 23
- Average time to close issues: 7 months
- Average time to close pull requests: 1 day
- Total issue authors: 7
- Total pull request authors: 6
- Average comments per issue: 1.19
- Average comments per pull request: 1.39
- Merged pull requests: 21
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 4
- Average time to close issues: N/A
- Average time to close pull requests: about 2 hours
- Issue authors: 1
- Pull request authors: 3
- Average comments per issue: 0.0
- Average comments per pull request: 1.25
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- lpatiny (13)
- stropitek (3)
- dcyou (1)
- andyjamesn (1)
- hamed-musallam (1)
- FC5570 (1)
- targos (1)
Pull Request Authors
- cheminfo-bot (16)
- lpatiny (3)
- ruofee (2)
- stropitek (2)
- wadjih-bencheikh18 (1)
- opatiny (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- npm 4,680 last-month
- Total docker downloads: 43
- Total dependent packages: 6
- Total dependent repositories: 13
- Total versions: 27
- Total maintainers: 4
npmjs.org: smart-array-filter
Filter an array of objects
- Homepage: https://github.com/cheminfo/smart-array-filter
- License: MIT
-
Latest release: 4.1.1
published over 1 year ago
Rankings
Maintainers (4)
Dependencies
- @types/jest ^28.1.7 development
- @types/lodash.escaperegexp ^4.1.7 development
- cheminfo-build ^1.1.11 development
- eslint ^8.22.0 development
- eslint-config-cheminfo-typescript ^11.0.1 development
- jest ^28.1.3 development
- prettier ^2.7.1 development
- rimraf ^3.0.2 development
- ts-jest ^28.0.8 development
- typescript ^4.7.4 development
- lodash.escaperegexp ^4.1.2
- JamesIves/github-pages-deploy-action releases/v4 composite
- actions/checkout v2 composite
- zakodium/documentationjs-action v1 composite
- actions/checkout v2 composite
- actions/setup-node v2 composite
- zakodium/lactame-action v1 composite
- GoogleCloudPlatform/release-please-action v2 composite
- actions/checkout v2 composite
- actions/setup-node v2 composite