Skip to content
correct typical string-related Common Form validation problems
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.npmignore
.travis.yml
LICENSE.md
README.md
collapse-spaces.js
index.js
package.json
prepublish.js
remove-non-ascii.js
replace-unicode.js

README.md

commonform-fix-strings

correct typical string-related Common Form validation problems

var fixStrings = require('commonform-fix-strings')

Concatenates contiguous strings:

var assert = require('assert')

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

Squashes contiguous spaces:

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

Squashes contiguous blanks:

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

Removes leading whitespace:

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

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

Removes trailing whitespace:

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

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

Removes both:

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

From headings:

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

Remove empty headings:

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

Replaces common non-ASCII characters with ASCII equivalents:

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:

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

Removes space leading a child form:

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

Removes space following a child form:

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

Preserves conspicuous properties:

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

Cleans up terms and headings:

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:

assert.deepStrictEqual(
  fixStrings({
    content: [
      'A',
      { form: { content: ['B'] } },
      'C'
    ]
  }),
  {
    content: [
      'A',
      { form: { content: ['B'] } },
      'C'
    ]
  }
)
You can’t perform that action at this time.