Skip to content

Commit e5bed00

Browse files
committed
readme and docs: update
1 parent 806170d commit e5bed00

11 files changed

+211
-246
lines changed

README.md

+29-26
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ This project received a [Wikimedia Project Grant](https://meta.wikimedia.org/wik
3131
- [Changelog](#changelog)
3232
- [Dependencies](#dependencies)
3333
- [Install](#install)
34-
- [as a module](#as-a-module)
34+
- [as an ES module](#as-an-es-module)
35+
- [as an CommonJS module](#as-an-commonjs-module)
3536
- [download pre-bundled files](#download-pre-bundled-files)
3637
- [Features](#features)
3738
- [Wikibase API](#wikibase-api)
@@ -48,27 +49,28 @@ This project received a [Wikimedia Project Grant](https://meta.wikimedia.org/wik
4849
See [CHANGELOG.md](CHANGELOG.md) for version info
4950

5051
## Dependencies
51-
This module uses [JavaScript ES6](https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_-_ECMAScript_2015), which means NodeJS `>= v6.4.0` or not too outdated web browsers.
52+
* A somewhat modern JS runtime: NodeJS `>= v12.0.0` or not too outdated web browsers (see [`Object.fromEntries` browser compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries))
5253

53-
For older version, you can use ES5 [bundles](#download-pre-bundled-files).
54+
For older JS runtimes, you can use [ES5 bundles from `wikibase-sdk <= v8`](https://github.com/maxlath/wikibase-sdk/tree/v8.1.1#download-pre-bundled-files).
5455

5556
## Install
56-
### as a module
57-
Install via npm to be able to use the module with `require` (CommonJS) or `import` (ES6 Modules)
57+
### as an ES module
58+
Install via npm to be able to use the `import` the module.
5859
```sh
5960
npm install wikibase-sdk
6061
```
62+
6163
Then in your javascript:
6264
```js
63-
const WBK = require('wikibase-sdk')
65+
import { WBK } from 'wikibase-sdk'
6466
const wbk = WBK({
6567
instance: 'https://my-wikibase-instan.se',
6668
sparqlEndpoint: 'https://query.my-wikibase-instan.se/sparql' // Required to use `sparqlQuery` and `getReverseClaims` functions, optional otherwise
6769
})
6870
```
6971
The `wdk` object of previous versions of this documentation - from the time this module was bound to wikidata.org only - thus corresponds to the following:
7072
```js
71-
const WBK = require('wikibase-sdk')
73+
import { WBK } from 'wikibase-sdk'
7274
const wdk = WBK({
7375
instance: 'https://www.wikidata.org',
7476
sparqlEndpoint: 'https://query.wikidata.org/sparql'
@@ -77,38 +79,41 @@ const wdk = WBK({
7779
For convenience, and for the sake of retro-compatibility, that same `wdk` object can be obtain directly from the `wikidata-sdk` package:
7880
```js
7981
// After having run `npm install wikidata-sdk`
80-
const wdk = require('wikidata-sdk')
82+
import { wdk } from 'wikidata-sdk'
8183
```
8284
and instance-independant helper functions are directly available from the module root:
8385
```js
84-
const { simplify, parse, isEntityId, isPropertyId, ... } = require('wikibase-sdk')
86+
import { simplify, parse, isEntityId, isPropertyId, ... } from 'wikibase-sdk'
8587
```
8688

8789
By default `wikibase-sdk` assumes that your Wikibase instance has [`$wgScriptPath`](https://www.mediawiki.org/wiki/Manual:$wgScriptPath) set to `/w`, but if that's not the case, you can set it by passing a `wgScriptPath` parameter:
8890
```js
89-
const wbk = require('wikibase-sdk')({
91+
import { WBK } from 'wikibase-sdk'
92+
const wbk = WBK({
9093
instance: 'https://my-wikibase-instan.se',
9194
wgScriptPath: '/some_custom_script_path'
9295
})
9396
```
9497

95-
### download pre-bundled files
96-
If you just want to import the lib from an HTML file and don't have a setup that can import with CommonJS or ES6 Modules, you can simply download those pre-bundled files:
98+
### as an CommonJS module
99+
Importing with CommonJS `require` is not supported anymore in version `>= v9.0.0`, but can still be done by installing an older version:
97100
```sh
98-
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/dist/dist/wikibase-sdk.js
99-
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/dist/dist/wikidata-sdk.js
100-
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/dist/dist/wikibase-sdk.min.js
101-
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/dist/dist/wikidata-sdk.min.js
101+
npm install wikibase-sdk@v8
102102
```
103103

104-
then you can import it in your html:
105-
```html
106-
<script src="/path/to/wikibase-sdk.js"></script>
107-
<script>console.log('can access WBK', WBK)</script>
108-
<script src="/path/to/wikidata-sdk.js"></script>
109-
<script>console.log('can access wdk, the wikidata.org bound product of WBK', wdk)</script>
104+
See the [corresponding version documentation](https://github.com/maxlath/wikibase-sdk/tree/v8.1.1#as-a-module)
105+
106+
### download pre-bundled files
107+
Pre-bundled files is not supported anymore in version `>= v9.0.0`, but can still be done by pre-bundled files from older versions:
108+
```sh
109+
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/v8.1.1/dist/wikibase-sdk.js
110+
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/v8.1.1/dist/wikidata-sdk.js
111+
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/v8.1.1/dist/wikibase-sdk.min.js
112+
wget https://raw.githubusercontent.com/maxlath/wikibase-sdk/v8.1.1/dist/wikidata-sdk.min.js
110113
```
111114

115+
See the [corresponding version documentation](https://github.com/maxlath/wikibase-sdk/tree/v8.1.1#download-pre-bundled-files)
116+
112117
## Features
113118
### Wikibase API
114119
A set of functions to make **read** queries to a Wikibase instance API (see [Wikidata API documentation](https://www.wikidata.org/w/api.php)).
@@ -143,18 +148,16 @@ This library had for primary purpose to serve the needs of the [inventaire](http
143148

144149
**Design constraints**
145150

146-
* `wikibase-sdk` should stay "small" and dependency-free, so that a web application can include it in its bundle without paying a too high cost for it. A consequence is that the lib generates URLs where other libs would integrate doing the request and parsing it's response. But that actually feels quite right to do this way: simply generating the URLs let's users free to handle requests as they like (with callbacks, promises, async/await, whatever!)
151+
* `wikibase-sdk` should stay "small" and dependency-free, so that a web application can include it in its bundle without paying a too high cost for it. A consequence is that the lib generates URLs where other libs would integrate doing the request and parsing it's response. But that actually feels quite right to do this way: simply generating the URLs let's users free to handle requests as they like (with callbacks, promises, async/await, custom request agent, whatever!)
147152
* Therefore, it should focus on providing basic, general helper functions most application working with a Wikibase instance would need.
148153
* Write operations should go into [wikibase-edit](https://github.com/maxlath/wikibase-edit) as it involves working with Wikibase credentials/tokens.
149-
* General command-line interface tools should go to [wikibase-cli](https://github.com/maxlath/wikibase-cli), very specific ones — [`wikidata-filter`, `import-wikidata-dump-to-couchdb`, and alikes](#see-also) — should get their own modules.
154+
* General command-line interface tools should go to [wikibase-cli](https://github.com/maxlath/wikibase-cli), very specific ones — [`wikibase-dump-filter` and alikes](#see-also) — should get their own modules.
150155

151156
## See Also
152157
* [wikibase-edit](https://github.com/maxlath/wikibase-edit): Edit a Wikibase instance from NodeJS
153158
* [wikibase-cli](https://github.com/maxlath/wikibase-cli): The command-line interface to Wikibase instances
154159
* [wikibase-dump-filter](https://npmjs.com/package/wikibase-dump-filter): Filter and format a newline-delimited JSON stream of Wikibase entities
155-
* [wikidata-subset-search-engine](https://github.com/inventaire/entities-search-engine/tree/wikidata-subset-search-engine): Tools to setup an ElasticSearch instance fed with subsets of Wikidata
156160
* [wikidata-taxonomy](https://github.com/nichtich/wikidata-taxonomy): Command-line tool to extract taxonomies from Wikidata
157-
* [import-wikidata-dump-to-couchdb](https://github.com/maxlath/import-wikidata-dump-to-couchdb): Import a subset or a full Wikidata dump into a CouchDB database
158161
* [Other Wikidata external tools](https://www.wikidata.org/wiki/Wikidata:Tools/External_tools)
159162

160163
## You may also like

0 commit comments

Comments
 (0)