{"id":16741707,"url":"https://github.com/italypaleale/arraybuffer","last_synced_at":"2025-08-17T01:05:49.468Z","repository":{"id":57184207,"uuid":"407224781","full_name":"ItalyPaleAle/arraybuffer","owner":"ItalyPaleAle","description":"NPM: arraybuffer-encoding","archived":false,"fork":false,"pushed_at":"2021-12-27T00:31:20.000Z","size":156,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-11T22:45:00.998Z","etag":null,"topics":["arraybuffer","base64","hex","javascript"],"latest_commit_sha":null,"homepage":"https://italypaleale.github.io/arraybuffer/","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/ItalyPaleAle.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":"2021-09-16T15:49:41.000Z","updated_at":"2024-11-12T16:44:31.000Z","dependencies_parsed_at":"2022-08-23T01:20:46.155Z","dependency_job_id":null,"html_url":"https://github.com/ItalyPaleAle/arraybuffer","commit_stats":null,"previous_names":["italypaleale/arraybuffer-encode"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/ItalyPaleAle/arraybuffer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItalyPaleAle%2Farraybuffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItalyPaleAle%2Farraybuffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItalyPaleAle%2Farraybuffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItalyPaleAle%2Farraybuffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ItalyPaleAle","download_url":"https://codeload.github.com/ItalyPaleAle/arraybuffer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ItalyPaleAle%2Farraybuffer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270792483,"owners_count":24646187,"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-16T02:00:11.002Z","response_time":91,"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":["arraybuffer","base64","hex","javascript"],"created_at":"2024-10-13T01:04:40.131Z","updated_at":"2025-08-17T01:05:49.403Z","avatar_url":"https://github.com/ItalyPaleAle.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/arraybuffer-encoding)](https://www.npmjs.com/package/arraybuffer-encoding) [![Node.js CI](https://github.com/ItalyPaleAle/arraybuffer/actions/workflows/node.js.yaml/badge.svg)](https://github.com/ItalyPaleAle/arraybuffer/actions/workflows/node.js.yaml) ![License: MIT](https://img.shields.io/github/license/ItalyPaleAle/arraybuffer)\n\n# ArrayBuffer encoding and decoding tools\n\nThis package contains utilities to encode and decode ArrayBuffer objects to **base64** and **hex** with full support for Unicode and binary data. It's especially designed for usage in web browsers, but it works on Node.js too.\n\n- Encode and decode ArrayBuffer objects (and typed arrays like Uint8Array, and strings) to base64 and hex, for the browser and Node.js\n- Supports base64 \"standard\" and \"URL-safe\" encodings, with optional padding; custom base64 encodings can be defined as well\n- Clean, well-documented APIs\n- Reasonable performance\n\nFull API documentation available at [https://italypaleale.github.io/arraybuffer/](https://italypaleale.github.io/arraybuffer/)\n\n## Installation\n\nInstall [from NPM](https://www.npmjs.com/package/arraybuffer-encoding):\n\n```sh\nnpm i arraybuffer-encoding\n```\n\n## Base64\n\nThis package offers support for encoding and decoding base64 in two variants:\n\n- **\"Standard\" base64** (RFC 4648 §4): uses `+` and `/` for characters 62 and 63 respectively. Encoded strings have `=` padding characters added at the end by the `Encode` function, if necessary.  \n  Import with:  \n\n  ```js\n  import {Encode, Decode} from 'arraybuffer-encoding/base64/standard'\n  ```\n\n  Can also use `arraybuffer-encoding/base64` as alias.\n\n- **URL-safe base64** (RFC 4648 §5): uses `-` and `_` for characters 62 and 63 respectively. Encoded strings are never padded by the `Encode` function.  \n  Import with:  \n\n  ```js\n  import {Encode, Decode} from 'arraybuffer-encoding/base64/url'\n  ```\n\n\u003e In all cases, the `Decode` function accepts strings with or without padding.\n\n### Encoding to base64\n\nTo encode an ArrayBuffer to base64, use the `Encode(ab: ArrayBuffer): string` method:\n\n```js\nimport {Encode} from 'arraybuffer-encoding/base64'\nconst ab = new ArrayBuffer(...)\nconst encoded = Encode(ab)\n```\n\nTyped arrays, such as Uint8Array objects, can be passed as well:\n\n```js\nimport {Encode} from 'arraybuffer-encoding/base64'\nconst array = new Uint8Array(...)\nconst encoded = Encode(ab)\n```\n\nTo encode a UTF-8 string, convert it to a typed array object first:\n\n```js\nimport {Encode} from 'arraybuffer-encoding/base64'\nconst str = 'Hello world'\nconst textEnc = new TextEncoder()\nconst encoded = Encode(textEnc.encode(str))\n```\n\n### Decoding base64\n\nTo decode a base64-encoded string, use the `Decode(str: string): ArrayBuffer` method, which returns an ArrayBuffer object:\n\n```js\nimport {Decode} from 'arraybuffer-encoding/base64'\nconst encoded = 'RGV2cw'\nconst ab = Decode(encoded)\n```\n\nThe decoded ArrayBuffer can be converted to a string (for example, UTF-8 encoded) with:\n\n```js\nimport {Decode} from 'arraybuffer-encoding/base64'\nconst encoded = 'RGV2cw'\nconst ab = Decode(encoded)\nconst textDecoder = new TextDecoder('utf-8')\nconst str = textDecoder.decode(ab)\n```\n\n### Custom base64 charset\n\nIf needed, you can define your own base64 charset by using the `Encoding` class in `arraybuffer-encoding/base64/encoding`:\n\n```js\nimport {Encoding} from 'arraybuffer-encoding/base64/encoding'\nconst base64 = new Encoding(charset, noPadding)\n```\n\nThe constructor accepts two parameters:\n\n- `charset: string` is a string of 64 characters containing the base64 charset to use\n- `noPadding: boolean` if true, the `Encode` method never adds padding at the end of the string (note that the `Decode` method always considers padding optional)\n\nThe object contains two methods:\n\n- `Encode(ab: ArrayBuffer): string`\n- `Decode(str: string): ArrayBuffer`\n\n## Hex\n\nTo import the hex encoding and decoding utilities, use:\n\n```js\nimport {Encode, Decode} from 'arraybuffer-encoding/hex'\n```\n\n### Encoding to hex\n\nTo encode an ArrayBuffer to hex, use the `Encode(ab: ArrayBuffer): string` method:\n\n```js\nimport {Encode} from 'arraybuffer-encoding/hex'\nconst ab = new ArrayBuffer(...)\nconst encoded = Encode(ab)\n```\n\nTyped arrays, such as Uint8Array objects, can be passed as well:\n\n```js\nimport {Encode} from 'arraybuffer-encoding/hex'\nconst array = new Uint8Array(...)\nconst encoded = Encode(ab)\n```\n\nTo encode a UTF-8 string, convert it to a typed array object first:\n\n```js\nimport {Encode} from 'arraybuffer-encoding/hex'\nconst str = 'Hello world'\nconst textEnc = new TextEncoder()\nconst encoded = Encode(textEnc.encode(str))\n```\n\n### Decoding hex\n\nTo decode a hex-encoded string, use the `Decode(str: string): ArrayBuffer` method, which returns an ArrayBuffer object:\n\n```js\nimport {Decode} from 'arraybuffer-encoding/hex'\nconst encoded = '54686520717569636b2062726f776e20f09fa68a206a756d7073206f766572203133206c617a7920f09f90b62e'\nconst ab = Decode(encoded)\n```\n\nThe decoded ArrayBuffer can be converted to a string (for example, UTF-8 encoded) with:\n\n```js\nimport {Decode} from 'arraybuffer-encoding/hex'\nconst encoded = '54686520717569636b2062726f776e20f09fa68a206a756d7073206f766572203133206c617a7920f09f90b62e'\nconst ab = Decode(encoded)\nconst textDecoder = new TextDecoder('utf-8')\nconst str = textDecoder.decode(ab)\n```\n\n## License\n\nThis package is released under a MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitalypaleale%2Farraybuffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitalypaleale%2Farraybuffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitalypaleale%2Farraybuffer/lists"}