Artisan SVG > Script (script) (file-format-javascript)

Mask an object's properties with an example object

Snippet
Universal
Advanced

Snippets are pieces of workflows. You can copy and paste them directly into any Tray workflow.

New to snippets? Watch this video

For more details please see our Snippet Documentation

About this Snippet
Copy

This snippet allows you to apply a mask, or filter, to an object using an example object.

So if you have the object:

1
{
2
   person: {
3
    name: "john doe",
4
    email: "john@doe.com",
5
    phone: "555-555-5555",
6
    social: "555-55-5555",
7
    kids: ["sally","michelle"]
8
   }
9
  }

But you only want to return their name and email, you provide the script with a filter object like:

1
{
2
   person: {
3
    name: true,
4
    email: true
5
   }
6
  }

And it will return:

1
{
2
   person: {
3
    name: "john doe",
4
    email: "john@doe.com"
5
   }
6
  }

The snippet includes an additional "demo" script that returns a sample set of data that you can use to test how it works. You'll only need the 2nd script in the snippet to perform the actual object filter/mask.

See it in action
Copy