![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
@types/bson
Advanced tools
@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.
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());
The 'bson' package is the core library for BSON serialization and deserialization. It provides the same functionalities as @types/bson but without TypeScript type definitions. It is often used directly in JavaScript projects.
The 'mongodb' package is the official MongoDB driver for Node.js. It includes BSON serialization and deserialization functionalities along with a comprehensive API for interacting with MongoDB databases. It is more feature-rich compared to @types/bson, as it provides database connectivity and operations.
The 'bson-ext' package is an extension of the 'bson' library that includes native C++ bindings for improved performance. It offers the same BSON serialization and deserialization functionalities but is faster due to its native implementation.
npm install --save @types/bson
This package contains type definitions for bson (https://github.com/mongodb/js-bson).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/bson
Additional Details
These definitions were written by Hiroki Horiuchi https://github.com/horiuchi, Federico Caselli https://github.com/CaselIT.
FAQs
Stub TypeScript definitions entry for bson, which provides its own types definitions
The npm package @types/bson receives a total of 421,633 weekly downloads. As such, @types/bson popularity was classified as popular.
We found that @types/bson demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.