Developers

Field Hooks Part 2: compute

Let's continue thinking through more real-world examples to wrap our minds around the possibilities of Flatfile's Field Hooks, which — as their name suggests — clean up or validate data at the field level.


This is Part 2 of a 3-part series about Flatfile's Field Hooks. Read Part 1 - Field Hooks: cast first if you haven't already.


Scene 2: compute

Suppose we need to convert all employee names to lowercase before reasoning about the data strings.

Leveraging recordCompute Field Hooks

We'll use compute to modify the data in place before proceeding to validate.

  1. First, compute will receive data of the type determined by the field's cast hook

  2. Then, it will perform a transformation to the value returned from cast.

    1. Note: compute will always return data of the same type

CODE EXAMPLE

While Field Hooks only clean up or validate data at the field level, recordCompute and batchRecordsCompute come into play when you need to run computations across all fields in a single record or in bulk operations. More on Record Hooks soon.

Check out the docs to learn more about processing data with Flatfile or get started not with CLI Quickstart.