@grafctory/core - v0.15.0
    Preparing search index...

    Function localised

    • Creates a function that transforms every text of a Localised language map.

      The function keeps the shape of the map it is given. A language carrying one text gets one text back, and a language carrying several gets several back. Texts the mapper empties are dropped, and so are languages left with no text.

      Parameters

      • mapper: (value: string) => string

        The transformation applied to every text of a map, for example a clean-up of stray whitespace

      Returns {
          (localised: Localised<string>): Localised<string>;
          (localised: Localised<readonly string[]>): Localised<readonly string[]>;
      }

      A function applying mapper to every text of the language maps it is given

      import { localised } from "@grafctory/core/language";

      const upper = localised(value => value.toUpperCase());

      upper({ en: "name", it: "nome" }); // { en: "NAME", it: "NOME" }
      upper({ en: ["one", "two"] }); // { en: ["ONE", "TWO"] }