Class Mistake

Represents a language mistake, including its path in the Grammle URL and its Fields.

Hierarchy

  • Mistake

Constructors

  • Constructs a new Mistake object with a deep copy of the given Fields object.

    Parameters

    • path: string

      the relative URL path of the Mistake

    • fields: Fields

      the actual parameters of the Mistake

    Returns Mistake

Properties

fields: Fields

Holds the actual parameters of the Mistake.

path: string

The relative URL path of the Mistake. Must match Fields#id.

Methods

  • Returns a clone of this Mistake. A clone is a new Mistake object with the same properties, but a different reference.

    Returns

    a clone of this Mistake

    Returns Mistake

  • Checks whether a given Mistake is equal to this one, i.e. whether they have the same path and fields, by comparing their #toString() representations.

    Returns

    boolean whether the given Mistake is equal to this one

    Parameters

    Returns boolean

  • Returns a deep copy of the #fields.aliases Array.

    Returns

    the #fields.aliases Array or undefined if it is not set

    Returns undefined | string[]

  • Returns

    a deep copy of the #fields.alt Array or undefined if it is not set

    Returns undefined | string[]

  • Returns

    a deep copy of the #fields.confusion Array or undefined if it is not set

    Returns undefined | string[]

  • Returns string

  • Returns string

  • Returns undefined | string

  • Returns

    the #fields.name property

    Returns string

  • Returns undefined | true

  • Returns undefined | true

  • Returns string

  • Returns undefined | string

  • Returns

    the #fields.orderID property

    Returns string

  • Returns

    the #path property

    Returns string

  • Returns

    a deep copy of the #fields.related Array or undefined if it is not set

    Returns undefined | string[]

  • Returns string

  • Returns

    a deep copy of the #fields.source Array or undefined if it is not set

    Returns undefined | Source[]

  • Returns undefined | string

  • Returns

    the #fields.uid property

    Returns undefined | string

  • Returns string

  • Returns string

  • Returns

    a deep copy of the #fields.wrongs Array or undefined if it is not set

    Returns undefined | string[]

  • Generates a new fields#uid for this Mistake.

    TL;DR

    UID = unique ID of a mistake := MD5 hash of (mistake.toString() + milliseconds since 1970)
    The UID must never change, because it's used to link related mistakes together.

    Explanation

    Assume we linked rules G3 and G8 only based on their respective IDs. Further, assume we'd use the web-based edit tool to re-order several mistakes, including G3 or G8 (or both).

    Now, because G8 isn't G8 anymore – as it was re-ordered as G7 – we'd need to figure out a way to re-link it to G3.

    The problem is: We don't know whether G3 is still G3 – perhaps it had been re-ordered itself before G8 became G7.

    The only solution that is guaranteed to always work is to create truly unique IDs for each mistake at the time of creation.

    That doesn't mean it's impossible to link mistakes based on their IDs, but this would be way too complicated to implement, maintain and refactor.

    Thus, we're using cryptographic hashes of the mistake objects plus the respective current date. Obviously, MD5 is outdated, but since our use case is not sensitive at all, that's perfectly ok, or rather it's not worth wasting significantly more space just for SHA512.

    Returns

    true if the UID was successfully set

    Throws

    IllegalDiscrepancyError if the UID is already set

    Returns true | IllegalDiscrepancyError

  • Sets new categories for this Mistake and deduplicates them, but keeps the previous first category and therefore does NOT update the #path, #fields.id, #fields.orderID or #fields.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 by calling Fields#setAliases and updates the #path accordingly if necessary.

    Returns

    true if the aliases were valid and set successfully

    Throws

    IllegalArgumentError If the given aliases didn't meet the requirements of Fields#setAliases

    Parameters

    • aliases: string[]

      the new aliases for this Mistake

    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

  • Parameters

    • includeIn404: true

    Returns void

  • Parameters

    • featured: true

    Returns void

  • Parameters

    • note: string

    Returns void

  • Sets a new orderID for this Mistake and updates the #path, #fields.id and #fields.aliases[0] accordingly.

    Returns

    true if the orderID was set successfully, false otherwise

    Throws

    if the orderID does not match the pattern <category[0]><padding zeros><UInt> with number.length == 4

    Parameters

    • orderID: string

      the new orderID for this Mistake

    Returns true | IllegalArgumentError

  • Parameters

    • related: string[]

    Returns void

  • Parameters

    • slug: string

    Returns void

  • Parameters

    Returns void

  • Parameters

    • status: string

    Returns void

  • Parameters

    • wrong: string

    Returns void

  • Parameters

    • wrongex: string

    Returns void

  • Parameters

    • wrongs: string[]

    Returns void

  • Returns

    the Mistake as a raw Object

    Returns Object

  • Returns

    this Mistake as a JSON string.

    Returns string

  • Updates a specific item in a given string Array at a given index to a new given value. This method exists to avoid having to check for undefined every time.

    Returns

    the updated Array

    Parameters

    • array: undefined | string[]

      the Array to update

    • index: number

      the index of the item to update

    • newValue: string

      the new value for the item at the given index

    Returns string[]

  • Checks whether this Mistake is valid by calling validate on this.

    Returns

    boolean whether this Mistake is valid

    Returns boolean

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

    Returns

    the new Mistake object

    Throws

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

    Parameters

    • inputObject: Object

      the raw object to create the Mistake from

    Returns IllegalArgumentError | Mistake

Generated using TypeDoc