Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protobuf-fieldmask

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protobuf-fieldmask

Library for generating and applying FieldMask

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

protobuf-fieldmask

npm version npm downloads Coverage Status

Library for generating and applying protobuf FieldMask

Usage

generateFieldMask

/**
 * Generates field mask that includes all non-function own properties on specified object
 * @param {*} object - object to generate field mask from
 * @returns {string[]} - generated field mask
 */
function generateFieldMask(object)

The name of the properties containing . or \ characters are escaped.

For an example, running this function with this input:

{
  f: {
    a: 22,
    b: {
      d: 1
    },
    'b.d': 33,
    'x\\y': 44
  }
}

generates this output:

['f.a', 'f.b.d', 'f.b\\.d', "f.x\\\\y"]

applyFieldMask

/**
 * Creates a new object that copies fields present in field mask from specified source object
 * @param {*} sourceObject - object to apply field mask to
 * @param {string[]} fieldMask
 * @returns {*} - new object created by applying field mask on source object or original entity if source is not an object
 */
function applyFieldMask(sourceObject, fieldMask)

Respects the escaping of the property names in the fieldMask.

For an example, running this function with this input:

{
  f: {
    a: 22,
    b: {
      d: 1,
      x: 2
    },
    'b.d': 33,
    y: 13
  },
  z: 8
},
['f.a', 'f.b.d', 'f.b\\.d']

generates this output:

{
  f: {
    a: 22,
    b: {
      d: 1
    },
    'b.d': 33
  }
}

Special thanks to Jorge Yero Salazar for providing TS typings!

Keywords

FAQs

Package last updated on 01 Feb 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc