commonform-phrase-annotator

    2.0.0 • Public • Published

    commonform-phrase-annotator

    The module exports a single function that takes an array of strings and a function for generating annotations, returning an annotator function to apply to Common Forms.

    var phrases = ['thereof', 'whereof']

    The annotation function receives the form in which a string was found, its path within the overall form, and the string that matches. It must return a Common Form Annotations.

    function implementation (form, path, string) {
      return {
        message: '"' + string + '" is archaic',
        path: path,
        source: 'example-annotator',
        url: null
      }
    }
     
    var phraseAnnotator = require('commonform-phrase-annotator')
     
    var annotator = phraseAnnotator(phrases, implementation)

    The library does the job of finding matches and calculating paths.

    var assert = require('assert')
     
    assert.deepStrictEqual(
      annotator({ content: ['all rights thereof and whereof'] }),
      [
        {
          message: '"thereof" is archaic',
          path: ['content', 0],
          source: 'example-annotator',
          url: null
        },
        {
          message: '"whereof" is archaic',
          path: ['content', 0],
          source: 'example-annotator',
          url: null
        }
      ]
    )

    Install

    npm i commonform-phrase-annotator

    DownloadsWeekly Downloads

    1

    Version

    2.0.0

    License

    BlueOak-1.0.0

    Unpacked Size

    4.07 kB

    Total Files

    4

    Last publish

    Collaborators

    • kemitchell