routup 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -66,7 +66,8 @@ router.listen(3000);
66
66
 
67
67
  ## Plugins
68
68
 
69
- According to the fact that routup is a minimalistic framework, it depends on plugins to cover some
69
+ According to the fact that routup is a minimalistic framework,
70
+ it depends on [plugins](https://github.com/routup/plugins) to cover some
70
71
  typically http framework functions, which are not integrated in the main package.
71
72
 
72
73
  | Name | Description |
@@ -1,4 +1,4 @@
1
- export declare enum Method {
1
+ export declare enum MethodName {
2
2
  GET = "get",
3
3
  POST = "post",
4
4
  PUT = "put",
package/dist/index.cjs CHANGED
@@ -235,16 +235,16 @@ function getConfigOption(key) {
235
235
  return config.get(key);
236
236
  }
237
237
 
238
- exports.Method = void 0;
239
- (function(Method) {
240
- Method["GET"] = 'get';
241
- Method["POST"] = 'post';
242
- Method["PUT"] = 'put';
243
- Method["PATCH"] = 'patch';
244
- Method["DELETE"] = 'delete';
245
- Method["OPTIONS"] = 'options';
246
- Method["HEAD"] = 'head';
247
- })(exports.Method || (exports.Method = {}));
238
+ exports.MethodName = void 0;
239
+ (function(MethodName) {
240
+ MethodName["GET"] = 'get';
241
+ MethodName["POST"] = 'post';
242
+ MethodName["PUT"] = 'put';
243
+ MethodName["PATCH"] = 'patch';
244
+ MethodName["DELETE"] = 'delete';
245
+ MethodName["OPTIONS"] = 'options';
246
+ MethodName["HEAD"] = 'head';
247
+ })(exports.MethodName || (exports.MethodName = {}));
248
248
  exports.HeaderName = void 0;
249
249
  (function(HeaderName) {
250
250
  HeaderName["ACCEPT"] = 'accept';
@@ -1156,16 +1156,16 @@ class Route {
1156
1156
  }
1157
1157
  matchMethod(method) {
1158
1158
  let name = method.toLowerCase();
1159
- if (name === exports.Method.HEAD && !smob.hasOwnProperty(this.layers, name)) {
1160
- name = exports.Method.GET;
1159
+ if (name === exports.MethodName.HEAD && !smob.hasOwnProperty(this.layers, name)) {
1160
+ name = exports.MethodName.GET;
1161
1161
  }
1162
1162
  return Object.prototype.hasOwnProperty.call(this.layers, name);
1163
1163
  }
1164
1164
  // --------------------------------------------------
1165
1165
  getMethods() {
1166
1166
  const keys = Object.keys(this.layers);
1167
- if (smob.hasOwnProperty(this.layers, exports.Method.GET) && !smob.hasOwnProperty(this.layers, exports.Method.HEAD)) {
1168
- keys.push(exports.Method.HEAD);
1167
+ if (smob.hasOwnProperty(this.layers, exports.MethodName.GET) && !smob.hasOwnProperty(this.layers, exports.MethodName.HEAD)) {
1168
+ keys.push(exports.MethodName.HEAD);
1169
1169
  }
1170
1170
  return keys;
1171
1171
  }
@@ -1176,8 +1176,8 @@ class Route {
1176
1176
  return;
1177
1177
  }
1178
1178
  let name = req.method.toLowerCase();
1179
- if (name === exports.Method.HEAD && !smob.hasOwnProperty(this.layers, name)) {
1180
- name = exports.Method.GET;
1179
+ if (name === exports.MethodName.HEAD && !smob.hasOwnProperty(this.layers, name)) {
1180
+ name = exports.MethodName.GET;
1181
1181
  }
1182
1182
  const layers = this.layers[name];
1183
1183
  /* istanbul ignore next */ if (typeof layers === 'undefined' || layers.length === 0 || typeof meta.path === 'undefined') {
@@ -1221,25 +1221,25 @@ class Route {
1221
1221
  }
1222
1222
  }
1223
1223
  get(...handlers) {
1224
- return this.register(exports.Method.GET, ...handlers);
1224
+ return this.register(exports.MethodName.GET, ...handlers);
1225
1225
  }
1226
1226
  post(...handlers) {
1227
- return this.register(exports.Method.POST, ...handlers);
1227
+ return this.register(exports.MethodName.POST, ...handlers);
1228
1228
  }
1229
1229
  put(...handlers) {
1230
- return this.register(exports.Method.PUT, ...handlers);
1230
+ return this.register(exports.MethodName.PUT, ...handlers);
1231
1231
  }
1232
1232
  patch(...handlers) {
1233
- return this.register(exports.Method.PATCH, ...handlers);
1233
+ return this.register(exports.MethodName.PATCH, ...handlers);
1234
1234
  }
1235
1235
  delete(...handlers) {
1236
- return this.register(exports.Method.DELETE, ...handlers);
1236
+ return this.register(exports.MethodName.DELETE, ...handlers);
1237
1237
  }
1238
1238
  head(...handlers) {
1239
- return this.register(exports.Method.HEAD, ...handlers);
1239
+ return this.register(exports.MethodName.HEAD, ...handlers);
1240
1240
  }
1241
1241
  options(...handlers) {
1242
- return this.register(exports.Method.OPTIONS, ...handlers);
1242
+ return this.register(exports.MethodName.OPTIONS, ...handlers);
1243
1243
  }
1244
1244
  // --------------------------------------------------
1245
1245
  isStrictPath() {
@@ -1324,7 +1324,7 @@ class Router {
1324
1324
  res.end();
1325
1325
  return;
1326
1326
  }
1327
- if (req.method && req.method.toLowerCase() === exports.Method.OPTIONS) {
1327
+ if (req.method && req.method.toLowerCase() === exports.MethodName.OPTIONS) {
1328
1328
  const options = allowedMethods.map((key)=>key.toUpperCase()).join(',');
1329
1329
  res.setHeader(exports.HeaderName.ALLOW, options);
1330
1330
  send(res, options);
@@ -1373,8 +1373,8 @@ class Router {
1373
1373
  match = layer.matchPath(path);
1374
1374
  if (req.method && !layer.matchMethod(req.method)) {
1375
1375
  match = false;
1376
- if (req.method.toLowerCase() === exports.Method.OPTIONS) {
1377
- allowedMethods = smob.mergeArrays(allowedMethods, layer.getMethods(), true);
1376
+ if (req.method.toLowerCase() === exports.MethodName.OPTIONS) {
1377
+ allowedMethods = smob.distinctArray(smob.merge(allowedMethods, layer.getMethods()));
1378
1378
  }
1379
1379
  }
1380
1380
  }