Class Item

Constructors

  • Parameters

    • item: ItemInput

      the item in json format

    Returns Item

    Throws

    if the id is not a QString

    Example

    const item = new Item({
    type: "item",
    id: "q2",

    labels: {},
    descriptions: {},
    aliases: {},

    claims: {},
    sitelinks: {}
    })

Properties

_internalID: string = ''

a place to store the internalID so that it does not change if the contents of the object changes

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 modified

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
  • create a unique id for the Item

    Returns string

    the id

Methods

  • adds a statement to the item

    Parameters

    Returns void

    Example

    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

    Example

    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)
  • this function checks if two items are equal

    Parameters

    • other: Item

      the other item

    Returns boolean

    true if the items are equal

    Example

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

    if(itemA.equals(itemB)){
    alert('the items are the same');
    }
  • tries to find a label int the requested language. if non can be found, it will return undefined

    Parameters

    • language: string

      the language of the label

    Returns undefined | Label

    the labelA label if it found one or undefined

    Example

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

    Parameters

    Returns void

    See

    removeStatements

    Example

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

    Parameters

    • statements: Statement[]

      the statements to remove

    Returns void

    See

    removeStatement

    Example

    const statements = item.statements
    item.removeStatements(statements)
  • stringifies the Item into the same json format as the api

    Returns Item

    the item as json

    Example

    const json = item.toJson();
    
  • generates a new empty item object

    Returns Item

    returns a empty item

    Example

    const newItem = Item.fromNothing()
    

Generated using TypeDoc