Utility functions

function O.deduplicateArrayOfRefs(array)

Given an array-like object containing Ref or StoreObject objects, return a de-duplicated list of Ref objects.

This function guarantees the following properties. You must not rely on any other behaviour.

  • Order is preserved.
  • If a Ref value appears more than once in the input array, the output array will contain a single Ref of that value in the position equivalent to the lowest index.
  • The returned array will only contain Ref objects.
  • If an entry in the input array is a StoreObject, the returned array will return the corresponding Ref.
  • undefined and null values in the input array are ignored, and therefore will not be included in the output array.
  • While the array may contain the exact Ref objects which appeared in the input array, only equivalence is guaranteed.
  • A new array is returned, and the caller may modify that array.
  • If array is undefined or null, an empty array is returned.
  • An exception will be thrown if the input array contains an object of an unexpected type.

function O.interpolateString(string, inserts)

Replace occurrences of {property} within string with the corresponding property from inserts.

  let s = O.interpolateString("Hello {name}, it's {day}.", {
    name: "world",
    day: "Tuesday"
  });
  // s === "Hello world, it's Tuesday"

This is often useful for translating text in plugins.

function O.getPluginInstance(pluginName)

Returns the Plugin object for the plugin named pluginName. Throws an exception if the plugin is not installed.

You should never need to use this function, unless you’re writing a very special plugin. Use the platform’s inter-plugin communication APIs unless you know you have a very good reason why they won’t work.