Skip to content

Commit caf0d43

Browse files
style: format code with StandardJS
This commit fixes the style issues introduced in bb84887 according to the output from StandardJS. Details: None
1 parent bb84887 commit caf0d43

File tree

2 files changed

+44
-46
lines changed

2 files changed

+44
-46
lines changed

server/index.js

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ const Response = require('./response.js') // Import the response object
55
const { warn } = require('console')
66

77
/**
8-
*
8+
*
99
* @param {Function} callback - The callback function to handle incoming connections.
1010
* @param {Object} context - The context object containing the server configuration.
1111
* @returns A server socket object.
12-
*
12+
*
1313
* @example
1414
* ```javascript
1515
* const server = getSocket(handler, {
@@ -28,12 +28,11 @@ function getSocket (callback, context) {
2828
return net.createServer(Socket => callback(Socket, context))
2929
}
3030

31-
3231
/**
33-
*
32+
*
3433
* @param {Socket} socket - The socket object for the response.
3534
* @param {Object} context - The context object containing the server configuration.
36-
* @returns A server socket object.
35+
* @returns A server socket object.
3736
*/
3837
function handler (socket, context) {
3938
socket.on('data', (data) => {
@@ -47,8 +46,8 @@ function handler (socket, context) {
4746
console.error('Error parsing HTTP request:', error)
4847
res.sendStatus(400) // Send a Bad Request status
4948
return null
50-
});
51-
});
49+
})
50+
})
5251
}
5352

5453
/**
@@ -152,7 +151,7 @@ function extractParams (routePath, actualPath) {
152151
*/
153152
class Server {
154153
socket
155-
/**
154+
/**
156155
* Creates a new Server instance
157156
* @constructor
158157
*/
@@ -163,15 +162,15 @@ class Server {
163162
* @private
164163
*/
165164
this.socket = getSocket(handler, this)
166-
/**
165+
/**
167166
* Array of routes registered with the server
168167
* @type {Array}
169168
* @private
170169
*/
171170
this.routes = []
172171
}
173172

174-
/**
173+
/**
175174
* Starts the server listening on specified port
176175
* @param {number} PORT - The port number to listen on
177176
* @param {Function} callback - Callback function to execute when server starts listening
@@ -188,16 +187,16 @@ class Server {
188187
}
189188

190189
class Hasty extends Server {
191-
/**
190+
/**
192191
* Creates a new Hasty server instance
193192
* @constructor
194193
*/
195194
constructor () {
196195
super()
197-
/**
196+
/**
198197
* Collection of middleware functions
199198
* @type {Array<Function>}
200-
* @private
199+
* @private
201200
*/
202201
this.enableCors = false // default to false
203202
/**
@@ -228,71 +227,72 @@ class Hasty extends Server {
228227
cors (enable) {
229228
this.enableCors = enable
230229
}
230+
231231
/**
232232
* GET
233-
*
234-
* @param {string} path
235-
* @param {Function} callback
233+
*
234+
* @param {string} path
235+
* @param {Function} callback
236236
*/
237237
get (path, callback) {
238238
this.setRoute('GET', { callback, path })
239239
}
240240

241241
/**
242242
* POST
243-
*
244-
* @param {string} path
245-
* @param {Function} callback
243+
*
244+
* @param {string} path
245+
* @param {Function} callback
246246
*/
247247
post (path, callback) {
248248
this.setRoute('POST', { callback, path })
249249
}
250250

251251
/**
252252
* PUT
253-
*
254-
* @param {string} path
255-
* @param {Function} callback
253+
*
254+
* @param {string} path
255+
* @param {Function} callback
256256
*/
257257
put (path, callback) {
258258
this.setRoute('PUT', { callback, path })
259259
}
260260

261261
/**
262262
* DELETE
263-
*
264-
* @param {string} path
265-
* @param {Function} callback
263+
*
264+
* @param {string} path
265+
* @param {Function} callback
266266
*/
267267
delete (path, callback) {
268268
this.setRoute('DELETE', { callback, path })
269269
}
270270

271271
/**
272272
* PATCH
273-
*
274-
* @param {string} path
275-
* @param {Function} callback
273+
*
274+
* @param {string} path
275+
* @param {Function} callback
276276
*/
277277
patch (path, callback) {
278278
this.setRoute('PATCH', { callback, path })
279279
}
280280

281281
/**
282282
* HEAD
283-
*
284-
* @param {string} path
285-
* @param {Function} callback
283+
*
284+
* @param {string} path
285+
* @param {Function} callback
286286
*/
287287
head (path, callback) {
288288
this.setRoute('HEAD', { callback, path })
289289
}
290290

291291
/**
292292
* OPTIONS
293-
*
294-
* @param {string} path
295-
* @param {Function} callback
293+
*
294+
* @param {string} path
295+
* @param {Function} callback
296296
*/
297297
options (path, callback) {
298298
this.setRoute('OPTIONS', { callback, path })

server/response.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const fs = require('fs')
22
const { lookupMimeType } = require('../lib/utils')
33
const path = require('path')
44

5-
65
const STATUS_CODES = Object.freeze({
76
200: 'OK',
87
201: 'Created',
@@ -25,16 +24,15 @@ const STATUS_CODES = Object.freeze({
2524
503: 'Service Unavailable'
2625
})
2726

28-
2927
/**
3028
* Response class for handling HTTP responses.
31-
*
29+
*
3230
* @class Response
33-
*
31+
*
3432
* @param {Socket} socket - The socket object for the response.
3533
* @param {boolean} enableCors - Enable Cross-Origin Resource Sharing (CORS).
3634
* @param {string} statusTextMap - Map of status codes to status texts.
37-
* @example
35+
* @example
3836
* ```javascript
3937
const Response = require('./response.js');
4038
@@ -68,7 +66,7 @@ class Response {
6866
}
6967

7068
/**
71-
*
69+
*
7270
* @param {number} code - The HTTP status code.
7371
* @returns - The Response instance.
7472
*/
@@ -81,7 +79,7 @@ class Response {
8179
}
8280

8381
/**
84-
*
82+
*
8583
* @param {string} key - The header key.
8684
* @param {string} value - The header value.
8785
* @returns - The Response instance.
@@ -115,7 +113,7 @@ class Response {
115113
}
116114

117115
/**
118-
*
116+
*
119117
* @param {string} data - The data to send.
120118
* @returns - If the data is an object or array, send as JSON
121119
*/
@@ -144,7 +142,7 @@ class Response {
144142
}
145143

146144
/**
147-
*
145+
*
148146
* @param {number} statusCode - The HTTP status code.
149147
* Updates the status code and sends the status code as a response.
150148
*/
@@ -156,7 +154,7 @@ class Response {
156154
}
157155

158156
/**
159-
*
157+
*
160158
* @param {*} data - The data to send.
161159
*/
162160
json (data) {
@@ -172,7 +170,7 @@ class Response {
172170
}
173171

174172
/**
175-
*
173+
*
176174
* @param {*} file - The file to send.
177175
*/
178176
sendFile (file) {
@@ -208,7 +206,7 @@ class Response {
208206
}
209207

210208
/**
211-
*
209+
*
212210
* @param {*} file - The file to send.
213211
* @param {*} filename - The filename to send.
214212
*/

0 commit comments

Comments
 (0)