question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

2 way transformations possibility

See original GitHub issue

I went through documentation and I am wondering, whether there is something like cast reverse.

Here is my use case.

Lets say I have schema with a Date field. Now cast calls chain of transformations. But I am interested in 2 sides of it, namely string > Date and Date > string, can this be achieved somehow?

With this, I could use one yup schema as a serializer/deserializer, which would be awesome.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jquensecommented, Aug 9, 2018

There isn’t anything built into yup for this specifically but the pattern i often use is to define two schema and export serialize/deserialize functions something like:

const schema = object({
  name: string(),
  createdAt: date().required(),
  clientId: string().required()
})

export const serialize = value => schema.shape({
  clientId: string().strip(),
  createdAt: string().transform(date => date.toISOString())
}).cast(value, { stripUnknown: true })

export const deserialize = value => schema.cast(value)

0reactions
klis87commented, Aug 10, 2018

@jquense Added in #282

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lesson 9: Data Transformations - STAT ONLINE
It is easy to understand how transformations work in the simple linear regression context because we can see everything in a scatterplot of...
Read more >
Identifying function transformations (video) - Khan Academy
Sal walks through several examples of how to write g(x) implicitly in terms of f(x) ... What would the transformation do if g(x)=(x+6)^...
Read more >
Identifying type of transformation (video) - Khan Academy
So a line that has slope of positive 3/ 2. So this one looks right in between the two. Or actually it could...
Read more >
Transformations of Random Variables - Arizona Math
The associated probability µg(X) is called the distribution of g(X). ... Then Y = X + a is a uniform random variable on...
Read more >
Transformation and potentialization: how to extend the present ...
203–238). To sum up, we claim that the potentiality administration actualizes the potentialization of possibilities. In every communicative ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found