How to use the wikidata-sdk.isItemId function in wikidata-sdk

To help you get started, we’ve selected a few wikidata-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-edit / lib / reference / validate_reference_args.js View on Github external
const validateReferenceArgs = (guid, property, reference) => {
  if (!_.isNonEmptyString(guid)) {
    throw error_.new('missing guid', 400, guid)
  }

  const [ entity, rest ] = guid.split('$')
  if (!wdk.isItemId(entity)) {
    throw error_.new('invalid guid', 400, guid)
  }

  if (!(_.isNonEmptyString(rest) && /[\w-]{36}/.test(rest))) {
    throw error_.new('invalid guid', 400, guid)
  }

  if (!_.isNonEmptyString(property)) {
    throw error_.new('missing property', 400, property)
  }

  validate.property(property)
  validate.referenceValue(property, reference)
}
github maxlath / wikidata-filter / lib / validate_arguments.js View on Github external
const validateClaim = claim => {
  const [ P, Q ] = claim.split(':')
  if (!(isPropertyId(P))) throw new Error(`invalid claim property: ${P}`)
  if (Q) {
    const Qs = Q.split(',')
    for (let q of Qs) {
      if (!(isItemId(q))) throw new Error(`invalid claim value: ${q}`)
    }
  }
}