Skip to content

Instantly share code, notes, and snippets.

@secretfader
Created May 1, 2014 13:23
Show Gist options
  • Select an option

  • Save secretfader/747c145ea9df4835e7cc to your computer and use it in GitHub Desktop.

Select an option

Save secretfader/747c145ea9df4835e7cc to your computer and use it in GitHub Desktop.

Revisions

  1. secretfader created this gist May 1, 2014.
    27 changes: 27 additions & 0 deletions distill.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    var distill = require('distill');
    var data = {
    id: 1,
    title: 'Hello, World',
    dirty_field: 'This field should not be exposed.',
    authors: {
    id: 2,
    name: 'Joshua',
    email: '[email protected]'
    }
    };

    var output =
    distill(data)
    .field('id')
    .field('title')
    .embed('authors', 'id')
    .bottle();

    // Output
    {
    id: 1,
    title: 'Hello, World',
    authors: [
    { id: 2 }
    ]
    }