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

[translate] Make it possible to pass function as argument #12

Open
diegohaz opened this issue Feb 2, 2018 · 3 comments
Open

[translate] Make it possible to pass function as argument #12

diegohaz opened this issue Feb 2, 2018 · 3 comments

Comments

@diegohaz
Copy link
Owner

diegohaz commented Feb 2, 2018

translate(values => ({
  name: ...
}))

So it would be possible to do something like:

const camelizeKeys = values => Object.keys(values).reduce((finalObject, key) => ({
  ...finalObject,
  [camelCase(key)]: key,
}), {})

translate(camelizeKeys)
``
@itaditya
Copy link
Contributor

I see there is support for string shorthand

const userSchema = schema({
  name: String,
  email: String,
}, translate({
  email: "emails.0",
}));

However can I do this too ?

const userSchema = schema({
  name: String,
  email: String,
}, translate({
  email: ({ emails }) => emails[0],
}));

The reason I ask is although the string shorthand is easy to use, it cannot be used in all cases, I would like the ability to define what I want to do with a param.

@diegohaz
Copy link
Owner Author

diegohaz commented Mar 24, 2018

I agree, @itaditya. Both passing a function directly to translate or to key values should be supported by the library.

@itaditya
Copy link
Contributor

Yes, I would also like both things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants