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.

Combined refine/transform

See original GitHub issue

Hello,

I’m using transform() to base64-decode a value. I’m bumping up against this requirement from the docs:

⚠️ Transformation functions must not throw. Make sure to use refinements before the transformer to make sure the input can be parsed by the transformer.

To satisfy this requirement, I am doing this:

const schema = string().refine(isBase64).transform(d => Buffer.from(d, 'base64'));

function isBase64(data: string): boolean {
  try {
    Buffer.from(data, 'base64');
  } catch {
    return false;
  }
  return true;
}

This implementation is a little silly since I am base64-decoding the object just to check whether I can base64-decode it.

Is there some way to memoize the Buffer object created in refine call, so that I don’t have to double-decode?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:11
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
colinhackscommented, Jul 4, 2021

This is a known limitation. Refinements and transforms will be combined into a single concept at some point in the near future. I’ll post here when that happens. 👍

4reactions
jvliwanagcommented, Mar 13, 2022

should we keep this open? it’s a very common use case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Grid Manipulations (merge, split, refine, transform) - pygridtools
Most grid transformations such as merge and transpose return a new object, allowing consecutive operations to be chained together. Optionally, you can pass ......
Read more >
Data Transformation with OpenRefine - Web Scraper
It takes data from a column and clusters it allowing the user to bundle possibly-similar groups together. For example, if there are many ......
Read more >
@enlight.refine.transform • Instagram photos and videos
Though we journey together, our paths are different, our timing is different, but · God will give you vision and instruct you to...
Read more >
Add Refine transform function for Netflow data set (I6a24d41e ...
Add Refine transform function for Netflow data set This change adds a new file with a Refine ... Change has been successfully merged...
Read more >
Common Transformations - OpenRefine
Common Transformations · Removing Duplicates · Splitting Cell Values · Combining Cell Values · Data Shaping · Clustering.
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