Skip to content

Commit

Permalink
Partially revert "helpers: removing helpers that were only needed to …
Browse files Browse the repository at this point in the history
…work with the now-offline WDQ service"

to bring back wdk.isNumericId, and wdk.getNumericId as they are needed, at least by the wikidata-edit module

This partially reverts commit df4301a.
  • Loading branch information
maxlath committed Mar 31, 2017
1 parent 9223b6c commit 2b5020e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/helpers/helpers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const toDateObject = require('./wikidata_time_to_date_object')

const helpers = {}
helpers.isNumericId = (id) => /^[0-9]+$/.test(id)
helpers.isEntityId = (id) => /^(Q|P)[0-9]+$/.test(id)
helpers.isItemId = (id) => /^Q[0-9]+$/.test(id)
helpers.isPropertyId = (id) => /^P[0-9]+$/.test(id)

helpers.getNumericId = function (id) {
if (!(helpers.isEntityId(id))) throw new Error(`invalid wikidata id: ${id}`)
return id.replace(/Q|P/, '')
}

helpers.wikidataTimeToDateObject = toDateObject

// Try to parse the date or return the input
Expand Down
2 changes: 2 additions & 0 deletions test/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('general', function () {
wdk.isEntityId.should.be.a.Function()
wdk.isItemId.should.be.a.Function()
wdk.isPropertyId.should.be.a.Function()
wdk.isNumericId.should.be.a.Function()
wdk.getNumericId.should.be.a.Function()
wdk.wikidataTimeToDateObject.should.be.a.Function()
wdk.wikidataTimeToEpochTime.should.be.a.Function()
wdk.wikidataTimeToISOString.should.be.a.Function()
Expand Down

0 comments on commit 2b5020e

Please sign in to comment.