{"id":19543101,"url":"https://github.com/batterii/encode-object","last_synced_at":"2025-02-26T05:27:41.106Z","repository":{"id":40661981,"uuid":"234382162","full_name":"Batterii/encode-object","owner":"Batterii","description":"Object encoding and decoding utils","archived":false,"fork":false,"pushed_at":"2022-04-29T19:27:46.000Z","size":305,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-02-09T01:34:18.917Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/Batterii.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}},"created_at":"2020-01-16T18:13:00.000Z","updated_at":"2022-04-29T19:26:58.000Z","dependencies_parsed_at":"2022-07-24T19:46:34.546Z","dependency_job_id":null,"html_url":"https://github.com/Batterii/encode-object","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Batterii%2Fencode-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Batterii%2Fencode-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Batterii%2Fencode-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Batterii%2Fencode-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Batterii","download_url":"https://codeload.github.com/Batterii/encode-object/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240797562,"owners_count":19859209,"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":[],"created_at":"2024-11-11T03:17:19.595Z","updated_at":"2025-02-26T05:27:40.921Z","avatar_url":"https://github.com/Batterii.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @batterii/encode-object\nThis module contains utility functions for encoding and decoding\nJSON-serializable objects from [base64url][1], allowing them to be safely sent\nas HTTP headers and URI components.\n\nThere are many modules like this already, but at Batterii we wrote yet another\none and ended up wanting to open-source some things that depend on it. So we\nopen-sourced this as well. Feel free to use but there's really nothing special\nabout it.\n\nNote that while encoded objects are not typically human-readable, that does not\nmean they are encrypted or signed in any way. Reading the data from them is as\nsimple as reversing the encoding process, and tampering with them is as simple\nas repeating it with different data.\n\nTo produce signed tokens, which prevent tampering, use [tokengrip][2] instead.\n\n\n## Usage\n```js\nimport { decodeObject, encodeObject } from '@batterii/encode-object';\n\nconst str = encodeObject({ foo: 'bar' } );\n\nconsole.log(str);\n// eyJmb28iOiJiYXIifQ\n\nconst obj = decodeObject(str);\n\nconsole.log(obj);\n// { foo: 'bar' }\n```\n\nIn addition to plain objects and arrays, top-level JSON primitives are also\nsupported:\n\n```js\nconsole.log(decodeObject(encodeObject('some string')));\n// some string\n\nconsole.log(decodeObject(encodeObject(true)));\n// true\n\nconsole.log(decodeObject(encodeObject(false)));\n// false\n\nconsole.log(decodeObject(encodeObject(null)));\n// null\n```\n\n\n## Error Handling\nThis package uses [Nani][3] to define the following error classes:\n\n- `EncodeObjectError`: This is the base class for all other errors in\n  the package, for namespacing purposes.\n\n- `InvalidJsonError`: Will be thrown if encoded text contaning invalid JSON is\n  sent to `decodeObject`.\n\n\n[1]: https://base64.guru/standards/base64url\n[2]: https://www.npmjs.com/package/tokengrip\n[3]: https://www.npmjs.com/package/nani\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbatterii%2Fencode-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbatterii%2Fencode-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbatterii%2Fencode-object/lists"}