Skip to content

Commit d12f665

Browse files
authored
Merge pull request #1192 from danielpeintner/issue-1187
docs: align import/require style in READMEs
2 parents 3af996d + fd3f489 commit d12f665

5 files changed

Lines changed: 32 additions & 40 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ With node-wot you can create server-side Things, in WoT jargon we call this oper
142142

143143
```JavaScript
144144
// Required steps to create a servient for creating a thing
145-
const Servient = require('@node-wot/core').Servient;
146-
const HttpServer = require('@node-wot/binding-http').HttpServer;
145+
const { Servient } = require("@node-wot/core");
146+
const { HttpServer } = require("@node-wot/binding-http");
147147

148148
const servient = new Servient();
149149
servient.addServer(new HttpServer());
@@ -181,7 +181,7 @@ Now supposing you want to interact with the device, you have to consume its Thin
181181
// client.js
182182
// Required steps to create a servient for a client
183183
const { Servient } = require("@node-wot/core");
184-
const { HttpClientFactory } = require('@node-wot/binding-http');
184+
const { HttpClientFactory } = require("@node-wot/binding-http");
185185

186186
const servient = new Servient();
187187
servient.addClientFactory(new HttpClientFactory(null));
@@ -337,8 +337,7 @@ export interface ContentCodec {
337337
Finally you can add to your servient the new codec as follows:
338338

339339
```JavaScript
340-
const ContentSerdes = require('@node-wot/core').ContentSerdes
341-
const JsonCodec = require('@node-wot/core').JsonCodec
340+
const { ContentSerdes, JsonCodec } = require("@node-wot/core");
342341

343342
// e.g., assign built-in codec for *new* contentType
344343
const cs = ContentSerdes.get();

packages/binding-file/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ The example tries to load an internal TestThing TD and reads the `fileContent` p
2121
`node example1.js`
2222

2323
```js
24-
// example.js1
25-
const Servient = require("@node-wot/core").Servient;
26-
const FileClientFactory = require("@node-wot/binding-file").FileClientFactory;
24+
// example1.js
25+
const { Servient } = require("@node-wot/core");
26+
const { FileClientFactory } = require("@node-wot/binding-file");
2727

2828
// create Servient and add File binding
2929
const servient = new Servient();
@@ -81,8 +81,8 @@ The example tries to load a locally stored TestThing TD and reads the `fileConte
8181

8282
```js
8383
// example2.js
84-
const Servient = require("@node-wot/core").Servient;
85-
const FileClientFactory = require("@node-wot/binding-file").FileClientFactory;
84+
const { Servient } = require("@node-wot/core");
85+
const { FileClientFactory } = require("@node-wot/binding-file");
8686

8787
// create Servient and add File binding
8888
const servient = new Servient();

packages/binding-http/README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ The Thing Description is located under the following uri <http://plugfest.thingw
2626

2727
```js
2828
// example-client.js
29-
Servient = require("@node-wot/core").Servient;
30-
HttpClientFactory = require("@node-wot/binding-http").HttpClientFactory;
29+
const { Servient } = require("@node-wot/core");
30+
const { HttpClientFactory } = require("@node-wot/binding-http");
3131

3232
// create Servient and add HTTP binding
33-
let servient = new Servient();
33+
const servient = new Servient();
3434
servient.addClientFactory(new HttpClientFactory(null));
3535

3636
servient
@@ -60,13 +60,11 @@ The server example produces a thing that allows for setting a property `count`.
6060

6161
```js
6262
// example-server.js
63-
Servient = require("@node-wot/core").Servient;
64-
HttpServer = require("@node-wot/binding-http").HttpServer;
65-
66-
Helpers = require("@node-wot/core").Helpers;
63+
const { Servient } = require("@node-wot/core");
64+
const { HttpServer } = require("@node-wot/binding-http");
6765

6866
// create Servient add HTTP binding with port configuration
69-
let servient = new Servient();
67+
const servient = new Servient();
7068
servient.addServer(
7169
new HttpServer({
7270
port: 8081, // (default 8080)
@@ -110,21 +108,19 @@ The _secure_ server example shows how to add credentials and how to set up HTTPS
110108

111109
```js
112110
// example-server-secure.js
113-
Servient = require("@node-wot/core").Servient;
114-
HttpServer = require("@node-wot/binding-http").HttpServer;
115-
116-
Helpers = require("@node-wot/core").Helpers;
111+
const { Servient } = require("@node-wot/core");
112+
const { HttpServer } = require("@node-wot/binding-http");
117113

118114
// create secure Servient with username & password credentials
119-
let servient = new Servient();
115+
const servient = new Servient();
120116
servient.addCredentials({
121117
"urn:dev:wot:org:eclipse:thingweb:my-example-secure": {
122118
username: "node-wot",
123119
password: "hello",
124120
// token: "1/mZ1edKKACtPAb7zGlwSzvs72PvhAbGmB8K1ZrGxpcNM"
125121
},
126122
});
127-
let httpConfig = {
123+
const httpConfig = {
128124
allowSelfSigned: true, // client configuration
129125
serverKey: "privatekey.pem",
130126
serverCert: "certificate.pem",

packages/binding-mqtt/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ In addition, the Thing subscribes to the `resetCounter` topic (via its action ha
2626
it can handle requests to reset the counter value.
2727

2828
```js
29-
Servient = require("@node-wot/core").Servient;
30-
MqttBrokerServer = require("@node-wot/binding-mqtt").MqttBrokerServer;
29+
const { Servient } = require("@node-wot/core");
30+
const { MqttBrokerServer } = require("@node-wot/binding-mqtt");
3131

3232
// create Servient add MQTT binding
33-
let servient = new Servient();
33+
const servient = new Servient();
3434
servient.addServer(new MqttBrokerServer({ uri: "mqtt://test.mosquitto.org" }));
3535

3636
servient.start().then((WoT) => {
@@ -111,17 +111,15 @@ The Thing Description corresponding to the previous example is shown below:
111111
This example takes the Thing Description of the previous example and subscribes to the `counterEvent` and resets the counter every 20s via the `resetCounter` action.
112112

113113
```js
114-
Servient = require("@node-wot/core").Servient;
115-
MqttClientFactory = require("@node-wot/binding-mqtt").MqttClientFactory;
116-
117-
Helpers = require("@node-wot/core").Helpers;
114+
const { Servient } = require("@node-wot/core");
115+
const { MqttClientFactory } = require("@node-wot/binding-mqtt");
118116

119117
// create Servient and add MQTT binding
120-
let servient = new Servient();
118+
const servient = new Servient();
121119
servient.addClientFactory(new MqttClientFactory(null));
122120

123121
// Thing Description can be also fetched
124-
let td = `{
122+
const td = `{
125123
"@context": "https://www.w3.org/2019/td/v1",
126124
"title": "MQTT-Test",
127125
"id": "urn:dev:wot:mqtt:counter",

packages/td-tools/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@ The example parses a TD and also serializes yet another newly created TD.
1818

1919
```
2020
// example.js
21-
TDTools = require("@node-wot/td-tools");
22-
Thing = require("@node-wot/td-tools").Thing;
23-
21+
const TDTools = require("@node-wot/td-tools");
22+
const { Thing } = require("@node-wot/td-tools");
2423
2524
// parse TD
26-
let tdString = JSON.stringify({
25+
const tdString = JSON.stringify({
2726
id : "123",
2827
title: "MyThing"
2928
});
30-
let dd = TDTools.parseTD(tdString);
29+
const dd = TDTools.parseTD(tdString);
3130
console.log("**** PARSED TD ****");
3231
console.log(dd);
3332
console.log("****");
3433
3534
3635
// init Thing and serialize to TD
37-
let thing = new Thing();
36+
const thing = new Thing();
3837
thing.id = "789";
3938
thing["@type"] = "Thing";
4039
thing.support = "foo@example.com"
@@ -43,7 +42,7 @@ thing.properties = {
4342
type: "integer"
4443
}
4544
}
46-
let tdString2 = TDTools.serializeTD(thing);
45+
const tdString2 = TDTools.serializeTD(thing);
4746
console.log("**** SERIALIZED TD ****");
4847
console.log(tdString2);
4948
console.log("****");

0 commit comments

Comments
 (0)