How to use json-mask - 8 common examples

To help you get started, we’ve selected a few json-mask examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ringcentral / ringcentral-js-widgets / packages / ringcentral-integration / modules / ExtensionInfo / index.js View on Github external
function extractData(info) {
  const serviceFeatures = {};
  info.serviceFeatures.forEach((f) => {
    serviceFeatures[f.featureName] = {
      enabled: f.enabled,
    };
    if (!f.enabled) {
      serviceFeatures[f.featureName].reason = f.reason;
    }
  });
  const output = mask(info, DEFAULT_MASK);
  output.serviceFeatures = serviceFeatures;
  return output;
}
github ringcentral / ringcentral-js-widgets / packages / ringcentral-integration / modules / Conference / index.js View on Github external
fetchFunction: async () =>
        mask(await getConferenceInfo(client), DEFAULT_MASK),
      storage,
github nemtsov / koa-json-mask / index.js View on Github external
const jsonMask = require('json-mask');
const compile = jsonMask.compile;
const filter = jsonMask.filter;

/**
 * Mask parts of the response.
 *
 *  - `name` querystring param name [fields]
 *
 * @param {Object} opts
 * @return {Promise}
 * @api public
 */

module.exports = opts => {
  opts = opts || {};
  const name = opts.name || 'fields';
github nemtsov / express-partial-response / index.js View on Github external
var jsonMask = require('json-mask'),
  compile = jsonMask.compile,
  filter = jsonMask.filter;

module.exports = function (opt) {
  opt = opt || {};

  function partialResponse(obj, fields) {
    if (!fields) return obj;
    return filter(obj, compile(fields));
  }

  function wrap(orig) {
    return function (obj) {
      var param = this.req.query[opt.query || 'fields'];
      if (1 === arguments.length) {
        orig(partialResponse(obj, param));
      } else if (2 === arguments.length) {
github middyjs / middy / src / middlewares / httpPartialResponse.js View on Github external
const jsonMask = require('json-mask')
const compile = jsonMask.compile
const filter = jsonMask.filter

const defaults = {
  filteringKeyName: 'fields'
}

const getFilterParams = (handler, filteringKeyName) => {
  const { body } = handler.response
  const { queryStringParameters } = handler.event
  const fields = queryStringParameters
    ? queryStringParameters[filteringKeyName]
    : undefined

  return {
    body,
    fields
github nemtsov / koa-json-mask / index.js View on Github external
const jsonMask = require('json-mask');
const compile = jsonMask.compile;
const filter = jsonMask.filter;

/**
 * Mask parts of the response.
 *
 *  - `name` querystring param name [fields]
 *
 * @param {Object} opts
 * @return {Promise}
 * @api public
 */

module.exports = opts => {
  opts = opts || {};
  const name = opts.name || 'fields';

  return async function mask(ctx, next) {
github nemtsov / express-partial-response / index.js View on Github external
var jsonMask = require('json-mask'),
  compile = jsonMask.compile,
  filter = jsonMask.filter;

module.exports = function (opt) {
  opt = opt || {};

  function partialResponse(obj, fields) {
    if (!fields) return obj;
    return filter(obj, compile(fields));
  }

  function wrap(orig) {
    return function (obj) {
      var param = this.req.query[opt.query || 'fields'];
      if (1 === arguments.length) {
        orig(partialResponse(obj, param));
      } else if (2 === arguments.length) {
        if ('number' === typeof arguments[1]) {
github middyjs / middy / src / middlewares / httpPartialResponse.js View on Github external
const jsonMask = require('json-mask')
const compile = jsonMask.compile
const filter = jsonMask.filter

const defaults = {
  filteringKeyName: 'fields'
}

const getFilterParams = (handler, filteringKeyName) => {
  const { body } = handler.response
  const { queryStringParameters } = handler.event
  const fields = queryStringParameters
    ? queryStringParameters[filteringKeyName]
    : undefined

  return {
    body,
    fields
  }

json-mask

Tiny language and engine for selecting specific parts of a JS object, hiding the rest.

MIT
Latest version published 2 years ago

Package Health Score

53 / 100
Full package analysis

Popular json-mask functions