# to-buffer

> Pass in a string, array, Buffer, Data View, or Uint8Array, and get a Buffer back.

Latest version **1.2.2** (published 2025-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install to-buffer
pnpm add to-buffer
yarn add to-buffer
bun add to-buffer
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2025-09-24 |
| First published | 2016-02-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.4 |
| Dependencies | 3 |
| Unpacked size | 13.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Mathias Buus |
| Maintainers | ljharb, mafintosh |

## Links

- npm: https://www.npmjs.com/package/to-buffer
- Repository: https://github.com/browserify/to-buffer
- Issues: https://github.com/browserify/to-buffer/issues
- npm.io page: https://npm.io/package/to-buffer

## Dependencies (3)

- [isarray](https://npm.io/package/isarray.md) ^2.0.5
- [safe-buffer](https://npm.io/package/safe-buffer.md) ^5.2.1
- [typed-array-buffer](https://npm.io/package/typed-array-buffer.md) ^1.0.3

## Recent versions

- 1.2.2 (latest) — 2025-09-24
- 1.2.1 — 2025-06-20
- 1.2.0 — 2025-06-17
- 1.1.1 — 2018-04-26
- 1.1.0 — 2017-04-12
- 1.0.1 — 2016-02-15
- 1.0.0 — 2016-02-15

## README

# to-buffer <sup>[![Version Badge][2]][1]</sup>

Pass in a string, array, Buffer, Data View, or Uint8Array, and get a Buffer back.

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][11]][1]


```
npm install to-buffer
```

## Usage

``` js
var toBuffer = require('to-buffer');

console.log(toBuffer('hi')); // <Buffer 68 69>
console.log(toBuffer(Buffer('hi'))); // <Buffer 68 69>
console.log(toBuffer('6869', 'hex')); // <Buffer 68 69>
console.log(toBuffer(43)); // throws
```

[1]: https://npmjs.org/package/to-buffer
[2]: https://versionbadg.es/browserify/to-buffer.svg
[5]: https://david-dm.org/browserify/to-buffer.svg
[6]: https://david-dm.org/browserify/to-buffer
[7]: https://david-dm.org/browserify/to-buffer/dev-status.svg
[8]: https://david-dm.org/browserify/to-buffer#info=devDependencies
[11]: https://nodei.co/npm/to-buffer.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/to-buffer.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/to-buffer.svg
[downloads-url]: https://npm-stat.com/charts.html?package=to-buffer
[codecov-image]: https://codecov.io/gh/browserify/to-buffer/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/browserify/to-buffer/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/browserify/to-buffer
[actions-url]: https://github.com/browserify/to-buffer/actions

---
_Source: https://npm.io/package/to-buffer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
