ret
retarget
npm i retarget
ret

retarget

Focus on targets with selectors

by Kye Hohenberger

0.0.2 (see all)License:MITTypeScript:Not Found
npm i retarget
Readme

npm version Build Status codecov

retarget

selectors via targets

Install

npm i retarget -S

or

yarn add retarget

import retarget from 'retarget'

const STATE = {
  profile: {
    name: {
      first: 'Waylon',
      last: 'Jennings'
    }
  }
}

const lastNameSelector  = retarget`profile.name.last`

console.log(lastNameSelector(STATE)) // logs "Jennings"

Composing

It is possible to compose multiple selectors together to create a new one.

import retarget from 'retarget'

const STATE = {
  users: {
    '1': {
      profile: {
          name: {
            first: 'Waylon',
            last: 'Jennings'
          }
        }
      }
    }
}

const lastNameSelector  = retarget`profile.name.last`

const createUserSelector = (id) =>
  retarget`users.${id}${lastNameSelector}`


const userSelector = createUserSelector(1)

console.log(userSelector(STATE)) // logs "Jennings"

API

retarget function

import retarget from 'retarget'

const selector = retarget`dot.seperated.path.to.value`

const state = {/* Huge object */}
selector(state) // returns the value at "dot.seperated.path.to.value"

Returns

retarget returns a function that when passed an obj, attempts to get the value for the given path.

Downloads/wk

8

GitHub Stars

31

LAST COMMIT

4yrs ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

1

OPEN PRs

1
VersionTagPublished
0.0.2
latest
4yrs ago
No alternatives found
No tutorials found
Add a tutorial