UNPKG

@cosmicmind/foundationjs

Version:

A comprehensive TypeScript library offering utilities and tools for efficient project development.

133 lines (132 loc) 4.14 kB
var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const assert$1 = /* @__PURE__ */ __name((condition, data) => console.assert(condition, data), "assert$1"); const clear = /* @__PURE__ */ __name(() => console.clear(), "clear"); const count = /* @__PURE__ */ __name((label) => console.count(label), "count"); const countReset = /* @__PURE__ */ __name((label) => console.countReset(label), "countReset"); const debug = /* @__PURE__ */ __name((...data) => console.debug(...data), "debug"); const error = /* @__PURE__ */ __name((...data) => console.error(...data), "error"); const info = /* @__PURE__ */ __name((...data) => console.info(...data), "info"); const log = /* @__PURE__ */ __name((...data) => console.log(...data), "log"); const time = /* @__PURE__ */ __name((label) => console.time(label), "time"); const timeEnd = /* @__PURE__ */ __name((label) => console.timeEnd(label), "timeEnd"); const timeLog = /* @__PURE__ */ __name((label, ...data) => console.timeLog(label, data), "timeLog"); const timeStamp = /* @__PURE__ */ __name((label) => console.timeStamp(label), "timeStamp"); const trace = /* @__PURE__ */ __name((...data) => console.log(...data), "trace"); const warn = /* @__PURE__ */ __name((...data) => console.warn(...data), "warn"); const json = /* @__PURE__ */ __name((...data) => JSON.stringify(console.log(...data)), "json"); const logger = { assert: assert$1, clear, count, countReset, debug, error, info, log, time, timeEnd, timeLog, timeStamp, trace, warn, json }; const _FoundationError = class _FoundationError extends Error { get name() { return this.constructor.name; } toString() { return `[${this.name} ${this.message}]`; } }; __name(_FoundationError, "FoundationError"); let FoundationError = _FoundationError; const _FoundationTypeError = class _FoundationTypeError extends TypeError { get name() { return this.constructor.name; } toString() { return `[${this.name} ${this.message}]`; } }; __name(_FoundationTypeError, "FoundationTypeError"); let FoundationTypeError = _FoundationTypeError; const _AssertError = class _AssertError extends FoundationError { }; __name(_AssertError, "AssertError"); let AssertError = _AssertError; const assert = /* @__PURE__ */ __name((statement, message) => { if (statement) { return true; } else { throw new AssertError(message); } }, "assert"); function validate(data, ...keys) { if (null === data || "undefined" === typeof data) { return false; } if ("object" === typeof data) { for (const k of keys) { if (!(k in data)) { return false; } } } else if ("object" !== typeof data && 0 < keys.length) { return false; } return true; } __name(validate, "validate"); function guard(data, ...keys) { if (Array.isArray(data)) { return true; } return validate(data, ...keys); } __name(guard, "guard"); function guardIterator(data, ...keys) { if (guard(data) && typeof data[Symbol.iterator] === "function") { for (const x of data) { if (!validate(x, ...keys)) { return false; } } return true; } return false; } __name(guardIterator, "guardIterator"); const timeout = /* @__PURE__ */ __name((fn, delay = 25) => { const id = setTimeout(fn, delay); return () => clearTimeout(id); }, "timeout"); const assign = /* @__PURE__ */ __name((target, ...sources) => { for (const source of sources) { for (const name of Object.getOwnPropertyNames(source)) { const desc = Object.getOwnPropertyDescriptor(source, name); if ("undefined" !== typeof desc) { Object.defineProperty(target, name, desc); } } for (const symbol of Object.getOwnPropertySymbols(source)) { const desc = Object.getOwnPropertyDescriptor(source, symbol); if ("undefined" !== typeof desc) { Object.defineProperty(target, symbol, desc); } } } return target; }, "assign"); export { AssertError, FoundationError, FoundationTypeError, assert, assign, guard, guardIterator, logger, timeout };