Socket
Socket
Sign inDemoInstall

field-filter

Package Overview
Dependencies
1
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    field-filter

api query parameter result object filter


Version published
Maintainers
3
Install size
959 kB
Created

Readme

Source

Field filter

npm install field-filter

Implements the partial response query filter method as seen here

Examples

var filter = require('field-filter');

var input = {
  a: 'a',
  b: 'b',
  c: 'c'
};

var filterString = 'a,b';

filter(filterString, input);
{
  a: 'a',
  b: 'b'
}

var input = {
  a: {
    b: {
      c: {
        d: {
          e: 'e',
          f: 'f'
        },
        g: 'g'
      },
      f: 'f'
    },
    g: {
      h: 'h'
    }
  }
};

// () and / to sub-select
var filterString = 'a( b/c( d/e ) , g)';

filter(filterString, input)
{
  a: {
    b: {
      c: {
        d: {
          e: 'e'
        }
      }
    },
    g: {
      h: 'h'
    }
  }
}

// wildcard *
var input = {
  a: {
    b: {
      c: 'c',
      d: 'd'
    },
    e: {
      c: 'c',
      f: 'f'
    }
  },
  g: {
    h: {
      i: 'i',
      j: 'j'
    },
    k: {
      i: 'i',
      j: 'j'
    }
  },
  m: 'm'
};

var filterString = 'a/*/c,g(*(i, j)),*';

filter(filterString, input)
{
  a: {
    b: {
      c: 'c'
    },
    e: {
      c: 'c'
    }
  },
  g: {
    h: {
      i: 'i',
      j: 'j'
    },
    k: {
      i: 'i',
      j: 'j'
    }
  },
  m: 'm'
});


// array index
var input = [
  {
    a: 'a',
    b: [
      'c',
      'd'
    ]
  },
  {
    e: 'e'
  }
];

var filterString = '0(a,b/1)';

filter(filterString, input)
[
  {
    a: 'a',
    b: [
      undefined,
      'd'
    ]
  }
]);

FAQs

Last updated on 19 Jun 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc