tsdown
Version:
The Elegant Bundler for Libraries
38 lines (35 loc) • 889 B
JavaScript
import process from "node:process";
import { consola } from "consola";
//#region src/utils/logger.ts
/**
* Logger instance
*/
const logger = consola.withTag("tsdown");
function setSilent(silent) {
if (!("CONSOLA_LEVEL" in process.env)) logger.level = silent ? 0 : 3;
}
//#endregion
//#region src/utils/general.ts
function toArray(val, defaultValue) {
if (Array.isArray(val)) return val;
else if (val == null) {
if (defaultValue) return [defaultValue];
return [];
} else return [val];
}
function resolveComma(arr) {
return arr.flatMap((format) => format.split(","));
}
function debounce(fn, wait) {
let timeout;
return function(...args) {
if (timeout) clearTimeout(timeout);
timeout = setTimeout(() => {
timeout = void 0;
fn.apply(this, args);
}, wait);
};
}
const noop = (v) => v;
//#endregion
export { debounce, logger, noop, resolveComma, setSilent, toArray };