Skip to content
correct typical string-related Common Form validation problems
JavaScript
Branch: master
Clone or download
Pull request Compare This branch is 11 commits behind commonform:master.
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
README.md
collapse-spaces.js
index.js
package.json
prepublish.js
remove-non-ascii.js
replace-unicode.js

README.md

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

Concatenates contiguous strings:

var assert = require('assert')

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

Squashes contiguous spaces:

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

Squashes contiguous blanks:

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

Removes leading whitespace:

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

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

Removes trailing whitespace:

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

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

Removes both:

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

From headings:

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

Remove empty headings:

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

Replaces common non-ASCII characters with ASCII equivalents:

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

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

Removes other non-ASCII characters:

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

Removes space leading a child form:

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

Removes space following a child form:

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

Preserves conspicuous properties:

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

Cleans up terms and headings:

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

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

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

Valid forms pass right through:

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