https://github.com/cheminfo/smart-array-filter

Filter an array of objects

https://github.com/cheminfo/smart-array-filter

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

hacktoberfest

Keywords from Contributors

nmr nmr-spectroscopy bruker jcamp jcamp-dx jeol nmr-parser chemistry data-format unidata
Last synced: 10 months ago · JSON representation

Repository

Filter an array of objects

Basic Info
  • Host: GitHub
  • Owner: cheminfo
  • License: mit
  • Language: TypeScript
  • Default Branch: main
  • Homepage:
  • Size: 1.37 MB
Statistics
  • Stars: 11
  • Watchers: 5
  • Forks: 4
  • Open Issues: 3
  • Releases: 27
Topics
hacktoberfest
Created over 10 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog License

README.md

smart-array-filter

NPM version build status Test coverage npm download

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:Gori will match the Gorilla entry because the name contains "Gori".
  • Strict equality: name:=Gorilla will match the name, but not name:=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:Gorilla will match all entries except the ones which match name:Gorilla. This operator can be combined with other operators: -name:=Gorilla.
  • Presence of a property: is:phylum will match all entries that has a property called phylum. 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

MIT

Owner

  • Name: Cheminfo
  • Login: cheminfo
  • Kind: organization

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 Email 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
enhancement (2) bug (1)
Pull Request Labels
autorelease: tagged (13) autorelease: pending (3)

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

  • Versions: 27
  • Dependent Packages: 6
  • Dependent Repositories: 13
  • Downloads: 4,680 Last month
  • Docker Downloads: 43
Rankings
Downloads: 3.1%
Dependent packages count: 3.2%
Dependent repos count: 3.3%
Average: 6.0%
Forks count: 9.9%
Stargazers count: 10.5%
Last synced: 11 months ago

Dependencies

package.json npm
  • @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
.github/workflows/documentationjs.yml actions
  • JamesIves/github-pages-deploy-action releases/v4 composite
  • actions/checkout v2 composite
  • zakodium/documentationjs-action v1 composite
.github/workflows/lactame.yml actions
  • actions/checkout v2 composite
  • actions/setup-node v2 composite
  • zakodium/lactame-action v1 composite
.github/workflows/release.yml actions
  • GoogleCloudPlatform/release-please-action v2 composite
  • actions/checkout v2 composite
  • actions/setup-node v2 composite
.github/workflows/nodejs.yml actions