# foldline

> Folds a long line according to the RFC 5322

Latest version **2.0.0** (published 2026-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install foldline
pnpm add foldline
yarn add foldline
bun add foldline
```

## Health

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

Positive: no vulnerabilities.

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

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-02-10 |
| First published | 2016-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonas Hermsmeier |
| Maintainers | jhermsmeier |
| Keywords | line, fold, folding, rfc5322, format |

## Links

- npm: https://www.npmjs.com/package/foldline
- Repository: https://codeberg.org/jhermsmeier/node-foldline
- Issues: https://codeberg.org/jhermsmeier/node-foldline/issues
- npm.io page: https://npm.io/package/foldline

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-02-10
- 1.1.0 — 2018-08-12
- 1.0.1 — 2017-11-14
- 1.0.0 — 2016-05-29

## README

# foldline
[![npm version](https://img.shields.io/npm/v/foldline.svg?style=flat-square)](https://npmjs.com/foldline)
[![npm license](https://img.shields.io/npm/l/foldline.svg?style=flat-square)](https://npmjs.com/foldline)
[![npm downloads](https://img.shields.io/npm/dm/foldline.svg?style=flat-square)](https://npmjs.com/foldline)

Folds a long line according to the [RFC 5322](https://datatracker.ietf.org/doc/html/rfc5322#section-2.1.1)

Note: There are other documents, specifically the MIME documents
([RFC 2045], [RFC 2046], [RFC 2049], [RFC 4288], [RFC 4289]),
that extend (and limit) this specification to allow for different sorts of message bodies.

[RFC 2045]: https://datatracker.ietf.org/doc/html/rfc2045
[RFC 2046]: https://datatracker.ietf.org/doc/html/rfc2046
[RFC 2049]: https://datatracker.ietf.org/doc/html/rfc2049
[RFC 4288]: https://datatracker.ietf.org/doc/html/rfc4288
[RFC 4289]: https://datatracker.ietf.org/doc/html/rfc4289

## Install via [npm](https://npmjs.com/package/foldline)

```sh
$ npm install --save foldline
```

## Usage

```js
var foldLine = require( 'foldline' )
```

## Example

```js
foldLine( 'Subject: from x.y.test by example.net via TCP with ESMTP id ABC12345 for <mary@example.net>', 30 )
```

```js
'Subject: from x.y.test by \r\n' +
  ' example.net via TCP with \r\n' +
  ' ESMTP id ABC12345 for \r\n' +
  ' <mary@example.net>'
```

## API

### Constants

- number `foldLine.DEFAULT_LINE_LENGTH` = 78
- number `foldLine.MIN_LINE_LENGTH` = 1
- number `foldLine.MAX_LINE_LENGTH` = 998

### Methods

#### `foldLine( value[, maxLength[, minLength]] )`

- string `value`: String to be folded
- number `maxLength`: Maximum line length (excluding \<CRLF\>).  
  Hard line length limit. Any line longer than this will be hard-folded.  
  Defaults to `foldLine.DEFAULT_LINE_LENGTH` (78).
- number `minLength`: Minimum line length (excluding \<CRLF\>).  
  Lines that would be shorter than this limit when soft-folded will
  be hard-folded instead, in order to maintain more consistent line lengths.  
  Defaults to `maxLength / 3`.

Returns `string`

#### `foldLine.unfold( value )`

- string `value`: String to be unfolded

Returns `string`

## Tests

```sh
$ npm test
```

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