Class Item

Constructors

  • Parameters

    • item: ItemInput

      The item in JSON format.

    Returns Item

    If the id is not a QString.

    const item = new Item({
    type: "item",
    id: "q2",
    labels: {},
    descriptions: {},
    aliases: {},
    claims: {},
    sitelinks: {}
    })

Properties

aliases: Alias[]

The aliases of the item.

descriptions: Description[]

The descriptions of the item.

id: undefined | `Q${number}`

The Q-id of the item.

labels: Label[]

The labels of the item.

lastrevid: undefined | number

The id of the last revision of the item.

modified: undefined | Date

The date of last modification.

ns: undefined | number

The namespace the item is located in.

pageid: undefined | number

The id used by Wikibase.

sitelinks: SiteLink[]

The sitelinks of the item.

statements: Statement[]

The statements of the item.

title: undefined | string

The title of the item. Usually the Q-id of the item.

type: "item"

The type of the entity. Always 'item'.

Accessors

  • get internalID(): string
  • Creates a unique id for the Item.

    Returns string

    The id.

Methods

  • Adds a statement to the item.

    Parameters

    Returns void

    const statement = Statement.fromSnak(URLSnak.fromURL("p1", "https://www.wikidata.org"))
    item.addStatement(statement)
  • Finds the difference between two items.

    Parameters

    • other: Item

      The other item.

    Returns Changes[]

    The changes between the two items.

    const itemA = Item.fromNothing()
    const itemB = Item.fromNothing()
    itemA.addLabel(new Label({language: "nl", value: "Douglas Adams"}))

    const changes = itemA.diff(itemB)
    console.log(changes)
  • Checks if two items are equal.

    Parameters

    • other: Item

      The other item.

    Returns boolean

    True if the items are equal.

    const itemA = Item.fromNothing()
    const itemB = Item.fromNothing()

    if(itemA.equals(itemB)){
    alert('the items are the same');
    }
  • Tries to find a label in the requested language. If the default for all languages (mul) label is present, it will return that one. If none can be found, it will return undefined.

    Parameters

    • language: string

      The language of the label.

    Returns undefined | Label

    The label if it found one or undefined.

    const label = item.findLabel("nl")
    console.log(label.value)
    // Douglas Adams
  • Removes a statement from the item.

    Parameters

    • statement: Statement

      The statement to remove.

    Returns void

    removeStatements

    const statement = item.statements[0]
    item.removeStatement(statement)
  • Removes multiple statements from the item.

    Parameters

    • statements: Statement[]

      The statements to remove.

    Returns void

    removeStatement

    const statements = item.statements
    item.removeStatements(statements)
  • Stringifies the Item into the same JSON format as the API.

    Returns Item

    The item as JSON.

    const json = item.toJSON();
    
  • Generates a new empty item object.

    Returns Item

    Returns an empty item.

    const newItem = Item.fromNothing()