{"id":15676511,"url":"https://github.com/gildas-lormeau/yabson","last_synced_at":"2025-05-06T22:42:30.270Z","repository":{"id":40604068,"uuid":"472065210","full_name":"gildas-lormeau/yabson","owner":"gildas-lormeau","description":"YaBSON is a library allowing schemaless binary-encoded parsing/serialization of JavaScript data with a generator-based implementation","archived":false,"fork":false,"pushed_at":"2023-10-24T15:53:11.000Z","size":81,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T15:35:52.562Z","etag":null,"topics":["binary","circular-dependencies","generator","iterable","iterator","javascript","memory-efficient","parse","parser","schemaless","serialization","serialize","serializer"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/gildas-lormeau.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-20T18:18:31.000Z","updated_at":"2025-01-28T06:46:39.000Z","dependencies_parsed_at":"2024-10-23T13:03:58.106Z","dependency_job_id":null,"html_url":"https://github.com/gildas-lormeau/yabson","commit_stats":{"total_commits":132,"total_committers":2,"mean_commits":66.0,"dds":"0.022727272727272707","last_synced_commit":"609df7e24216d503102e0f42215d9bcb8fb6c34d"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fyabson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fyabson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fyabson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gildas-lormeau%2Fyabson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gildas-lormeau","download_url":"https://codeload.github.com/gildas-lormeau/yabson/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252782441,"owners_count":21803378,"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":["binary","circular-dependencies","generator","iterable","iterator","javascript","memory-efficient","parse","parser","schemaless","serialization","serialize","serializer"],"created_at":"2024-10-03T16:02:46.595Z","updated_at":"2025-05-06T22:42:30.248Z","avatar_url":"https://github.com/gildas-lormeau.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## YaBSON\r\n\r\nYaBSON is a library allowing schemaless binary-encoded parsing/serialization of \r\nJavaScript data with a generator-based parser/serializer.\r\n\r\nThis library is designed to transfer large arbitrary amounts of data into\r\nchunks. The main goal is to provide a very simple and easily extensible API and\r\nimplementation. This also illustrates pedagogically the interest of\r\n[iterators and generators](https://developer.mozilla.org/docs/Web/JavaScript/Guide/Iterators_and_Generators)\r\nin JavaScript. Note that the binary encoding is determined by the platform\r\nendianness.\r\n\r\n## Example\r\n\r\n```js\r\nimport { getParser, getSerializer } from \"yabson\";\r\n// Deno: import { getParser, getSerializer } from \"https://deno.land/x/yabson\";\r\n// Browser: import { getParser, getSerializer } from \"https://unpkg.com/yabson\";\r\n\r\n// `object` is the data to serialize\r\nconst object = {\r\n  array: [\r\n    1,\r\n    2,\r\n    3.1415927,\r\n    true,\r\n    undefined,\r\n    null,\r\n    NaN,\r\n    42n,\r\n    \"string\",\r\n  ],\r\n  [Symbol(\"symbol\")]: \"symbol\",\r\n  typedArray: new Uint8Array([1, 2, 3]),\r\n  misc: {\r\n    date: new Date(),\r\n    error: new Error(\"error\"),\r\n    regExp: /test/gi,\r\n  },\r\n  map: new Map([[\"key\", \"value\"], [42, { value: \"result\" }]]),\r\n  set: new Set([1, 2, 3]),\r\n  stringObject: new String(\"abc\"),\r\n  numberObject: new Number(123),\r\n  booleanObject: new Boolean(true),\r\n  arrayBuffer: new Uint16Array([1, 2, 3]).buffer,\r\n};\r\n// Create empty slots in `object.array`\r\nobject.array[12] = 12;\r\n// Add a circular reference\r\nobject.map.set(object.array, object);\r\n// Add a property to a native object\r\nobject.numberObject.myProperty = \"propertyValue\";\r\n\r\n// `chunkSize` (optional) is the max. size in bytes of `chunk` in the for-of loop below\r\nconst serializer = getSerializer(object, { chunkSize: 16 });\r\nconst parser = getParser();\r\n\r\nlet result;\r\n// `chunk` is a Uint8Array of binary encoded data\r\nfor (const chunk of serializer) {\r\n  // Parse immediately binary data\r\n  result = parser.next(chunk);\r\n}\r\n// Display a deep clone of `object`\r\nconsole.log(result.value);\r\n```\r\n\r\nTest it on JSFiddle: https://jsfiddle.net/np4581x2\r\n\r\n## Example with a custom type\r\n\r\n```js\r\nimport {\r\n  getParser,\r\n  getSerializer,\r\n  parseString,\r\n  registerType,\r\n  serializeString,\r\n} from \"yabson\";\r\n\r\n// Custom type class\r\nclass CustomType {\r\n  constructor(name) {\r\n    this.name = name;\r\n  }\r\n}\r\n\r\n// Register the custom type\r\nregisterType(serializeCustomType, parseCustomType, testCustomType);\r\n\r\nfunction* serializeCustomType(data, customType) {\r\n  // Delegate serialization to `serializeString` from yabson\r\n  yield* serializeString(data, customType.name);\r\n}\r\n\r\nfunction* parseCustomType(data) {\r\n  // Delegate parsing to `parseString` from yabson\r\n  const name = yield* parseString(data);\r\n  return new CustomType(name);\r\n}\r\n\r\nfunction testCustomType(value) {\r\n  return value instanceof CustomType;\r\n}\r\n\r\n// Run test\r\nconst array = [\r\n  new CustomType(\"first\"),\r\n  new CustomType(\"second\"),\r\n];\r\n\r\nconst serializer = getSerializer(array);\r\nconst parser = getParser();\r\n\r\nlet result;\r\nfor (const chunk of serializer) {\r\n  result = parser.next(chunk);\r\n}\r\n// Display a deep clone of `array`\r\nconsole.log(result.value);\r\n```\r\n\r\n## Install\r\n\r\n```sh\r\nnpm install https://www.npmjs.com/package/yabson\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgildas-lormeau%2Fyabson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgildas-lormeau%2Fyabson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgildas-lormeau%2Fyabson/lists"}