1.0.9
This commit is contained in:
parent
7f8b2e4f7a
commit
3ecf33036c
@ -25,7 +25,7 @@ export function randomNum (minNum, maxNum) {
|
|||||||
* @param {Array} arr
|
* @param {Array} arr
|
||||||
* @param {number} index
|
* @param {number} index
|
||||||
*/
|
*/
|
||||||
export function nextArray(arr, index) {
|
export function nextArray (arr, index) {
|
||||||
index--;
|
index--;
|
||||||
return arr.slice(index + 1, arr.length).concat(arr.slice(0, index + 1));
|
return arr.slice(index + 1, arr.length).concat(arr.slice(0, index + 1));
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ export function nextArray(arr, index) {
|
|||||||
* 数组去重函数
|
* 数组去重函数
|
||||||
* @param {Array} arr
|
* @param {Array} arr
|
||||||
*/
|
*/
|
||||||
export function ArrayDeHeavy(arr) {
|
export function ArrayDeHeavy (arr) {
|
||||||
let newArr = new Set();
|
let newArr = new Set();
|
||||||
arr.forEach(item => {
|
arr.forEach(item => {
|
||||||
newArr.add(item);
|
newArr.add(item);
|
||||||
@ -47,7 +47,7 @@ export function ArrayDeHeavy(arr) {
|
|||||||
* 获取相对时间(中文)
|
* 获取相对时间(中文)
|
||||||
* @param {Date} date
|
* @param {Date} date
|
||||||
*/
|
*/
|
||||||
export function getRelativeTime(date) {
|
export function getRelativeTime (date) {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
const diffInSeconds = Math.floor((now.getTime() - date.getTime()) / 1000);
|
||||||
|
|
||||||
@ -81,4 +81,31 @@ export function getRelativeTime(date) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return '很久以前';
|
return '很久以前';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 解析nginx日志(单行)
|
||||||
|
* @param {string} log
|
||||||
|
*/
|
||||||
|
function parseNginxLog (log) {
|
||||||
|
const logPattern = /^(\S+) - - \[([^\]]+)\] "(\S+) (\S+) HTTP\/\d\.\d" (\d+) (\d+) "([^"]*)" "([^"]*)"/;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const match = log.match(logPattern);
|
||||||
|
if (match) {
|
||||||
|
return {
|
||||||
|
ip: match[1],
|
||||||
|
timestamp: match[2],
|
||||||
|
method: match[3],
|
||||||
|
url: match[4],
|
||||||
|
status: parseInt(match[5]),
|
||||||
|
responseSize: parseInt(match[6]),
|
||||||
|
referrer: match[7],
|
||||||
|
userAgent: match[8],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
2
index.js
2
index.js
@ -8,6 +8,6 @@
|
|||||||
* @FilePath: /index.js
|
* @FilePath: /index.js
|
||||||
*/
|
*/
|
||||||
export { animateStart, setClassVar, getStyleVar } from './Tool/animate.js';
|
export { animateStart, setClassVar, getStyleVar } from './Tool/animate.js';
|
||||||
export { randomNum, nextArray, ArrayDeHeavy, getRelativeTime } from './Tool/number.js';
|
export { randomNum, nextArray, ArrayDeHeavy, getRelativeTime, parseNginxLog } from './Tool/number.js';
|
||||||
|
|
||||||
console.log('ddmt-tool Loading successfully!! 😺');
|
console.log('ddmt-tool Loading successfully!! 😺');
|
1
types/index.d.ts
vendored
1
types/index.d.ts
vendored
@ -8,5 +8,6 @@ declare module 'ddmt-tool' {
|
|||||||
export function randomNum(minNum: number): number;
|
export function randomNum(minNum: number): number;
|
||||||
export function randomNum(minNum: number, maxNum: number): number;
|
export function randomNum(minNum: number, maxNum: number): number;
|
||||||
export function nextArray(arr: any[], index: number): any[];
|
export function nextArray(arr: any[], index: number): any[];
|
||||||
|
export function parseNginxLog(log: string): object;
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user