{"id":21747345,"url":"https://github.com/mpaland/bsonfy","last_synced_at":"2025-04-13T06:51:06.701Z","repository":{"id":45042060,"uuid":"62897757","full_name":"mpaland/bsonfy","owner":"mpaland","description":"Ultrafast BSON typescript serializer and parser","archived":false,"fork":false,"pushed_at":"2022-01-12T23:55:21.000Z","size":21,"stargazers_count":19,"open_issues_count":3,"forks_count":6,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T23:11:20.316Z","etag":null,"topics":["bson","bson-format","deserializer","json","parser","serializer","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mpaland.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-08T15:14:33.000Z","updated_at":"2024-10-29T13:00:27.000Z","dependencies_parsed_at":"2022-09-23T10:51:12.723Z","dependency_job_id":null,"html_url":"https://github.com/mpaland/bsonfy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpaland%2Fbsonfy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpaland%2Fbsonfy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpaland%2Fbsonfy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mpaland%2Fbsonfy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mpaland","download_url":"https://codeload.github.com/mpaland/bsonfy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675458,"owners_count":21143766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bson","bson-format","deserializer","json","parser","serializer","typescript"],"created_at":"2024-11-26T08:08:43.753Z","updated_at":"2025-04-13T06:51:06.682Z","avatar_url":"https://github.com/mpaland.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bsonfy - ultrafast BSON parser\n\n[![npm](https://img.shields.io/npm/v/bsonfy.svg)](https://www.npmjs.com/package/bsonfy)\n[![npm](https://img.shields.io/npm/dt/bsonfy.svg)](https://www.npmjs.com/package/bsonfy)\n[![Github Issues](https://img.shields.io/github/issues/mpaland/bsonfy.svg)](http://github.com/mpaland/bsonfy/issues)\n[![Github Releases](https://img.shields.io/github/release/mpaland/bsonfy.svg)](https://github.com/mpaland/bsonfy/releases)\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/mpaland/mipher/master/LICENSE)\n\n**bsonfy** is an ultrafast serializer and deserializer for the [BSON](http://bsonspec.org) format.  \nIt is written in clean typescript and has no other lib dependencies.\nBSON is mainly used as compact transport format for (JSON) objects.\n\n\n### Motivation\nI needed a simple, fast and clean (typescript) module to generate and parse BSON for storing JSON objects in files efficiently.  \nThere are some parsers around (2016/06), mainly the primary one of the mongodb project. But I found that it's really not lightweight enough and too slow for mobile usage.  \nA further requirement was using typed arrays (`Uint8Array`) instead of nodejs buffers, to get this baby portable and running in browsers, too.\n\n\n### Design goals:\n- Written in typescript\n- Fast and lightweight parser\n- Very easy to use, just one include module, NO dependencies\n- tslint warning free, clean code\n- Unit tested, around 50 passing test cases\n- Rocksolid (I hope so)\n- MIT license\n\n\n## Usage\nUsing this module is rather simple. Copy or (npm) install *bsonfy* to your project and use it like:\n\n```typescript\nimport { BSON } from 'bsonfy';\n\n// create a test document\nlet doc = { id: 10, time: new BSON.UTC(), arr: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]) };\n\n// serialize the document\nlet bson = BSON.serialize(doc);\n\n// and deserialize it, using BSON.UTC objects as time representation\nlet orig = BSON.deserialize(bson, true);\n```\n\n\n## API\n\nBasically the API consists of just two static methods to serialize/deserialize objects to/from BSON format:\n\n### BSON serialization and deserialiation\n\n**`BSON.serialize(object)`**\n  * @param {Object} object The Javascript object to serialize\n  * @return {Uint8Array} returns an Uint8Array in BSON format.  \n    Unknown objects are ignored in serialization.\n\n**`BSON.deserialize(buffer, useUTC)`**\n  * @param {Uint8Array} buffer An Uint8Array containing the BSON data\n  * @param {Boolean} useUTC Optional, if set a `BSON.UTC` object is created for 'UTC datetime' instead of a normal JS `Date` object. Defaults to false\n  * @return {Object} returns the deserialized Javascript object or `undefined` in case of a parsing error (unsupported BSON element etc.)\n\n\n### UTC\n\n**`bson.ObjectId.isValid(id)`** - Returns true if `id` is a valid number or hexadecimal string representing an ObjectId.\n**`bson.ObjectId.createFromHexString(hexString)`** - Returns the ObjectId the `hexString` represents.\n**`bson.ObjectId.createFromTime(time)`** - Returns an ObjectId containing the passed time.\n* `time` - A Unix timestamp (number of seconds since the epoch).\n\n\n### UUID\n\n**`bson.ObjectId.isValid(id)`** - Returns true if `id` is a valid number or hexadecimal string representing an ObjectId.\n**`bson.ObjectId.createFromHexString(hexString)`** - Returns the ObjectId the `hexString` represents.\n**`bson.ObjectId.createFromTime(time)`** - Returns an ObjectId containing the passed time.\n* `time` - A Unix timestamp (number of seconds since the epoch).\n\n\n### ObjectId\n\n**`bson.ObjectId.isValid(id)`** - Returns true if `id` is a valid number or hexadecimal string representing an ObjectId.\n**`bson.ObjectId.createFromHexString(hexString)`** - Returns the ObjectId the `hexString` represents.\n**`bson.ObjectId.createFromTime(time)`** - Returns an ObjectId containing the passed time.\n* `time` - A Unix timestamp (number of seconds since the epoch).\n\n\n### Unsupported elements\nThe following BSON elements are currently not supported (and lead to a deserialiation error):\n- JavaScript code\n- Min key\n- Max key\n- Regular expression (implemented, but untested yet - so don't rely on it)\n\n\n## Caveats\n- 64-bit integer BSON values are converted to the Javascript Number type.  \n  However, Javascript supports integer precision up to 2^53 as maximum size.\n  If a parsed 64-bit integer exceeds this size, floating point rounding errors may occur!\n\n\n## Test suite\nbsonfy is using the mocha test suite for testing.\nTo do all tests just run `npm run test`.\n\n\n## Contributing\nIf you find any bugs, have any comments, improvements or suggestions:\n\n1. Create an issue and describe your idea\n2. [Fork it](https://github.com/mpaland/bsonfy/fork)\n3. Create your feature branch (`git checkout -b my-new-feature`)\n4. Commit your changes (`git commit -am 'Add some feature'`)\n5. Publish the branch (`git push origin my-new-feature`)\n6. Create a new pull request\n7. Profit! :white_check_mark:\n\n\n## License\nbsonfy is written under the [MIT license](http://www.opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpaland%2Fbsonfy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmpaland%2Fbsonfy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmpaland%2Fbsonfy/lists"}