eslint-plugin-jsdoc

This commit is contained in:
yeyang
2024-03-23 18:59:59 +08:00
committed by 🌌
parent de4547d16d
commit 56576352c7
41 changed files with 784 additions and 365 deletions

View File

@@ -7,6 +7,10 @@ cron表达式为秒
*/
// 返回错误信息用
let message = ''
/**
*
* @param cronExpression
*/
export default function cronValidate (cronExpression) {
// 先将cron表达式进行分割
let cronParams = cronExpression.split(' ')
@@ -68,21 +72,37 @@ export default function cronValidate (cronExpression) {
}
// 检查秒的函数方法
/**
*
* @param secondsField
*/
function checkSecondsField (secondsField) {
return checkField(secondsField, 0, 59, '秒')
}
// 检查分的函数方法
/**
*
* @param minutesField
*/
function checkMinutesField (minutesField) {
return checkField(minutesField, 0, 59, '分')
}
// 检查小时的函数方法
/**
*
* @param hoursField
*/
function checkHoursField (hoursField) {
return checkField(hoursField, 0, 23, '时')
}
// 检查日期的函数方法
/**
*
* @param dayOfMonthField
*/
function checkDayOfMonthField (dayOfMonthField) {
if (dayOfMonthField == '?') {
return true
@@ -98,6 +118,10 @@ function checkDayOfMonthField (dayOfMonthField) {
}
// 检查月份的函数方法
/**
*
* @param monthsField
*/
function checkMonthsField (monthsField) {
// 月份简写处理
if (monthsField != '*') {
@@ -120,6 +144,10 @@ function checkMonthsField (monthsField) {
}
// 星期验证
/**
*
* @param dayOfWeekField
*/
function checkDayOfWeekField (dayOfWeekField) {
dayOfWeekField = dayOfWeekField.replace('SUN', '1')
dayOfWeekField = dayOfWeekField.replace('MON', '2')
@@ -143,11 +171,22 @@ function checkDayOfWeekField (dayOfWeekField) {
}
// 检查年份的函数方法
/**
*
* @param yearField
*/
function checkYearField (yearField) {
return checkField(yearField, 1970, 2099, '年的')
}
// 通用的检查值的大小范围的方法( - , / *)
/**
*
* @param value
* @param minimal
* @param maximal
* @param attribute
*/
function checkField (value, minimal, maximal, attribute) {
// 校验值中是否有“-”,如果有“-”的话,下标会>0
if (value.indexOf('-') > -1) {
@@ -168,6 +207,14 @@ function checkField (value, minimal, maximal, attribute) {
}
// 检测是否是整数以及是否在范围内,参数:检测的值,下限,上限,是否检查端点,检查的属性
/**
*
* @param value
* @param minimal
* @param maximal
* @param checkExtremity
* @param attribute
*/
function checkIntValue (value, minimal, maximal, checkExtremity, attribute) {
try {
// 用10进制犯法来进行整数转换
@@ -187,6 +234,13 @@ function checkIntValue (value, minimal, maximal, checkExtremity, attribute) {
}
}
// 检验枚举类型的参数是否正确
/**
*
* @param value
* @param minimal
* @param maximal
* @param attribute
*/
function checkListField (value, minimal, maximal, attribute) {
let st = value.split(',')
let values = new Array(st.length)
@@ -232,6 +286,13 @@ function checkListField (value, minimal, maximal, attribute) {
}
// 检验循环
/**
*
* @param value
* @param minimal
* @param maximal
* @param attribute
*/
function checkIncrementField (value, minimal, maximal, attribute) {
if (value.split('/').length > 2) {
return (attribute + "中的参数只能有一个'/'")
@@ -257,6 +318,13 @@ function checkIncrementField (value, minimal, maximal, attribute) {
}
// 检验范围
/**
*
* @param params
* @param minimal
* @param maximal
* @param attribute
*/
function checkRangeAndCycle (params, minimal, maximal, attribute) {
// 校验“-”符号是否只有一个
if (params.split('-').length > 2) {
@@ -310,6 +378,14 @@ function checkRangeAndCycle (params, minimal, maximal, attribute) {
}
// 检查日中的特殊字符
/**
*
* @param value
* @param letter
* @param minimalBefore
* @param maximalBefore
* @param attribute
*/
function checkFieldWithLetter (value, letter, minimalBefore, maximalBefore, attribute) {
// 判断是否只有一个字母
for (let i = 0; i < value.length; i++) {
@@ -367,6 +443,14 @@ function checkFieldWithLetter (value, letter, minimalBefore, maximalBefore, attr
}
// 检查星期中的特殊字符
/**
*
* @param value
* @param letter
* @param minimalBefore
* @param maximalBefore
* @param attribute
*/
function checkFieldWithLetterWeek (value, letter, minimalBefore, maximalBefore, attribute) {
// 判断是否只有一个字母
for (let i = 0; i < value.length; i++) {

View File

@@ -18,6 +18,12 @@ try {
core = (await import('icqq').catch(() => {}))?.core
}
/**
*
* @param record_url
* @param seconds
* @param transcoding
*/
async function uploadRecord (record_url, seconds = 0, transcoding = true) {
if (!Contactable) return segment.record(record_url)
const result = await getPttBuffer(record_url, Bot.config.ffmpeg_path, transcoding)
@@ -95,6 +101,12 @@ async function uploadRecord (record_url, seconds = 0, transcoding = true) {
export default uploadRecord
/**
*
* @param file
* @param ffmpeg
* @param transcoding
*/
async function getPttBuffer (file, ffmpeg = 'ffmpeg', transcoding = true) {
let buffer
let time
@@ -158,6 +170,11 @@ async function getPttBuffer (file, ffmpeg = 'ffmpeg', transcoding = true) {
return { buffer, time }
}
/**
*
* @param file
* @param ffmpeg
*/
async function getAudioTime (file, ffmpeg = 'ffmpeg') {
return new Promise((resolve, _reject) => {
(0, child_process.exec)(`${ffmpeg} -i "${file}"`, async (_error, _stdout, stderr) => {
@@ -186,6 +203,11 @@ async function getAudioTime (file, ffmpeg = 'ffmpeg') {
})
}
/**
*
* @param file
* @param ffmpeg
*/
async function audioTrans (file, ffmpeg = 'ffmpeg') {
return new Promise((resolve, reject) => {
const tmpfile = path.join(TMP_DIR, (0, uuid)());
@@ -202,6 +224,10 @@ async function audioTrans (file, ffmpeg = 'ffmpeg') {
})
}
/**
*
* @param file
*/
async function read7Bytes (file) {
const fd = await fs.promises.open(file, 'r')
const buf = (await fd.read(Buffer.alloc(7), 0, 7, 0)).buffer
@@ -209,11 +235,18 @@ async function read7Bytes (file) {
return buf
}
/**
*
*/
function uuid () {
let hex = crypto.randomBytes(16).toString('hex')
return hex.substr(0, 8) + '-' + hex.substr(8, 4) + '-' + hex.substr(12, 4) + '-' + hex.substr(16, 4) + '-' + hex.substr(20)
}
/**
*
* @param ip
*/
function int32ip2str (ip) {
if (typeof ip === 'string') { return ip }
ip = ip & 0xffffffff
@@ -232,7 +265,10 @@ const TMP_DIR = os.tmpdir()
/** no operation */
const NOOP = () => { }
/** md5 hash */
/**
* md5 hash
* @param data
*/
const md5 = (data) => (0, crypto.createHash)('md5').update(data).digest()
errors.LoginErrorCode = errors.drop = errors.ErrorCode = void 0
@@ -284,6 +320,11 @@ const ErrorMessage = {
120: '在该群被禁言',
121: 'AT全体剩余次数不足'
}
/**
*
* @param code
* @param message
*/
function drop (code, message) {
if (!message || !message.length) { message = ErrorMessage[code] }
throw new core.ApiRejection(code, message)