Socket
Socket
Sign inDemoInstall

@babel/plugin-syntax-optional-chaining

Package Overview
Dependencies
54
Maintainers
6
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @babel/plugin-syntax-optional-chaining

Allow parsing of optional properties


Version published
Weekly downloads
26M
increased by1.82%
Maintainers
6
Install size
11.2 kB
Created
Weekly downloads
 

Package description

What is @babel/plugin-syntax-optional-chaining?

The @babel/plugin-syntax-optional-chaining package allows Babel to parse and understand the optional chaining syntax. Optional chaining (`?.`) permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid. The `?.` operator functions similarly to the `.` chaining operator, except that instead of causing an error if a reference is nullish (`null` or `undefined`), the expression short-circuits with a return value of `undefined`. This simplifies accessing values through connected objects when there's a possibility that a reference may be missing.

What are @babel/plugin-syntax-optional-chaining's main functionalities?

Optional Property Access

This feature allows safe access to nested object properties without having to check each level of the object to ensure it exists. If any reference is nullish, the expression evaluates to `undefined` instead of throwing an error.

const streetName = user?.address?.street;

Optional Method Calls

Enables calling a method on an object only if the object exists; otherwise, it returns `undefined`. This is useful for calling methods on objects that may not be initialized.

const length = users?.length;

Optional Bracket Notation

Similar to optional property access, but with the ability to access properties using bracket notation. This is useful when property names are dynamically determined.

const lastName = user?.['name']?.['last'];

Other packages similar to @babel/plugin-syntax-optional-chaining

Readme

Source

@babel/plugin-syntax-optional-chaining

Allow parsing of optional properties

See our website @babel/plugin-syntax-optional-chaining for more information.

Install

Using npm:

npm install --save-dev @babel/plugin-syntax-optional-chaining

or using yarn:

yarn add @babel/plugin-syntax-optional-chaining --dev

Keywords

FAQs

Last updated on 13 Jan 2020

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