Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    A mapping of CompendiumCollection instances, one per Compendium pack

    Hierarchy (View Summary)

    Index

    Accessors

    • get contents(): V[]

      Return an Array of all the entry values in the Collection

      Returns V[]

    • get name(): string

      The Collection class name

      Returns string

    Methods

    • Find an entry in the Map using a functional condition.

      Parameters

      Returns CompendiumCollection<any> | undefined

      The value, if found, otherwise undefined

      let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
      c.get("a") === c.find(entry => entry === "A"); // true
    • Apply a function to each element of the collection

      Parameters

      Returns void

      Array#forEach

      let c = new Collection([["a", {active: false}], ["b", {active: false}], ["c", {active: false}]]);
      c.forEach(e => e.active = true);
    • Get an element from the Collection by its key.

      Parameters

      • key: string

        The key of the entry to retrieve

      • Optionaloptions: { strict?: boolean } = {}

        Additional options that affect how entries are retrieved

        • Optionalstrict?: boolean

          Throw an Error if the requested key does not exist. Default false.

      Returns CompendiumCollection<any> | undefined

      The retrieved entry value, if the key exists, otherwise undefined

      let c = new Collection([["a", "Alfred"], ["b", "Bob"], ["c", "Cynthia"]]);
      c.get("a"); // "Alfred"
      c.get("d"); // undefined
      c.get("d", {strict: true}); // throws Error
    • Get an entry from the Collection by name. Use of this method assumes that the objects stored in the collection have a "name" attribute.

      Parameters

      • name: string

        The name of the entry to retrieve

      • Optionaloptions: { strict?: boolean } = {}

        Additional options that affect how entries are retrieved

        • Optionalstrict?: boolean

          Throw an Error if the requested name does not exist. Default false.

      Returns CompendiumCollection<any> | undefined

      The retrieved entry value, if one was found, otherwise undefined

      let c = new Collection([["a", "Alfred"], ["b", "Bob"], ["c", "Cynthia"]]);
      c.getName("Alfred"); // "Alfred"
      c.getName("D"); // undefined
      c.getName("D", {strict: true}); // throws Error
    • Transform each element of the Collection into a new form, returning an Array of transformed values

      Type Parameters

      • U

      Parameters

      Returns U[]

      An Array of transformed values

    • Reduce the Collection by applying an evaluator function and accumulating entries

      Type Parameters

      • U

      Parameters

      • reducer: (
            accum: U,
            element: T,
            index: number,
            collection: Collection<string, CompendiumCollection<any>>,
        ) => U

        A reducer function applied to each entry value.

      • initial: U

        An initial value which accumulates with each iteration

      Returns U

      The accumulated result

      let c = new Collection([["a", "A"], ["b", "B"], ["c", "C"]]);
      let letters = c.reduce((s, l) => {
      return s + l;
      }, ""); // "ABC"
    • Test whether a condition is met by some entry in the Collection.

      Parameters

      • condition: (
            element: T,
            index: number,
            set: Collection<string, CompendiumCollection<any>>,
        ) => boolean

        The functional condition to test.

      Returns boolean

      Was the test condition passed by at least one entry?

    • Convert the Collection to a primitive array of its contents.

      Returns object[]

      An array of contained values

    • Parameters

      • a: any
      • b: any

      Returns any