Interface for a wide range of utility functions.

Hierarchy

  • Helper

Properties

CSV: {
    isContentValidCSV: ((uploadedFile, checkFileExtension?, options?) => boolean);
    parse: ((csv, options?) => (string | number)[][]);
    stringify: ((table, options?) => string);
}

This sub interface allows to work with CSV data.

Type declaration

  • isContentValidCSV: ((uploadedFile, checkFileExtension?, options?) => boolean)
      • (uploadedFile, checkFileExtension?, options?): boolean
      • Tests the uploaded file result to see if it is a valid CSV file.

        Parameters

        • uploadedFile: MEUIUploadFile

          The uploaded file result to test.

        • Optional checkFileExtension: boolean

          Check the file extension as well. Default value is false.

        • Optional options: CsvOptions

          The CSV options to use for testing. Default value is null.

        Returns boolean

        True if the uploaded file result is a valid CSV file, and false if it is not.

  • parse: ((csv, options?) => (string | number)[][])
      • (csv, options?): (string | number)[][]
      • Helper function to parse a string to a CSV table.

        Parameters

        • csv: string

          The CSV string to parse.

        • Optional options: CsvOptions

          The optional CSV options to use for parsing.

        Returns (string | number)[][]

        An array of arrays (with the rows and columns) of the parsed result. Note that based on disableNumberConversion the values may be strings or numbers.

  • stringify: ((table, options?) => string)
      • (table, options?): string
      • Helper function to convert a CSV table to a string.

        Parameters

        • table: (string | number)[][]

          The CSV table to convert to a string.

        • Optional options: CsvOptions

          The optional CSV options to use for stringifying.

        Returns string

        The CSV string.

Config: {
    GetConfig<T>() => T;
    HasConfig() => boolean;
    Merge<T>(target) => void;
}

The config sub interface allows to interact with the script configuration.

Type declaration

  • GetConfig:function
    • Returns the current script configuration object.

      Type Parameters

      • T

      Returns T

      The current script configuration object.

  • HasConfig:function
    • Check to see if the script has a configuration.

      Returns boolean

      True if the script has a configuration, and false if it does not.

  • Merge:function
    • Merges the script configuration into the passed target. This is useful to define the configuration object with all defaults, and then overwrite the defaults with the script configuration, which will also work partially. Anything not defined will still be the default value.

      Type Parameters

      • T

      Parameters

      • target: T

        The target object to merge the script configuration into. This will be usually the full configuration object with all defaults.

      Returns void

Convert: {
    mmToPoints(mm) => number;
    pointsToMm(pt) => number;
}

The convert sub interface allows to convert between different units.

Type declaration

  • mmToPoints:function
    • Convert mm to points.

      Parameters

      • mm: number

        The value in mm.

      Returns number

      The value in points.

  • pointsToMm:function
    • Convert points to mm.

      Parameters

      • pt: number

        The value in points.

      Returns number

      The value in mm.

TextHelper: {
    PerformFieldDataReplacement(fieldArray, replacementData, optionalVariableTags?, optionalImageRetrievalFunction?, replaceCaseInvariant?, textSuppressionMode?, replacementText?, callback?) => void;
    SuppressText(text, tags, data, mode) => string;
}

The text helper sub interface has helper functions to work with text.

Type declaration

  • PerformFieldDataReplacement:function
    • Performs variable data replacement on the given field array using the given replacement data. The operation depends on the field type.

      Parameters

      • fieldArray: BaseField[]

        The field listing to perform the replacement on.

      • replacementData: {
            [key: string]: string;
        }

        The replacement data to use with keys (placeholder names) and values (replacement values). This is used for text and barcode fields.

        • [key: string]: string
      • Optional optionalVariableTags: {
            end: string;
            start: string;
        }

        The start and end tags for the text replacement.

        • end: string
        • start: string
      • Optional optionalImageRetrievalFunction: (() => void)

        For image fields, this function can be used to retrieve the image data for the given image field. If not specified, the image will not be replaced.

          • (): void
          • Returns void

      • Optional replaceCaseInvariant: boolean

        This flag controls if the replacement should be case invariant. Default value is false.

      • Optional textSuppressionMode: TextSuppressionMode

        The optional text suppression mode to use. Default value is null meaning no suppression to be used.

      • Optional replacementText: string

        The optional replacement text allows to feed in the text to replace for the field from the outside - essentially overriding the field value. Default value is null meaning the field value will be used.

      • Optional callback: (() => void)

        The callback function to trigger once the replacement is complete.

          • (): void
          • Returns void

      Returns void

  • SuppressText:function
    • Suppresses segments of the given text based on whether corresponding data is present.

      The function identifies segments delimited by the specified start and end tags and checks if each segment's associated key exists in the provided data. If a key is missing, the segment is suppressed according to the specified mode.

      Parameters

      • text: string

        The input text that may contain segments eligible for suppression.

      • tags: {
            end: string;
            start: string;
        }

        An object defining the start and end tags that mark the segments.

        • end: string
        • start: string
      • data: {
            [key: string]: string;
        }

        An object mapping keys to values; a missing key indicates that its segment should be suppressed.

        • [key: string]: string
      • mode: TextSuppressionMode

        The suppression mode to apply. Defaults to null (i.e., no suppression) if not provided.

      Returns string

      The resulting text after applying the suppression logic.

Methods

  • Maps all given placeholders to the given values. The result will be an object with the placeholder as key and the mapping result as the value. The mapping result will have the index of the best matching value entry in the values array as the mapping index. Or -1 if no value matched. Note that multiple placeholders may be mapped to the same value.

    Parameters

    • placeholders: string[]

      The placeholders to map.

    • values: string[]

      The candidate values to map the placeholders to.

    Returns BatchMapping

    The mapping result.

  • Returns the index of the best matching item in a list of candidates for a given reference string using the simplified similarity check GetSimilarity.

    Parameters

    • reference: string

      The reference string to compare the candidates against.

    • candidates: string[]

      The list of candidates to compare against the reference string.

    Returns number

    The index of the best matching item in the list of candidates. If no item matches it will return -1.

  • Clears a previously triggered timeout based on the timeout id returned by SetTimeOut to avoid the timeout to be triggered.

    Parameters

    • timeoutId: number

      The timeout id to clear.

    Returns void

  • Performs a deep copy of the passed object. This will also copy all nested objects and arrays.

    Type Parameters

    • T

    Parameters

    • item: T

      The object to copy.

    Returns T

    The deep copy of the passed object.

  • Executes a megascript instance, optionally overriding the script and config. Note that this only works server side and cannot be used client side.

    Parameters

    • megascriptInstanceName: string

      The instance name to trigger.

    • Optional script: string

      Optionally the script to execute. If null, the script configured for the instance will be used.

    • Optional config: string

      The optional configuration to overwrite. If null, the configuration configured for the instance will be used.

    Returns boolean

    Boolean flag indicating if the script was executed successfully.

  • Return the custom field class for a custom field. When registering a custom field type, a custom class can be defined and made accessible through this function. The functions and interface depend fully on the custom script implementation.

    Parameters

    • fieldOrType: string | CustomField

      The custom field or the custom field type to get the class for.

    Returns unknown

    The custom field class or null if no class is registered for the given field or type.

  • Gets the DPI of the given image when it is rendered into the given dimensions using the given crop flag.

    Parameters

    • width: number

      The width of the area to fit the image into.

    • height: number

      The height of the area to fit the image into.

    • crop: boolean

      Flag indicating if the image should be cropped to fit the given dimensions fully, or if the entire image should be visible.

    • image: MediaItem | DimensionalItem

      The image to fit into the given dimensions.

    Returns number

    The DPI of the given image when it is rendered into the given dimensions using the given crop flag.

  • Get the DPI of the given image when it is rendered for a given Image field using the given crop flag.

    Parameters

    • field: ImageField

      The field to test the DPI for.

    • image: MediaItem | DimensionalItem

      The image to test the DPI for.

    • crop: boolean

      Flag indicating if the image should be cropped to fit the given dimensions fully, or if the entire image should be visible.

    Returns number

  • Returns the per product setting for the minimum image resolution or 0 if no setting is configured. If the value is <= 0, DPI checks will be disabled.

    Returns number

  • Calculates the scale factor required to fit the given diemnsional item (usually a Javascript Image object or a MediaItem) into the given width and height. The crop parameter can be used to specify if the image should be cropped to fit the given dimensions fully, or if the entire image should be visible.

    Parameters

    • width: number

      The width of the area to fit the image into.

    • height: number

      The height of the area to fit the image into.

    • crop: boolean

      Flag indicating if the image should be cropped to fit the given dimensions fully, or if the entire image should be visible.

    • image: MediaItem | DimensionalItem

      The image to fit into the given dimensions.

    Returns number

    The scale factor required to fit the given image into the given dimensions.

  • Simplified similarity check for two strings. The higher the value, the more similar the strings are.

    Parameters

    • a: string

      The first string to compare.

    • b: string

      The second string to compare.

    Returns number

    The similarity value >= 0. 0 means the strings are not similar at all. The higher the value, the more similar the strings are.

  • Escapes the HTML characters in the given text using https://github.com/mathiasbynens/he

    Parameters

    • text: string

      The text to escape.

    Returns string

    The escaped text.

  • Unescapes the HTML characters in the given text using https://github.com/mathiasbynens/he. The options parameter can be used to specify additional options for the unescape function - see above Github page for this.

    Parameters

    • text: string

      The text to unescape.

    • Optional options: UnescapeOptions

      The optional options to use for unescaping.

    Returns string

    The unescaped text.

  • Test function to check if the passed item is an array.

    Parameters

    • item: unknown

      The item to test.

    Returns boolean

    True if the passed item is an array, and false if it is not.

  • Test function to check if the passed item is a boolean.

    Parameters

    • item: unknown

      The item to test.

    Returns boolean

    True if the passed item is a boolean, and false if it is not.

  • Test function to check if the passed item is a function.

    Parameters

    • item: unknown

      The item to test.

    Returns boolean

    True if the passed item is a function, and false if it is not.

  • Test if the string passed is null, undefined or whitespace.

    Parameters

    • value: string

      The text to test.

    Returns boolean

    True if the string passed is null, undefined or whitespace, and false if it is not.

  • Test function to check if the passed item is a number.

    Parameters

    • item: unknown

      The item to test.

    Returns boolean

    True if the passed item is a number, and false if it is not.

  • Test function to check if the passed item is an object.

    Parameters

    • item: unknown

      The item to test.

    Returns boolean

    True if the passed item is an object, and false if it is not.

  • Test function to check if the passed item is a string.

    Parameters

    • item: unknown

      The item to test.

    Returns boolean

    True if the passed item is a string, and false if it is not.

  • Loads an external script or data set into the editor. The script will be loaded asynchronously and the callback will be triggered once the external resource is loaded.

    Parameters

    • url: string

      The URL to load the external resource from.

    • Optional callback: ((data?) => void)

      The callback function to trigger once the external resource is loaded.

        • (data?): void
        • Parameters

          • Optional data: unknown

          Returns void

    • Optional onlyData: boolean

      If set to true, the external resource will be loaded as data set and passed to the callback as parameter. If set to false, the URL will be loaded as a Javascript resource and the load event parameter will be passed. Default value is false.

    Returns void

  • Will measure the given text (width & height) using the given formatting options with the browser engine.

    Parameters

    • text: string

      The text to measure.

    • font: string

      The font to use for the measurement.

    • fontSize: number

      The font size to use for the measurement.

    • isBold: boolean

      If set, we will use a bold font for the measurement.

    • isItalic: boolean

      If set, we will use an italic font for the measurement.

    • leading: number

      The leading will be only used if we have not retrieved a calculated height from the browser engine.

    Returns Size

    The dimensions of the text.

  • Merges two objects together. This will merge all properties of the source object into the target object. If the current items are arrays, the items will be appended if necessary. If the current items are objects, the properties are merged, potentially overwriting the target properties with the source properties. Note that the objects need to be compatible in that sense that they need to be either array or object types (included nested objects).

    Parameters

    • target: object

      The target item to merge the source item into.

    • source: object

      The source item to merge into the target item.

    Returns void

  • Generate a new random GUID as string.

    Returns string

    The new GUID as string.

  • Sets a timeout to trigger the given callback after the given timeout in milliseconds within the editor. Server side this will be executed immediately. Once the current calling queue has been emptied.

    Parameters

    • callback: (() => void)

      The callback function to trigger.

        • (): void
        • Returns void

    • timeout: number

      The time in milliseconds to wait before triggering the callback (browser only).

    Returns number

    The timeout id which can be used to clear the timeout using ClearTimeOut.

Generated using TypeDoc