winccoa-manager
    Preparing search index...

    Class WinccoaLangStringTool

    Stateless helpers for working with WinccoaLangString values.

    A WinccoaLangString can take three forms depending on the active WinccoaLangStringFormat — a plain string (a single language), a string[] (one entry per project language), or a WinccoaLangStringObject ({ locale: value }). These helpers encapsulate the format knowledge that belongs to the type itself, so consumers don't have to re-implement it.

    All methods are static; the class is never instantiated.

    Index

    Constructors

    Methods

    • Compares two WinccoaLangString values for structural equality, assuming both are in the same format (both plain strings, both arrays, or both objects — as they always are when read with the same options).

      The object form is compared * key-order-insensitively . Values in different formats are treated as not equal; no cross-format conversion is attempted.

      Parameters

      Returns boolean

      true if both langStrings are equal in their shared format.

      import { WinccoaLangStringTool } from 'winccoa-manager';

      WinccoaLangStringTool.equals('bar', 'bar'); // true
      WinccoaLangStringTool.equals(['a', 'b'], ['a', 'b']); // true
      WinccoaLangStringTool.equals({ en: 'x', de: 'y' }, { de: 'y', en: 'x' }); // true
      WinccoaLangStringTool.equals('x', ['x']); // false (different forms)
    • Reports whether a WinccoaLangString carries no text in any of the forms it can take: a plain string is empty when ""; an array or per-locale object is empty when it has no entries or every per-locale value is "".

      Parameters

      Returns boolean

      true if the langString holds no non-empty text.

      import { WinccoaLangStringTool } from 'winccoa-manager';

      WinccoaLangStringTool.isEmpty(''); // true
      WinccoaLangStringTool.isEmpty(['', '']); // true
      WinccoaLangStringTool.isEmpty({ en: '', de: '' }); // true
      WinccoaLangStringTool.isEmpty('x'); // false
    • Type guard that reports whether an arbitrary value is a valid WinccoaLangString — i.e. a plain string, a string[] (every element a string), or a non-null non-array object whose values are all strings (WinccoaLangStringObject).

      When a WinccoaManager is passed the check also verifies the value against the project's languages (WinccoaManager.getProjectLangs): an array must have exactly one entry per project language, and an object's keys must be exactly the project locale names. A plain string is always accepted (it carries only the active language). Without a manager only the structural shape is checked.

      Parameters

      • value: unknown

        the value to test.

      • Optionalmanager: WinccoaManager

        optional manager; when given, enables the stricter project-language-aware validation described above.

      Returns value is WinccoaLangString

      true (narrowing to WinccoaLangString) if the value is a langString — in any of its three forms (no manager), or one that also matches the project languages (manager given).

      import { WinccoaManager, WinccoaLangStringTool } from 'winccoa-manager';
      const winccoa = new WinccoaManager();

      // structural check (no manager)
      WinccoaLangStringTool.isLangString('x'); // true
      WinccoaLangStringTool.isLangString(['a', 'b']); // true
      WinccoaLangStringTool.isLangString({ en: 'a' }); // true
      WinccoaLangStringTool.isLangString(42); // false
      WinccoaLangStringTool.isLangString({ a: 1 }); // false

      // project-language-aware check (assuming project languages ['de_AT.utf8', 'en_US.utf8'])
      WinccoaLangStringTool.isLangString(['de', 'en'], winccoa); // true (2 entries)
      WinccoaLangStringTool.isLangString(['de'], winccoa); // false (wrong count)
      WinccoaLangStringTool.isLangString(
      { 'de_AT.utf8': 'x', 'en_US.utf8': 'y' },
      winccoa
      ); // true (exact keys)
      WinccoaLangStringTool.isLangString({ 'de_AT.utf8': 'x' }, winccoa); // false (missing key)