Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapFrom does not call its mapper #5

Closed
Kui-kui opened this issue Jan 21, 2019 · 1 comment
Closed

mapFrom does not call its mapper #5

Kui-kui opened this issue Jan 21, 2019 · 1 comment

Comments

@Kui-kui
Copy link

Kui-kui commented Jan 21, 2019

Hello WaldoJeffers 👋

When I use mapFrom, the key I apply it on ends up undefined as if the mapper was never called.
By the way, the last test here is skipped 🙈

@WaldoJeffers
Copy link
Owner

WaldoJeffers commented Mar 2, 2019

It's actually more of a documentation issue following the release of v2.
The mapper function provided mapFrom will be called with a single value if a single string was passed as the first argument, or as an array if the first argument to mapFrom was an array.
Should be fixed by 3bc8fad
Can we close this?

Valid in v2 ✅

import { transform, mapFrom } from '@waldojeffers/transformer'

const input = { firstName: 'Waldo', lastName: 'Jeffers' }
const transformer = transform({
  fullName: mapFrom(['firstName', 'lastName'], arr => arr.join(' ')),
  firstname: mapFrom('firstName', str => str.toLowerCase())
})

Invalid in v2 ❌

import { transform, mapFrom } from '@waldojeffers/transformer'

const input = { firstName: 'Waldo', lastName: 'Jeffers' }
const transformer = transform({
  fullName: mapFrom(['firstName', 'lastName'], (a, b) => a + ' ' + b),
  names: mapFrom(['firstName', 'lastName'], ({firstName, lastName}) => firstName + ' ' + lastName),
})

@Kui-kui Kui-kui closed this as completed Mar 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants