{"id":18017418,"url":"https://github.com/alexdovzhanyn/bert-elixir","last_synced_at":"2025-08-21T02:31:10.401Z","repository":{"id":43125452,"uuid":"149225415","full_name":"alexdovzhanyn/bert-elixir","owner":"alexdovzhanyn","description":"BERT (Binary ERlang Term) serialization library for Javascript (with Elixir support)","archived":false,"fork":false,"pushed_at":"2024-06-13T01:11:28.000Z","size":128,"stargazers_count":35,"open_issues_count":1,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-08-09T02:27:41.989Z","etag":null,"topics":["bert","elixir","erlang","javascript","serialization-library"],"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/alexdovzhanyn.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":"2018-09-18T03:47:10.000Z","updated_at":"2025-03-07T12:35:13.000Z","dependencies_parsed_at":"2024-06-13T03:03:02.290Z","dependency_job_id":"7df46206-40d5-4cd1-a65c-6a71593a4b90","html_url":"https://github.com/alexdovzhanyn/bert-elixir","commit_stats":null,"previous_names":["elixiumnetwork/bert-elixir"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexdovzhanyn/bert-elixir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdovzhanyn%2Fbert-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdovzhanyn%2Fbert-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdovzhanyn%2Fbert-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdovzhanyn%2Fbert-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexdovzhanyn","download_url":"https://codeload.github.com/alexdovzhanyn/bert-elixir/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexdovzhanyn%2Fbert-elixir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271416750,"owners_count":24755945,"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","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bert","elixir","erlang","javascript","serialization-library"],"created_at":"2024-10-30T04:23:07.265Z","updated_at":"2025-08-21T02:31:10.155Z","avatar_url":"https://github.com/alexdovzhanyn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# BERT\n\nBinary ERlang Term serialization library for Javascript. (An updated version of [this repo](https://github.com/rustyio/BERT-JS) )\n\n## Usage\n--------------------------------\n\n### Example Usage\n\nWhen needing to consume data in Javascript from an Erlang system, the Erlang\nsystem can simply send encoded binary data:\n\n*Elixir/Erlang:*\n```elixir\n# This is Elixir code, but function calls will be very similar in Erlang\n\npersonData = %{\n  name: \"Bob\",\n  age: 32,\n  eye_color: \"Brown\",\n  personality_traits: [\n    \"Funny\",\n    \"Inquisitive\"\n  ]\n}\n\n# Convert to binary\n:erlang.term_to_binary(personData)\n\n# .... Code that sends binary data to javascript\n```\n\n*Javascript:*\n```javascript\n// ... Code that receives binary data from erlang/elixir and stores it\n// to a variable, personData\n\nconst Bert = require('bert-elixir')\n\nconst decodedPerson = Bert.decode(personData)\n/*\n  =\u003e { age: 32,\n      eye_color: 'Brown',\n      name: 'Bob',\n      personality_traits: [ 'Funny', 'Inquisitive' ]\n    }\n*/\n```\n\nModifying this data and sending it back to Erlang/Elixir would be as simple as:\n\n*Javascript:*\n```javascript\n// ... Assuming we have a decodedPerson object\n\ndecodedPerson.age = 38\ndecodedPerson.name = 'Robert'\n\nconst reEncodedPerson = Bert.encode(decodedPerson)\n\n// ... Send the binary\n```\n\n*Elixir/Erlang:*\n```elixir\n# ... After having received binary data and setting it to variable modifiedPersonData:\n\ndecodedPerson = :erlang.binary_to_term(modifiedPersonData, [:safe])\n\n# =\u003e %{ age: 38, eye_color: \"Brown\", name: \"Robert\", personality_traits: [\"Funny\", \"Inquisitive\"] }\n```\n\nsafe option should be always used when decoding an untrusted input, make also sure to have already all required atoms in the atoms table.\n\n### Encoding\n\n#### Maps (Elixir)\n\nJavascript objects map directly to Maps in Erlang\n\n```javascript\nconst Bert = require('bert-elixir')\n\n// To encode a javascript object to an elixir map:\nconst mapToEncode = { a: 1, b: \"hello!\", c: [1, 2, 3] }\nconst encodedMap = Bert.encode(mapToEncode)\n\n// BinaryToList shows individual bytes as a javascript array\nconsole.log(Bert.binaryToList(encodedMap))\n// =\u003e [ 131, 116, 0, 0, 0, 3, 100, 0, 1, 97, 97, 1, 100, 0, 1, 98, 109, 0, 0, 0, 6, 104, 101, 108, 108, 111, 33, 100, 0, 1, 99, 108, 0, 0, 0, 3, 97, 1, 97, 2, 97, 3, 106 ]\n```\n\n#### Lists\n\nJavascript arrays map to Erlang Lists\n\n```javascript\nconst Bert = require('bert-elixir')\n\nconst arrayToEncode = ['hello', 'world', 32, [{ key: \"value\" }]]\nconst encodedArray = Bert.encode(arrayToEncode)\n\nconsole.log(Bert.binaryToList(encodedArray))\n```\n\nTodo:\n- [ ] Write docs for rest of data types\n- [ ] Return `nil` as `null` instead of `'nil'`\n- [ ] Add support for NEW_FLOAT_EXT\n\n--------------------------------\n### Decoding\n\nDecoding is typically much simpler than encoding. Just pass the given Binary Erlang Term:\n\n```javascript\nconst Bert = require('bert-elixir')\n\n// We're showing the term as an array of bytes here for clarity.\n// You'll more likely have a string\nconst erlangTerm = [131, 116, 0, 0, 0, 3, 100, 0, 1, 97, 97, 1, 100, 0, 1, 98, 97, 2, 100, 0, 1, 99, 116, 0, 0, 0, 1, 100, 0, 4, 119, 111, 97, 104, 109, 0, 0, 0, 8, 97, 32, 115, 116, 114, 105, 110, 103]\n.map(x =\u003e String.fromCharCode(x)).join('') // Convert the array to a string\n\nconst decoded = Bert.decode(erlangTerm)\n\nconsole.log(decoded)\n// =\u003e { a: 1, b: 2, c: { woah: 'a string' } }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdovzhanyn%2Fbert-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexdovzhanyn%2Fbert-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexdovzhanyn%2Fbert-elixir/lists"}