Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 8de25f8

Browse files
authored
Change var to let or const, remove unnecessary semicolons at the end of function declarations (#142)
* Change var to let or const, remove unnecessary semicolons at the end of function declarations * Revert change to XccTemplate, those go in a different PR * restore spaces
1 parent b66be1b commit 8de25f8

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

src/test/resources/sample-base-dir/services/javascript.sjs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// - Setting additional response headers
99
//
1010
function get(context, params) {
11-
var results = [];
11+
let results = [];
1212
context.outputTypes = [];
13-
for (var pname in params) {
13+
for (const pname in params) {
1414
if (params.hasOwnProperty(pname)) {
1515
results.push({name: pname, value: params[pname]});
1616
context.outputTypes.push('application/json');
@@ -28,7 +28,7 @@ function get(context, params) {
2828

2929
// Return a Sequence to return multiple documents
3030
return Sequence.from(results);
31-
};
31+
}
3232

3333
// PUT
3434
//
@@ -49,8 +49,8 @@ function get(context, params) {
4949
//
5050
function put(context, params, input) {
5151
// normalize the inputs so we don't care whether we have 1 or many
52-
var docs = normalizeInput(input);
53-
var basenames = params.basename instanceof Array
52+
const docs = normalizeInput(input);
53+
const basenames = params.basename instanceof Array
5454
? params.basename: [ params.basename ];
5555

5656
// Validate inputs.
@@ -62,9 +62,9 @@ function put(context, params, input) {
6262
}
6363

6464
// Do something with the input documents
65-
var i = 0;
66-
var uris = [];
67-
for (var doc of docs) {
65+
let i = 0;
66+
const uris = [];
67+
for (const doc of docs) {
6868
uris.push( doSomething(
6969
doc, context.inputTypes[i], basenames[i++]
7070
));
@@ -73,17 +73,17 @@ function put(context, params, input) {
7373
// Set the response body MIME type and return the response data.
7474
context.outputTypes = ['application/json'];
7575
return { written: uris };
76-
};
76+
}
7777

7878
function post(context, params, input) {
7979
xdmp.log('POST invoked');
8080
return null;
81-
};
81+
}
8282

8383
function deleteFunction(context, params) {
8484
xdmp.log('POST invoked');
8585
return null;
86-
};
86+
}
8787

8888
// PUT helper func that demonstrates working with input documents.
8989
//
@@ -99,10 +99,10 @@ function deleteFunction(context, params) {
9999
//
100100
function doSomething(doc, docType, basename)
101101
{
102-
var uri = '/extensions/' + basename;
102+
let uri = '/extensions/' + basename;
103103
if (docType == 'application/json') {
104104
// create a mutable version of the doc so we can modify it
105-
var mutableDoc = doc.toObject();
105+
const mutableDoc = doc.toObject();
106106
uri += '.json';
107107

108108
// add a JSON property to the input content
@@ -117,7 +117,7 @@ function doSomething(doc, docType, basename)
117117
} else {
118118
return '(skipped)';
119119
}
120-
};
120+
}
121121

122122
// Helper function that demonstrates how to normalize inputs
123123
// that may or may not be multi-valued, such as the 'input'
@@ -132,7 +132,7 @@ function normalizeInput(item)
132132
return (item instanceof Sequence)
133133
? item // many
134134
: Sequence.from([item]); // one
135-
};
135+
}
136136

137137
// Helper function that demonstrates how to return an error response
138138
// to the client.
@@ -145,7 +145,7 @@ function returnErrToClient(statusCode, statusMsg, body)
145145
fn.error(null, 'RESTAPI-SRVEXERR',
146146
Sequence.from([statusCode, statusMsg, body]));
147147
// unreachable - control does not return from fn.error.
148-
};
148+
}
149149

150150

151151
// Include an export for each method supported by your extension.

src/test/resources/sample-base-dir/transforms/javascript-transform.sjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function insertTimestamp(context, params, content)
22
{
33
if (context.inputType.search('json') >= 0) {
4-
var result = content.toObject();
4+
let result = content.toObject();
55
if (context.acceptTypes) { /* read */
66
result.readTimestamp = fn.currentDateTime();
77
} else { /* write */
@@ -12,6 +12,6 @@ function insertTimestamp(context, params, content)
1212
/* Pass thru for non-JSON documents */
1313
return content;
1414
}
15-
};
15+
}
1616

1717
exports.transform = insertTimestamp;

0 commit comments

Comments
 (0)