{"id":24558161,"url":"https://github.com/rse/encodr","last_synced_at":"2025-04-19T09:59:05.951Z","repository":{"id":57225129,"uuid":"93444766","full_name":"rse/encodr","owner":"rse","description":"Encoding/Decoding to/from CBOR/MsgPack/JSON for Node.js and Browser","archived":false,"fork":false,"pushed_at":"2023-07-08T11:22:30.000Z","size":106,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T21:55:46.266Z","etag":null,"topics":["cbor","decoding","encoding","json","msgpack","serialization-format"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rse.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-05T20:39:40.000Z","updated_at":"2023-09-18T03:33:57.000Z","dependencies_parsed_at":"2024-06-18T20:09:52.663Z","dependency_job_id":"17dad19f-20f8-4be7-b65c-42300629c738","html_url":"https://github.com/rse/encodr","commit_stats":{"total_commits":110,"total_committers":1,"mean_commits":110.0,"dds":0.0,"last_synced_commit":"f4997c9beb9326dd1338b9924094f3ac8fc0fc6e"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fencodr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fencodr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fencodr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rse%2Fencodr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rse","download_url":"https://codeload.github.com/rse/encodr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249670097,"owners_count":21308673,"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":["cbor","decoding","encoding","json","msgpack","serialization-format"],"created_at":"2025-01-23T05:47:33.001Z","updated_at":"2025-04-19T09:59:05.935Z","avatar_url":"https://github.com/rse.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nEncodr\n======\n\nEncoding/Decoding to/from CBOR/MsgPack/JSON for Node.js and Browser.\n\n\u003cp/\u003e\n\u003cimg src=\"https://nodei.co/npm/encodr.png?downloads=true\u0026stars=true\" alt=\"\"/\u003e\n\n\u003cp/\u003e\n\u003cimg src=\"https://david-dm.org/rse/encodr.png\" alt=\"\"/\u003e\n\nAbout\n-----\n\nThis is a small JavaScript abstraction layer for Node.js and the Browser\nto encode/decode JavaScript values to/from the (binary) object serialization formats\nConcise Binary Object Representation (CBOR, [RFC7049](https://tools.ietf.org/html/rfc7049)),\nMessagePack ([MsgPack](https://github.com/msgpack/msgpack/blob/master/spec.md))\nand JavaScript Object Notation (JSON, [RFC4627](https://tools.ietf.org/html/rfc4627)).\nThe actual encoding/decoding is performed by underyling libraries. This\npackage is just a convenient abstraction layer to ensure the correct\nlibrary and consistent data types are used.\n\nInstallation\n------------\n\n```shell\n$ npm install encodr\n```\n\nUsage\n-----\n\n```js\nimport Encodr from \"encodr\"\n\nconst CBOR    = new Encodr(\"cbor\")\nconst MSGPACK = new Encodr(\"msgpack\")\nconst JSON    = new Encodr(\"json\")\n\nlet data = {\n    foo: \"bar\",\n    baz: 42,\n    baz: [ 1.0, \"quux\", true ],\n    quux: {}\n}\n\ndata = CBOR.encode(data)\ndata = CBOR.decode(data)\n\ndata = MSGPACK.encode(data)\ndata = MSGPACK.decode(data)\n\ndata = JSON.encode(data)\ndata = JSON.decode(data)\n```\n\nApplication Programming Interface\n---------------------------------\n\n- `type BLOB = Buffer | Uint8Array`\u003cbr/\u003e\n  The `BLOB` data type depends on the execution environment:\n  In Node.js it is `Buffer`, in the Browsers it is `Uint8Array`.\n\n- `new Encodr(format: string = \"cbor\"): Encodr`\u003cbr/\u003e\n  Create a new Encodr instance for a particular encoding\n  format. The supported formats are `cbor`, `msgpack`, `json`\n  and `jsons`. The default is `cbor`.\n\n- `Encodr::encode(data: any): BLOB`\u003cbr/\u003e\n  Encode a JavaScript value to the serialization format.\n\n- `Encodr::decode(data: BLOB): any`\u003cbr/\u003e\n  Decode a JavaScript value from the serialization format.\n\nEncoding Formats\n----------------\n\nThe following regular serialization formats are supported:\n\n- **cbor**: Concise Binary Object Representation (CBOR, [RFC7049](https://tools.ietf.org/html/rfc7049)):\u003cbr/\u003e\n  This is a very compact, efficient and IETF-standardized serialization format.\n\n- **msgpack**: MessagePack ([MsgPack](https://github.com/msgpack/msgpack/blob/master/spec.md)):\u003cbr/\u003e\n  This is a very compact, efficient and battle-tested serialization format.\n\nFor convenience and application development reasons, there is also an additional special serialization format:\n\n- **json**: UTF-16 string-encoded JavaScript Object Notation (JSON, [RFC4627](https://tools.ietf.org/html/rfc4627)):\u003cbr/\u003e\n  This is a less compact, less efficient but IETF-standardized and human-readable serialization format.\n\n  This serialization format is JSON encoded into a regular UTF-16 character\n  string (instead of the UTF-8 byte array as it is the case for `cbor` and `msgpack`)\n  and hence the API `BLOB` type here becomes `String` as an unregular case.\n\n  This serialization format exists for development purposes only, where one wants to\n  easily switch the encoding to a human-readable string representation.\n  For instance, when transferring the data over WebSockets via\n  [WebSocket-Framed](https://github.com/rse/websocket-framed), the\n  resulting WebSocket frame will be human-readable in the Browser's\n  debugger.\n\nLicense\n-------\n\nCopyright (c) 2017-2023 Dr. Ralf S. Engelschall (http://engelschall.com/)\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be included\nin all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fencodr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frse%2Fencodr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frse%2Fencodr/lists"}