Skip to content

Commit

Permalink
Merge 1dbeddd into ac53fdc
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljoppi committed Sep 5, 2017
2 parents ac53fdc + 1dbeddd commit bfa5e4e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 43 deletions.
29 changes: 29 additions & 0 deletions http/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';
var ono = require('..');
var statuses = require('statuses');
var codes = statuses.codes;

codes.forEach(function (code) {
var statusMessage = statuses[code];
var identifier = toIdentifier(statusMessage);

exports[identifier] = function () {
var args = Array.prototype.slice.call(arguments);
var err = ono.apply(this, args);
err.status = code;
err.statusCode = code;
if (!args.length || !err.message) {
err.message = statusMessage;
}
return err;
};
});

function toIdentifier (str) {
return str.split(' ').map(function (token, i) {
var f = token.slice(0, 1);
var pre = i ? f.toUpperCase() : f.toLowerCase();
var pos = token.slice(1);
return pre + pos;
}).join('').replace(/[^ _0-9a-z]/gi, '');
}
81 changes: 40 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"version-bump-prompt": "^3.1.0"
},
"dependencies": {
"format-util": "^1.0.3"
"format-util": "^1.0.3",
"statuses": "^1.3.1"
}
}
}

0 comments on commit bfa5e4e

Please sign in to comment.