chore: lib-server

This commit is contained in:
xiaojunnuo
2024-10-03 22:03:49 +08:00
parent a13203fb3f
commit a4e2cc54e6
101 changed files with 936 additions and 223 deletions
@@ -1,12 +0,0 @@
import log4js from 'log4js';
import path from 'path';
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info';
const filename = path.join('/logs/server.log');
log4js.configure({
appenders: {
std: { type: 'stdout', level: 'debug' },
file: { type: 'file', pattern: 'yyyy-MM-dd', daysToKeep: 3, filename },
},
categories: { default: { appenders: ['std'], level } },
});
export const logger = log4js.getLogger('server');
+9 -9
View File
@@ -1,6 +1,6 @@
const numbers = '0123456789';
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
const specials = '~!@#$%^*()_+-=[]{}|;:,./<>?';
const numbers = "0123456789";
const letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
const specials = "~!@#$%^*()_+-=[]{}|;:,./<>?";
/**
* Generate random string
@@ -11,24 +11,24 @@ function randomStr(length, options?) {
length || (length = 8);
options || (options = {});
let chars = '';
let result = '';
let chars = "";
let result = "";
if (options === true) {
chars = numbers + letters;
} else if (typeof options === 'string') {
} else if (typeof options === "string") {
chars = options;
} else {
if (options.numbers !== false) {
chars += typeof options.numbers === 'string' ? options.numbers : numbers;
chars += typeof options.numbers === "string" ? options.numbers : numbers;
}
if (options.letters !== false) {
chars += typeof options.letters === 'string' ? options.letters : letters;
chars += typeof options.letters === "string" ? options.letters : letters;
}
if (options.specials) {
chars += typeof options.specials === 'string' ? options.specials : specials;
chars += typeof options.specials === "string" ? options.specials : specials;
}
}