Socket
Socket
Sign inDemoInstall

@types/bson

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/bson

Stub TypeScript definitions entry for bson, which provides its own types definitions


Version published
Weekly downloads
537K
Maintainers
1
Weekly downloads
 
Created

What is @types/bson?

@types/bson provides TypeScript type definitions for the BSON library, which is used for serializing and deserializing data in the BSON (Binary JSON) format. This is particularly useful when working with MongoDB, as BSON is the format used for storing documents in MongoDB.

What are @types/bson's main functionalities?

Serialize an Object to BSON

This feature allows you to serialize a JavaScript object into BSON format. The serialized data can then be stored or transmitted in a binary format.

const BSON = require('bson');
const bson = new BSON();
const obj = { name: 'John', age: 30 };
const data = bson.serialize(obj);
console.log(data);

Deserialize BSON to an Object

This feature allows you to deserialize BSON data back into a JavaScript object. This is useful for reading data that was previously serialized into BSON format.

const BSON = require('bson');
const bson = new BSON();
const data = Buffer.from([/* some BSON data */]);
const obj = bson.deserialize(data);
console.log(obj);

ObjectId Generation

This feature allows you to generate a new ObjectId, which is a unique identifier commonly used in MongoDB documents.

const BSON = require('bson');
const ObjectId = BSON.ObjectId;
const id = new ObjectId();
console.log(id.toHexString());

Other packages similar to @types/bson

FAQs

Package last updated on 03 Sep 2021

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