• Factory function to create an annotations processor.

    Type Parameters

    • AType extends {
          [key: string]: any;
      }

      The type of the annotations.

    Parameters

    • Optional namespace: string = 'reactium'

      The namespace for the annotations. The namespace is searched for as @ in the provided string. For example, it defaults to 'reactium', so it's looking for '@reactium'.

    • Optional type: "sync" | "async" = 'async'

      The type of the processor, either 'async' or 'sync'.

    Returns ((content?, config?) => AType | Promise<AType>)

    • A function that takes content and a config object, and returns the processed content.
      • (content?, config?): AType | Promise<AType>
      • Parameters

        • content: string = ''
        • config: {
              rootPath: string;
              [key: string]: any;
          } = ...
          • [key: string]: any
          • rootPath: string

        Returns AType | Promise<AType>

    Example

    import { Hook, annotationsFactory, Processor } from '@atomic-reactor/reactium-sdk-core';

    // Define some example annotations

    const examples = `
    @reactium foo.bar Some content here.
    @reactium Reactium.State.description global state object
    @reactium Reactium.State.Tools collection of useful components <MyDemo> [file:example.md]
    @reactium example.multiple.mds [file:example.md] [file:example2.md]
    `;

    // Create an annotations processor
    const annotations = annotationsFactory('reactium', 'async');

    // Register a processor to prepend 'test1: ' to the content
    Hook.registerSync('@reactium', (registry) => {
    const processor: Processor<string> = {
    id: 'testProcessor1',
    processor: async (content) => {
    return 'test1: ' + content;
    },
    };

    registry.register('testProcessor1', processor);
    });

    // Use the annotations processor to process the example annotations
    annotations(examples).then((obj) => {
    console.log(op.get(obj, 'foo.bar')); // Logs 'test1: Some content here.'
    console.log(op.get(obj, 'Reactium.State.description')); // Logs 'test1: global state object'
    console.log(op.get(obj, 'Reactium.State.Tools')); // Logs 'test1: collection of useful components <MyDemo> [file:example.md]'
    });