Class Fields

Stores the actual parameters of a Mistake.

Hierarchy

  • Fields

Constructors

  • Creates a new Fields object. Updates the #orderID and #name accordingly to the given ID.

    Parameters

    • id: GrammleID

      the identification of the Mistake

    • arten: Kind

      the kind of mistake

    • kategorien: CategoryNames[]

      the categories the mistake belongs to with the main category first

    Returns Fields

Properties

aliases?: string[]

Relative URL paths that redirect to the #slug. These redirections are created by Hugo. The first one must be the #id, the second one must be the #uid.

alt?: string[]

A short list of correct phrases that are synonyms of the wrong phrase but do not contain the mistake, thus helping to avoid the mistake.

arten: Kind = Kind.fehler

The kind of mistake; each mistake is of exactly one kind.

confusion?: string[]

A short list of correct phrases that seem similar to the wrong phrase but mean something entirely different, thus creating confusion.

correct: string = ""

The correct form of the mistake, usually displayed like a headline, meaning that it should be rather short (not a whole sentence).

correctex: string = ""

A correct example of the mistake, usually displayed as a small paragraph. The example should be a whole sentence.

explanation?: string

A short explanation of the mistake. It's usually displayed as a small paragraph and should be a few sentences long.

id: string = ""

The human-readable identification of the mistake. Must be in the format <mainCategory[0]><UInt>, such as b3 or s10. Can be validated with validateID.

includeIn404?: true

Whether the mistake should be included in the "404: not found" error page.

isFeatured?: true

Whether the mistake is suitable to be used for promotional purposes.

kategorien: CategoryNames[]

All categories the mistake belongs to. The first category is the main category.

name: string = ""

The name of the mistake. Must be in the format Grammle-<mainCategory[0]><UInt>, such as Grammle-B3 or Grammle-S10. Can be validated with validateName.

note?: string

A short note about the mistake that displays additional information. It should be rather short (not a whole paragraph) and may be left out if there's nothing to add.

orderID: string = ""

The #id with padding zeros. Must be in the format <mainCategory[0]><UInt4>, such as b0003 or s0010. Can be validated with validateOrderID.

related?: string[]

UIDs of Mistakes that are similar or otherwise related to this one.

slug: string = ""

The relative URL path of the mistake. This is used by Hugo to create the URL of the mistake.

source?: Source[]

Third-party sources that provide additional information about the mistake and that are used to verify the correctness of the rule. Each Mistake must have at least one source. Multiple different entries of the same source are allowed but should be avoided if possible.

status?: string

The last time the mistake was updated.

uid?: string

The unique identification of the mistake. Must be an MD5 hash of 32 hexadecimal characters. Can be validated with validateUID.

wrong: string = ""

The wrong form of the mistake, usually displayed like a headline, meaning that it should be rather short (not a whole sentence).

wrongex: string = ""

A wrong example of the mistake, usually displayed as a small paragraph. The example should be a whole sentence.

wrongs?: string[]

Regular expressions that match the wrong form of the mistake. They must not match any correct phrases.

Methods

  • Returns

    a deep copy of this Fields object

    Returns Fields

  • Removes duplicate categories from the #kategorien array. Suggested by ChatGPT.

    Returns

    true if the categories were de-duplicated successfully

    Returns true

  • Returns undefined | string[]

  • Returns undefined | string[]

  • Returns Kind

  • Returns undefined | string[]

  • Returns string

  • Returns string

  • Returns undefined | string

  • Returns the identification (ID) of the mistake this Fields object represents as a GrammleID (even though it is locally stored in the form of a string).

    Returns

    the mistake's ID

    Returns GrammleID

  • Returns string

  • Returns undefined | true

  • Returns undefined | true

  • Returns string

  • Returns undefined | string

  • Returns string

  • Returns undefined | string[]

  • Returns string

  • Returns undefined | Source[]

  • Returns undefined | string

  • Returns undefined | string

  • Returns string

  • Returns string

  • Returns undefined | string[]

  • Removes all additional categories from the #kategorien array and keeps the first category, by calling #setAdditionalCategories with an empty array.

    Returns

    true if the categories were removed successfully

    Returns true

  • Sets a new #kategorien array and removes duplicate categories, but keeps the previous first category and therefore does NOT update #id, #orderID or #name accordingly.

    Info: If the given array is empty, all additional categories are removed, but the first category is kept.

    Returns

    true if the categories were set successfully

    Parameters

    Returns true

  • Sets new fields#aliases.

    § 1: First alias is valid ID

    If the first alias is a valid ID, then the second alias (if it exists) is required to be a valid UID.
    A second alias is not required to exist, though (i.e. aliases.length may be 1).
    The

    are updated accordingly if that requirement is met. Otherwise, an IllegalArgumentError is returned (and the aforementioned properties are not updated).

    § 2: Second alias is valid UID

    If the second alias is a valid UID, then the first alias is required to be a valid ID.
    If that requirement is met, the #uid is updated accordingly. Otherwise, an IllegalArgumentError is returned (and the #uid is not updated).

    Corollary

    In other words, we enforce that:

    • aliases[0] is valid ID ⇒ aliases.length == 1 || aliases[1] is valid UID
    • aliases[1] is valid UID ⇒ aliases[0] is valid ID
    • aliases[1] exists ⇒ (aliases[0] is valid ID ⇔ aliases[1] is valid UID)

    § 3: If the first two aliases are valid ID and UID

    If the first alias is a valid ID and the second alias is a valid UID, then the new aliases array overrides the current one, and

    are updated accordingly.
    Important: The callee is responsible for ensuring that aliases[1] is actually the correct fields#uid for the Mistake, not just some UID.

    § 4: First two aliases are not valid ID and UID

    If the first alias is not a valid ID and the second alias is not a valid UID, then the new aliases array is appended to the current one, instead of overriding it. The #id and #uid are not updated.
    However, if the current #uid is undefined, then there is no option to set #aliases[2] to the UID, so an IllegalArgumentError is returned.

    Returns

    true if the aliases were set successfully

    Throws

    if the aliases are not valid, as described above

    Parameters

    • aliases: string[]

      the new aliases

    Returns true | IllegalArgumentError

  • Parameters

    • alt: string[]

    Returns void

  • Parameters

    Returns void

  • Parameters

    • confusion: string[]

    Returns void

  • Parameters

    • correct: string

    Returns void

  • Parameters

    • correctex: string

    Returns void

  • Parameters

    • explanation: string

    Returns void

  • Sets a new ID and updates the #orderID, #name, #kategorien and #aliases accordingly.

    Returns

    true if the ID was set successfully

    Parameters

    Returns true

  • Sets the 404 status of this Fields object. In case of false, the 404 status is removed, i.e. #includeIn404 is set to undefined.

    Parameters

    • notFoundPage: boolean

      true if this Fields object shall be displayed on the 404 page, false otherwise

    Returns void

  • Sets the isFeatured status of this Fields object. In case of false, the isFeatured status is removed, i.e. #isFeatured is set to undefined.

    Parameters

    • featured: boolean

      true if this Fields object shall be isFeatured, false otherwise

    Returns void

  • Sets a new name and updates the #id, #orderID and #aliases accordingly, by calling #setID(GrammleID). The name must be in the format Grammle-<ID number>.

    Returns

    true if the name was set successfully

    Throws

    if the name is not in the format Grammle-<ID number>

    Parameters

    • name: string

      the new mistake name

    Returns true | IllegalArgumentError

  • Parameters

    • note: string

    Returns void

  • Sets a new order ID and updates the #id, #name and #aliases accordingly, by calling #setID(GrammleID). The order ID must be in the format .

    Returns

    true if the order ID was set successfully

    Throws

    if the order ID is not in the format

    Parameters

    • orderID: string

      the new order ID

    Returns true | IllegalArgumentError

  • Parameters

    • related: string[]

    Returns void

  • Parameters

    • slug: string

    Returns void

  • Parameters

    Returns void

  • Parameters

    • status: string

    Returns void

  • Sets a new UID and updates the #aliases accordingly. The UID must be an MD5 string of 32 characters.

    Returns

    true if the UID was set successfully

    Throws

    if the UID is not an MD5 string of 32 characters

    Parameters

    • uid: string

      the new UID

    Returns true | IllegalArgumentError

  • Parameters

    • wrong: string

    Returns void

  • Parameters

    • wrongex: string

    Returns void

  • Parameters

    • wrongs: string[]

    Returns void

  • Returns

    a deep copy of the Fields object as a raw Object

    Returns Object

  • Updates the #aliases with the given ID and UID as the first and second item respectively. The UID must be a valid MD5 string of 32 characters. At least one of the parameters must be defined.

    Important:

    • If the ID is not given, the current ID is used.
    • If the UID is not given, the current UID is used (if defined).
    Important: The callee is trusted to make sure that

    Returns

    true if the aliases were updated successfully

    Throws

    if the UID is not an MD5 string of 32 characters

    Parameters

    • Optional id: GrammleID

      the first alias, i.e. #aliases[0]; must be the ID (this is NOT checked)

    • Optional uid: string

      the second alias, i.e. #aliases[1]; must be the UID (this is NOT checked)

    Returns true | IllegalArgumentError

  • Sets a new main category by updating the #kategorien accordingly.

    Returns

    true: the mistake's main category has been updated to the given category, false: the mistake's main category is already the given category

    Parameters

    Returns boolean

  • Creates a new Fields object from a given raw Object.

    Returns

    the new Fields object

    Throws

    if the given parameter is not an Object or if it does not have a required property.

    Parameters

    • object: Object

      the raw Object to create the Fields from

    Returns IllegalArgumentError | Fields

  • Checks whether the given Fields object is valid.

    Conditions:

    Returns

    true if the given Fields object is valid, false otherwise

    Parameters

    Returns boolean

  • Validates that the given ID, name and orderID are equivalent and that the given category is the ID's category.

    Returns

    true if the given ID, name and orderID are equivalent and if the given category is the ID's category; false otherwise.

    Throws

    IllegalArgumentError if the given ID, name or orderID are not valid.

    Parameters

    • id: string

      the ID to validate

    • name: string

      the ID name to validate

    • orderID: string

      the orderID to validate

    • Optional category: string

      the category to validate

    Returns boolean | IllegalArgumentError

  • Checks whether a given string is a valid regular expression.

    Returns

    true if the given string is a valid regular expression, false otherwise

    Parameters

    • regex: string

      the string to check

    Returns boolean

Generated using TypeDoc