修改了@ehason/utils

This commit is contained in:
lik 2020-11-12 17:23:54 +08:00
parent 1c0f15491e
commit af71c348f4
6 changed files with 163 additions and 5 deletions

1
.gitignore vendored
View File

@ -17,3 +17,4 @@
/auth/.idea/ /auth/.idea/
/utils/.idea/ /utils/.idea/
/utils/node_modules/ /utils/node_modules/
/test/node_modules/

17
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,17 @@
{
// 使 IntelliSense
//
// 访: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "test-debug",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/test/test.js"
}
]
}

139
utils/impl/httpstatus.js Normal file
View File

@ -0,0 +1,139 @@
const Status = {
Continue: 100,
SwitchingProtocols: 101,
Processing: 102,
EarlyHints: 103,
OK: 200,
Created: 201,
Accepted: 202,
NonAuthoritativeInfo: 203,
NoContent: 204,
ResetContent: 205,
PartialContent: 206,
Multi: 207,
AlreadyReported: 208,
IMUsed: 226,
MultipleChoices: 300,
MovedPermanently: 301,
Found: 302,
SeeOther: 303,
NotModified: 304,
UseProxy: 305,
TemporaryRedirect: 307,
PermanentRedirect: 308,
BadRequest: 400,
Unauthorized: 401,
PaymentRequired: 402,
Forbidden: 403,
NotFound: 404,
MethodNotAllowed: 405,
NotAcceptable: 406,
ProxyAuthRequired: 407,
RequestTimeout: 408,
Conflict: 409,
Gone: 410,
LengthRequired: 411,
PreconditionFailed: 412,
RequestEntityTooLarge: 413,
RequestURITooLong: 414,
UnsupportedMediaType: 415,
RequestedRangeNotSatisfiable: 416,
ExpectationFailed: 417,
Teapot: 418,
MisdirectedRequest: 421,
UnprocessableEntity: 422,
Locked: 423,
FailedDependency: 424,
TooEarly: 425,
UpgradeRequired: 426,
PreconditionRequired: 428,
TooManyRequests: 429,
RequestHeaderFieldsTooLarge: 431,
UnavailableForLegalReasons: 451,
InternalServerError: 500,
NotImplemented: 501,
BadGateway: 502,
ServiceUnavailable: 503,
GatewayTimeout: 504,
HTTPVersionNotSupported: 505,
VariantAlsoNegotiates: 506,
InsufficientStorage: 507,
LoopDetected: 508,
NotExtended: 510,
NetworkAuthenticationRequired: 511
}
const StatusStr = {
Continue: "Continue",
SwitchingProtocols: "Switching Protocols",
Processing: "Processing",
EarlyHints: "Early Hints",
OK: "OK",
Created: "Created",
Accepted: "Accepted",
NonAuthoritativeInfo: "Non-Authoritative Information",
NoContent: "No Content",
ResetContent: "Reset Content",
PartialContent: "Partial Content",
Multi: "Multi-",
AlreadyReported: "Already Reported",
IMUsed: "IM Used",
MultipleChoices: "Multiple Choices",
MovedPermanently: "Moved Permanently",
Found: "Found",
SeeOther: "See Other",
NotModified: "Not Modified",
UseProxy: "Use Proxy",
TemporaryRedirect: "Temporary Redirect",
PermanentRedirect: "Permanent Redirect",
BadRequest: "Bad Request",
Unauthorized: "Unauthorized",
PaymentRequired: "Payment Required",
Forbidden: "Forbidden",
NotFound: "Not Found",
MethodNotAllowed: "Method Not Allowed",
NotAcceptable: "Not Acceptable",
ProxyAuthRequired: "Proxy Authentication Required",
RequestTimeout: "Request Timeout",
Conflict: "Conflict",
Gone: "Gone",
LengthRequired: "Length Required",
PreconditionFailed: "Precondition Failed",
RequestEntityTooLarge: "Request Entity Too Large",
RequestURITooLong: "Request URI Too Long",
UnsupportedMediaType: "Unsupported Media Type",
RequestedRangeNotSatisfiable: "Requested Range Not Satisfiable",
ExpectationFailed: "Expectation Failed",
Teapot: "I'm a teapot",
MisdirectedRequest: "Misdirected Request",
UnprocessableEntity: "Unprocessable Entity",
Locked: "Locked",
FailedDependency: "Failed Dependency",
TooEarly: "Too Early",
UpgradeRequired: "Upgrade Required",
PreconditionRequired: "Precondition Required",
TooManyRequests: "Too Many Requests",
RequestHeaderFieldsTooLarge: "Request Header Fields Too Large",
UnavailableForLegalReasons: "Unavailable For Legal Reasons",
InternalServerError: "Internal Server Error",
NotImplemented: "Not Implemented",
BadGateway: "Bad Gateway",
ServiceUnavailable: "Service Unavailable",
GatewayTimeout: "Gateway Timeout",
HTTPVersionNotSupported: "HTTP Version Not Supported",
VariantAlsoNegotiates: "Variant Also Negotiates",
InsufficientStorage: "Insufficient Storage",
LoopDetected: "Loop Detected",
NotExtended: "Not Extended",
NetworkAuthenticationRequired: "Network Authentication Required",
}
module.exports = { Status, StatusStr }

View File

@ -8,10 +8,10 @@ function ctxresp(ctx, data, errno, errmsg) {
if (data === null || data === undefined) data = {}; if (data === null || data === undefined) data = {};
ctx.body = { ctx.body = {
result: errno === 0 ? 'ok' : 'fail', code: errno,
error: { code: errno, msg: errmsg }, msg: errmsg,
data: data, data: data,
stime: Moment().format('YYYY-MM-DD HH:mm:ss') stime: Moment().format('YYYY-MM-DD HH:mm:ss SSS')
}; };
} }

View File

@ -2,5 +2,6 @@
module.exports = { module.exports = {
prxrmq: require('./impl/prxrmq'), prxrmq: require('./impl/prxrmq'),
ctxresp: require('./impl/koaresp'), ctxresp: require('./impl/koaresp'),
crc: require('./impl/crc') crc: require('./impl/crc'),
httpstatus: require('./impl/httpstatus')
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "@ehason/utils", "name": "@ehason/utils",
"version": "1.1.2", "version": "1.1.5",
"description": "Utils for ehason develope", "description": "Utils for ehason develope",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {