mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
build: trident-sync prepare
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
const log4js = require('log4js');
|
||||
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'info';
|
||||
const path = require('path');
|
||||
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('fast');
|
||||
@@ -0,0 +1,43 @@
|
||||
const numbers = '0123456789';
|
||||
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const specials = '~!@#$%^*()_+-=[]{}|;:,./<>?';
|
||||
|
||||
/**
|
||||
* Generate random string
|
||||
* @param {Number} length
|
||||
* @param {Object} options
|
||||
*/
|
||||
function randomStr(length, options) {
|
||||
length || (length = 8);
|
||||
options || (options = {});
|
||||
|
||||
let chars = '';
|
||||
let result = '';
|
||||
|
||||
if (options === true) {
|
||||
chars = numbers + letters;
|
||||
} else if (typeof options === 'string') {
|
||||
chars = options;
|
||||
} else {
|
||||
if (options.numbers !== false) {
|
||||
chars += typeof options.numbers === 'string' ? options.numbers : numbers;
|
||||
}
|
||||
|
||||
if (options.letters !== false) {
|
||||
chars += typeof options.letters === 'string' ? options.letters : letters;
|
||||
}
|
||||
|
||||
if (options.specials) {
|
||||
chars +=
|
||||
typeof options.specials === 'string' ? options.specials : specials;
|
||||
}
|
||||
}
|
||||
|
||||
while (length > 0) {
|
||||
length--;
|
||||
result += chars[Math.floor(Math.random() * chars.length)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export const RandomUtil = { randomStr };
|
||||
Reference in New Issue
Block a user