npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

commonform-simplify-structure

v1.0.0

Published

restructure forms so each form contains at most one series

Readme

Common Forms are hierarchical in structure, like XML and JSON documents more generally. Unlike some other document formats, Common Form allow arbitrary nesting of block elements (forms) within other block elements. For example:

in the states:

  1. Virginia
  2. New York

and the territories:

  1. Guam
  2. Puerto Rico

is represented:

var first = {
  content: [
    'in the states:',
    {form: {content: ['Virgina']}},
    {form: {content: ['New York']}},
    'and the territories:',
    {form: {content: ['Guam']}},
    {form: {content: ['Puerto Rico']}}
  ]
}

simplify splits the root content array into multiple children, with one series of contiguous child forms in each

var simplify = require('commonform-simplify-structure')
var assert = require('assert')

simplify(first)

assert.deepEqual(first, {
  content: [
    {
      form: {
        content: [
          'in the states:',
          {form: {content: ['Virgina']}},
          {form: {content: ['New York']}}
        ]
      }
    },
    {
      form: {
        content: [
          'and the territories:',
          {form: {content: ['Guam']}},
          {form: {content: ['Puerto Rico']}}
        ]
      }
    }
  ]
})

A form with multiple series of contiguous child forms in a child form

var second = {
  content: [
    {
      heading: 'Jurisdiction',
      form: {
        content: [
          'in the states:',
          {form: {content: ['Virgina']}},
          {form: {content: ['New York']}},
          'and the territories:',
          {form: {content: ['Guam']}},
          {form: {content: ['Puerto Rico']}}
        ]
      }
    }
  ]
}

gets changed in the same way, preserving an child-form headings so references remain correct

simplify(second)

assert.deepEqual(second, {
  content: [
    {
      heading: 'Jurisdiction',
      form: {
        content: [
          {
            form: {
              content: [
                'in the states:',
                {form: {content: ['Virgina']}},
                {form: {content: ['New York']}}
              ]
            }
          },
          {
            form: {
              content: [
                'and the territories:',
                {form: {content: ['Guam']}},
                {form: {content: ['Puerto Rico']}}
              ]
            }
          }
        ]
      }
    }
  ]
})

Each new paragraph in a form ends up in a separate child form

var third = {
  content: [
    {
      heading: 'Jurisdiction',
      form: {
        content: [
          // Paragraph
          'in the states:',
          // Series
          {form: {content: ['Virgina']}},
          {form: {content: ['New York']}},
          // Paragraph
          'and the territories:',
          // Series
          {form: {content: ['Guam']}},
          {form: {content: ['Puerto Rico']}},
          // Paragraph
          'and Washington, D.C.'
        ]
      }
    }
  ]
}

simplify(third)

assert.deepEqual(third, {
  content: [
    {
      heading: 'Jurisdiction',
      form: {
        content: [
          {
            form: {
              content: [
                'in the states:',
                {form: {content: ['Virgina']}},
                {form: {content: ['New York']}}
              ]
            }
          },
          {
            form: {
              content: [
                'and the territories:',
                {form: {content: ['Guam']}},
                {form: {content: ['Puerto Rico']}}
              ]
            }
          },
          {
            form: {
              content: [
                'and Washington, D.C.'
              ]
            }
          }
        ]
      }
    }
  ]
})

Definitions, uses, references, and blanks are preserved:

var fourth = {
  content: [
    {
      heading: 'Jurisdiction',
      form: {
        content: [
          // Paragraph
          'in the ', {use: 'States'}, ':',
          // Series
          {form: {content: ['Virgina']}},
          {form: {content: ['New York']}},
          // Paragraph
          'and the ', {use: 'Territories'}, ':',
          // Series
          {form: {content: ['Guam']}},
          {form: {content: ['Puerto Rico']}},
          // Paragraph
          'and Washington, D.C.'
        ]
      }
    }
  ]
}

simplify(fourth)

assert.deepEqual(fourth, {
  content: [
    {
      heading: 'Jurisdiction',
      form: {
        content: [
          {
            form: {
              content: [
                'in the ', {use: 'States'}, ':',
                {form: {content: ['Virgina']}},
                {form: {content: ['New York']}}
              ]
            }
          },
          {
            form: {
              content: [
                'and the ', {use: 'Territories'}, ':',
                {form: {content: ['Guam']}},
                {form: {content: ['Puerto Rico']}}
              ]
            }
          },
          {
            form: {
              content: [
                'and Washington, D.C.'
              ]
            }
          }
        ]
      }
    }
  ]
})

See also this blob post by the author.