@ones-design/utils
Advanced tools
Comparing version 1.10.0 to 1.10.1-rc.0
@@ -31,6 +31,42 @@ import { isEqual as isEqual$1 } from '@senojs/lodash'; | ||
/** | ||
* @file 工具函数 - 警告 | ||
* @file 工具函数 - 控制台警告 | ||
* @author htmlin | ||
*/ | ||
let logs = { | ||
error: {}, | ||
warn: {} | ||
}; | ||
let timer = null; | ||
/** | ||
* 合并 1s 内的重复日志 | ||
* @param log 日志信息 | ||
* @param type 日志类型 | ||
*/ | ||
function debounceLogs(log, type = 'error') { | ||
const assertlogs = logs[type]; | ||
if (!assertlogs[log]) { | ||
assertlogs[log] = 1; | ||
} else { | ||
assertlogs[log]++; | ||
} | ||
if (timer) { | ||
clearTimeout(timer); | ||
} | ||
timer = setTimeout(() => { | ||
Object.entries(logs).forEach(([key, value]) => { | ||
for (const log in value) { | ||
console[key](`[ONES Design] ${log}` + (value[log] > 1 ? ` (×${value[log]})` : '')); | ||
} | ||
}); | ||
logs = { | ||
error: {}, | ||
warn: {} | ||
}; | ||
timer = null; | ||
}, 500); | ||
} | ||
/** | ||
* 错误警告 | ||
@@ -41,10 +77,14 @@ * @param {boolean} condition - 条件表达式 | ||
function warn(condition, msg) { | ||
if (!condition) { | ||
console.error(`[ONES Design] ${msg}`); | ||
} | ||
if (condition) return; | ||
debounceLogs(msg); | ||
} | ||
/** | ||
* 警告提示 | ||
* @param {boolean} condition - 条件表达式 | ||
* @param {string} msg - 当 condition 结果为 false 时提示的警告信息 | ||
*/ | ||
function tip(condition, msg) { | ||
if (!condition) { | ||
console.warn(`[ONES Design] ${msg}`); | ||
} | ||
if (condition) return; | ||
debounceLogs(msg, 'warn'); | ||
} | ||
@@ -51,0 +91,0 @@ |
@@ -31,6 +31,42 @@ import { isEqual as isEqual$1 } from '@senojs/lodash'; | ||
/** | ||
* @file 工具函数 - 警告 | ||
* @file 工具函数 - 控制台警告 | ||
* @author htmlin | ||
*/ | ||
let logs = { | ||
error: {}, | ||
warn: {} | ||
}; | ||
let timer = null; | ||
/** | ||
* 合并 1s 内的重复日志 | ||
* @param log 日志信息 | ||
* @param type 日志类型 | ||
*/ | ||
function debounceLogs(log, type = 'error') { | ||
const assertlogs = logs[type]; | ||
if (!assertlogs[log]) { | ||
assertlogs[log] = 1; | ||
} else { | ||
assertlogs[log]++; | ||
} | ||
if (timer) { | ||
clearTimeout(timer); | ||
} | ||
timer = setTimeout(() => { | ||
Object.entries(logs).forEach(([key, value]) => { | ||
for (const log in value) { | ||
console[key](`[ONES Design] ${log}` + (value[log] > 1 ? ` (×${value[log]})` : '')); | ||
} | ||
}); | ||
logs = { | ||
error: {}, | ||
warn: {} | ||
}; | ||
timer = null; | ||
}, 500); | ||
} | ||
/** | ||
* 错误警告 | ||
@@ -41,10 +77,14 @@ * @param {boolean} condition - 条件表达式 | ||
function warn(condition, msg) { | ||
if (!condition) { | ||
console.error(`[ONES Design] ${msg}`); | ||
} | ||
if (condition) return; | ||
debounceLogs(msg); | ||
} | ||
/** | ||
* 警告提示 | ||
* @param {boolean} condition - 条件表达式 | ||
* @param {string} msg - 当 condition 结果为 false 时提示的警告信息 | ||
*/ | ||
function tip(condition, msg) { | ||
if (!condition) { | ||
console.warn(`[ONES Design] ${msg}`); | ||
} | ||
if (condition) return; | ||
debounceLogs(msg, 'warn'); | ||
} | ||
@@ -51,0 +91,0 @@ |
/** | ||
* @file 工具函数 - 警告 | ||
* @author htmlin | ||
* 错误警告 | ||
* @param {boolean} condition - 条件表达式 | ||
* @param {string} msg - 当 condition 结果为 false 时提示的警告信息 | ||
*/ | ||
declare function warn(condition: boolean, msg: string): void; | ||
/** | ||
* 错误警告 | ||
* 警告提示 | ||
* @param {boolean} condition - 条件表达式 | ||
* @param {string} msg - 当 condition 结果为 false 时提示的警告信息 | ||
*/ | ||
declare function warn(condition: boolean, msg: string): void; | ||
declare function tip(condition: boolean, msg: string): void; | ||
export { warn, tip }; |
{ | ||
"name": "@ones-design/utils", | ||
"version": "1.10.0", | ||
"version": "1.10.1-rc.0", | ||
"description": "ONES Design", | ||
@@ -57,3 +57,3 @@ "type": "module", | ||
}, | ||
"gitHead": "2cc0fc8d62d3f97f95be8fd6ee8a752ea84e5f04" | ||
"gitHead": "3aa363849c517182e32a6a8e7a7953a6e356b5ea" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67354
889
2