# commonform-fix-strings

> correct typical string-related Common Form validation problems

Latest version **3.0.0** (published 2026-09-05) · BlueOak-1.0.0 license · 0 weekly downloads

## Install

```sh
npm install commonform-fix-strings
pnpm add commonform-fix-strings
yarn add commonform-fix-strings
bun add commonform-fix-strings
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-09-05 |
| First published | 2015-09-09 |
| Weekly downloads | 0 |
| License | BlueOak-1.0.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kyle E. Mitchell |
| Maintainers | kemitchell |

## Links

- npm: https://www.npmjs.com/package/commonform-fix-strings
- Repository: https://github.com/commonform/commonform-fix-strings
- Homepage: https://github.com/commonform/commonform-fix-strings#readme
- Issues: https://github.com/commonform/commonform-fix-strings/issues
- npm.io page: https://npm.io/package/commonform-fix-strings

## Dependencies (1)

- [commonform-predicate](https://npm.io/package/commonform-predicate.md) ^7.0.1

## Recent versions

- 3.0.0 (latest) — 2026-09-05
- 2.0.1 — 2019-06-04
- 2.0.0 — 2019-06-04
- 1.0.0 — 2018-01-24
- 0.2.5 — 2016-09-09
- 0.2.4 — 2016-08-06
- 0.2.3 — 2015-11-01
- 0.2.2 — 2015-10-30
- 0.2.1 — 2015-10-18
- 0.2.0 — 2015-10-13
- 0.1.1 — 2015-09-09
- 0.1.0 — 2015-09-09

## README

# commonform-fix-strings

correct typical string-related Common Form validation problems

```javascript
import fixStrings from 'commonform-fix-strings'
```

Concatenates contiguous strings:

```javascript
import assert from 'node:assert'

assert.deepStrictEqual(
  fixStrings({ content: ['A', 'B'] }),
  { content: ['AB'] }
)
```

Squashes contiguous spaces:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: ['A ', ' B'] }),
  { content: ['A B'] }
)
```

Squashes contiguous blanks:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: [{ blank: '' }, { blank: '' }] }),
  { content: [{ blank: '' }] }
)
```

Removes leading whitespace:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: [' A'] }),
  { content: ['A'] }
)

assert.deepStrictEqual(
  fixStrings({ content: [' ', { definition: 'A' }] }),
  { content: [{ definition: 'A' }] }
)
```

Removes trailing whitespace:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: ['A '] }),
  { content: ['A'] }
)

assert.deepStrictEqual(
  fixStrings({ content: [{ definition: 'A' }, ' '] }),
  { content: [{ definition: 'A' }] }
)
```

Removes both:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: [' A '] }),
  { content: ['A'] }
)
```

From headings:

```javascript
assert.deepStrictEqual(
  fixStrings({
    content: [
      {
        heading: ' A  B ',
        form: { content: ['C'] }
      }
    ]
  }),
  {
    content: [
      {
        heading: 'A B',
        form: { content: ['C'] }
      }
    ]
  }
)
```

Remove empty headings:

```javascript
assert.deepStrictEqual(
  fixStrings({
    content: [
      {
        heading: '  ',
        form: { content: ['C'] }
      }
    ]
  }),
  { content: [{ form: { content: ['C'] } }] }
)
```

Replaces common non-ASCII characters with ASCII equivalents:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: ['String “with quotes”.'] }),
  { content: ['String "with quotes".'] }
)

assert.deepStrictEqual(
  fixStrings({ content: ['Has — em dash'] }),
  { content: ['Has --- em dash'] }
)
```

Removes other non-ASCII characters:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: ['See §10'] }),
  { content: ['See 10'] }
)
```

Removes space leading a child form:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: ['A ', { form: { content: ['B'] } }] }),
  { content: ['A', { form: { content: ['B'] } }] }
)
```

Removes space following a child form:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: [{ form: { content: ['B'] } }, ' A'] }),
  { content: [{ form: { content: ['B'] } }, 'A'] }
)
```

Preserves `conspicuous` properties:

```javascript
assert.deepStrictEqual(
  fixStrings({ conspicuous: 'yes', content: ['A'] }),
  { conspicuous: 'yes', content: ['A'] }
)
```

Cleans up terms and headings:

```javascript
assert.deepStrictEqual(
  fixStrings({ content: [{ use: 'A   B' }] }),
  { content: [{ use: 'A B' }] }
)

assert.deepStrictEqual(
  fixStrings({ content: [{ reference: 'A   B' }] }),
  { content: [{ reference: 'A B' }] }
)

assert.deepStrictEqual(
  fixStrings({ content: [{ heading: 'A   B', form: { content: ['test'] } }] }),
  { content: [{ heading: 'A B', form: { content: ['test'] } }] }
)
```

Valid forms pass right through:

```javascript
assert.deepStrictEqual(
  fixStrings({
    content: [
      'A',
      { form: { content: ['B'] } },
      'C'
    ]
  }),
  {
    content: [
      'A',
      { form: { content: ['B'] } },
      'C'
    ]
  }
)
```

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