2.1.1 • Published 2 years ago

selector v2.1.1

Weekly downloads
106
License
MIT
Repository
github
Last release
2 years ago

codecov Node.js CI release-please

Installing

Using npm:

npm i --save selector

Using yarn:

yarn add --dev selector

Usage

Here are examples of how you can use selector.

createSelector

Return a selector helper

Examples

Get first item
const data = ['John']
const getFirstItemSelector = createSelector(0)
const item = getFirstItemSelector(data)
console.log(item) // It'll display 'John'
Get first item's name
const data = { item: { name: 'Television', isActive: true } }
const selector = createSelector('item', 'name')
const itemName = selector(data)
console.log(itemName) // It'll display 'Television'
Get first item active
const data = {
  items: [
    {
      name: 'Television',
      isActive: false,
    },
    {
      name: 'Sofa',
      isActive: true,
    },
    {
      name: 'Door',
      isActive: true,
    },
  ],
}
const firstActiveItemSelector = createSelector('items', (items: IItem[]) =>
  items.find((item: IItem) => item.isActive)
)
const item = firstActiveItemSelector(data)
console.log(item) // It'll display '{ "isActive": true, "name": "Sofa" }'
Select item with path
const path = 'items.0.name'
const data = { items: [{ name: 'Television', isActive: true }] }
const selector = createSelector(...path.split('.'))
const itemName = selector(data)
console.log(itemName) // It'll display 'Television'

Running the tests

Tests are written with jest

Unit tests

Using jest:

yarn run test

Deployment

Deployment is done with Travis.

Built With

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

Show your support

Give a ⭐️ if this project helped you!

License

This project is licensed under the MIT License - see the LICENSE.md file for details

2.1.1

2 years ago

2.1.0

2 years ago

2.0.20

3 years ago

2.0.19

3 years ago

2.0.18

3 years ago

2.0.17

4 years ago

2.0.16

4 years ago

2.0.15

4 years ago

2.0.14

4 years ago

2.0.13

4 years ago

2.0.12

4 years ago

2.0.11

4 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.0

4 years ago

2.0.0-alpha.1

4 years ago

2.0.0-alpha.0

4 years ago

1.1.0

5 years ago

1.0.0

7 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.0

9 years ago

0.0.1

10 years ago

0.1.0

11 years ago