How to use the wikibase-sdk.isEntityId function in wikibase-sdk

To help you get started, we’ve selected a few wikibase-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maxlath / wikibase-cli / lib / format_statement_element_value.js View on Github external
subject: value => {
    if (isEntityId(value)) {
      return `wd:${value}`
    } else {
      errors_.exit(`invalid subject: ${value}`)
    }
  },
  property: value => {
github maxlath / wikibase-cli / lib / convert_ids.js View on Github external
module.exports = (property, ids) => {
  const useWdIdsAsKeys = isEntityId(ids[0])
  ids = uniq(ids)
  if (ids.length === 0) return output({})
  const sparqlBuilder = useWdIdsAsKeys ? fromWdIds : fromExternalIds
  const sparqlRequests = chunk(ids, 100).map(sparqlBuilder(property))
  const results = initResultsObj(ids)

  getResultsSequentially(sparqlRequests, results, useWdIdsAsKeys)
  .then(output)
  .catch(errors_.exit)
}
github maxlath / wikibase-cli / lib / tolerant_id_parser.js View on Github external
module.exports = input => {
  const match = input.match(/(Q|P)\d+/)

  if (match) {
    const id = match[0]
    if (isEntityId(id)) return id
  }

  if (isNumericId(input)) return `Q${input}`

  throw errors_.new('invalid id', input)
}
github maxlath / wikibase-edit / lib / validate.js View on Github external
entity: entity => {
    if (!isEntityId(entity)) {
      throw error_.new('invalid entity', { entity })
    }
  },
  property: property => {
github maxlath / wikibase-edit / lib / entity / validate_and_format_data.js View on Github external
module.exports = data => {
  const params = {}
  const { id, clear, labels, aliases, descriptions, claims, sitelinks, summary } = data

  if (id === 'create') {
    params['new'] = 'item'
  } else if (isEntityId(id)) {
    params.id = id
  } else {
    throw error_.new('invalid entity id', 400, id)
  }

  if (_.isNonEmptyString(summary)) params.summary = summary

  params.data = {}
  if (labels) {
    params.data.labels = format.values('label', labels)
  }
  if (aliases) {
    params.data.aliases = format.values('alias', aliases)
  }
  if (descriptions) {
    params.data.descriptions = format.values('description', descriptions)
github maxlath / wikibase-edit / lib / entity / edit.js View on Github external
if (type && type !== 'property' && type !== 'item') {
    throw error_.new('invalid entity type', { type })
  }

  if (create) {
    if (type === 'property') {
      if (!datatype) throw error_.new('missing property datatype', { datatype })
      params.new = 'property'
      params.data.datatype = datatype
    } else {
      if (datatype) {
        throw error_.new("an item can't have a datatype", { datatype })
      }
      params.new = 'item'
    }
  } else if (isEntityId(id)) {
    params.id = id
  } else {
    throw error_.new('invalid entity id', { id })
  }

  const { labels, aliases, descriptions, claims, sitelinks, summary } = data

  if (_.isNonEmptyString(summary)) params.summary = summary

  if (labels) {
    params.data.labels = format.values('label', labels)
  }
  if (aliases) {
    params.data.aliases = format.values('alias', aliases)
  }
  if (descriptions) {
github maxlath / wikibase-cli / lib / get_claims_texts.js View on Github external
const formatValue = labels => value => {
  return isEntityId(value) ? formatEntity(labels[value], value) : value
}
github maxlath / wikibase-edit / lib / resolve_title.js View on Github external
.then(prefixesMap => {
    if (!isEntityId(title)) return
    const idFirstLetter = title[0]
    const prefix = prefixesMap[idFirstLetter]
    return prefix === '' ? title : `${prefix}:${title}`
  })
}