{"version":3,"sources":["jsdelivr-header.js","/npm/@agtm/util@4.4.0/src/index.mjs"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OCES,kBAAqB,kBACrB,YAAe,mBACf,aAAgB,0BAClB,UAAW,mCACK,UAAa,8BAa7B,SAAS,UAAW,GACzB,OAAO,QAAQ,cAAc,GAC/B,QAEO,eAAe,SAAU,GAC9B,OAAO,KAAK,YAAY,SAAS,GACnC,QAEO,eAAe,aAAc,GAElC,MAAM,EAAQ,EAAc,MAAM,KAQlC,MAAO,CALS,EAAM,GAGT,EAAM,MAAM,GAG3B,QAgBO,eAAe,aAEpB,OADc,IAAI,OAAQ,MACb,MAAM,MAAM,MAAM,GAAG,KAAK,KACzC,gBAUe,SAAS,4BAA6B,EAAc,EAAO,EAAO,GAAI,OAAW,GAE9F,GAAI,EADmB,KAAK,MAAM,EAAM,OAAS,IACX,EAAG,CACvC,MAAM,EAAc,EAAe,EAAM,OAAU,IACnD,EAAW,EAAS,GAAc,QAAQ,IAAI,GAAG,KACnD,CACF,QAsBO,eAAe,KAAM,EAAI,EAAS,EAAW,KAClD,MAAM,EAAY,KAAK,MACvB,IAAI,EAAc,EAEd,QAAe,IAEnB,UAAkB,IAAX,GAAsB,CAG3B,GAFA,EAAc,KAAK,MAAQ,EAEvB,GAAe,EACjB,MAAM,IAAI,MAAM,iBAGZ,MAAM,GACZ,QAAe,GACjB,CAEA,OAAO,CACT,QAOO,SAAS,yBACd,MAAO,GAAG,KAAK,MAAM,SAAS,MAAM,KAAK,SAAS,SAAS,IAAI,UAAU,EAAG,KAC9E,QAGE,MAcA","file":"/npm/@agtm/util@4.4.0/src/index.mjs","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@agtm/util@4.4.0/src/index.mjs\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * **Created on 10/04/2021**\n *\n * index.js\n * @author André Timermann <andre@timermann.com.br>\n *\n */\n\nimport { fileURLToPath } from 'node:url'\nimport { dirname } from 'node:path'\nimport { readFile } from 'node:fs/promises'\nimport Multi from './multi.mjs'\nimport { setTimeout as sleep } from 'node:timers/promises'\n\n/**\n * Old __dirname\n *\n * Example of use:\n *\n * __dirname(import.meta.url)\n *\n * @param importMetaURL\n * @returns {string}\n * @private\n */\nexport function __dirname (importMetaURL) {\n  return dirname(fileURLToPath(importMetaURL))\n}\n\nexport async function loadJson (path) {\n  return JSON.parse(await readFile(path))\n}\n\nexport async function parseCommand (commandString) {\n  // Divida a string do comando em um array usando espaço como delimitador\n  const parts = commandString.split(' ')\n\n  // O comando é o primeiro item do array\n  const command = parts[0]\n\n  // Os argumentos são todos os itens restantes do array\n  const args = parts.slice(1)\n\n  return [command, args]\n}\n\n/**\n * Asynchronously generates and returns the current stack trace.\n *\n * This function creates a new Error object, extracts its stack trace,\n * and processes the stack trace to remove the first line (which would\n * indicate this function as the source of the Error).\n *\n * @returns {Promise<String>} A promise that resolves with a string representing the stack trace.\n *\n * @example\n *\n *  import { stacktrace } from '@agtm/util';\n *  console.log(stacktrace());\n*/\nexport async function stacktrace () {\n  const stack = new Error().stack\n  return stack.split('\\n').slice(1).join('\\n')\n}\n\n/**\n * Calculates and returns the percentage of progress based on defined intervals.\n *\n * @param {number} currentCount - The current count.\n * @param {Array} items - Array of items being processed.\n * @param {number} [step=10] - Interval at which to calculate the percentage.\n * @param {Function} [callback] - Optional callback function to handle the percentage message.\n */\nexport default function calculateProgressPercentage (currentCount, items, step = 10, callback = undefined) {\n  const divisionFactor = Math.floor(items.length / step)\n  if (currentCount % divisionFactor === 0) {\n    const percentage = (currentCount / items.length) * 100\n    callback ? callback(percentage) : console.log(`${percentage}%`)\n  }\n}\n\n/**\n * Waits for the specified function to return a value other than `undefined`.\n *\n * @async\n * @function\n * @param {Function} fn - The function to check. Should return something other than `undefined` to stop waiting.\n * @param {number} timeout - Maximum time (in ms) to wait before throwing an error.\n * @param {number} [interval=100] - Time interval (in ms) to wait between checks.\n * @returns {Promise<any>} - Returns a Promise that resolves with the value returned by `fn`.\n * @throws {Error} - Throws an error if the time exceeds the specified `timeout`.\n *\n * @example\n * const testFunction = () => Math.random() > 0.9 ? 'done' : undefined;\n * try {\n *   const result = await wait(testFunction, 1000);\n *   console.log('Function returned:', result);\n * } catch (err) {\n *   console.log('Error:', err.message);\n * }\n */\nexport async function wait (fn, timeout, interval = 100) {\n  const startTime = Date.now()\n  let elapsedTime = 0\n\n  let result = await fn()\n\n  while (result === undefined) {\n    elapsedTime = Date.now() - startTime\n\n    if (elapsedTime >= timeout) {\n      throw new Error('Timeout')\n    }\n\n    await sleep(interval)\n    result = await fn()\n  }\n\n  return result\n}\n\n/**\n * Generates a unique identification number based on the current date and a random number\n *\n * @returns {string}\n */\nexport function generateUniqueIdByDate () {\n  return `${Date.now().toString(36)}${Math.random().toString(36).substring(2, 10)}`\n}\n\nexport {\n  Multi,\n  /**\n   * Creates a delay in the execution of the JavaScript code.\n   *\n   * @param {number} ms - The amount of time, in milliseconds, to delay the execution of the subsequent code.\n   *\n   * @returns {Promise} - A Promise that resolves after the specified delay.\n   *\n   * @example\n   * // Print 'Hello', wait for 2 seconds, then print 'World'.\n   * console.log('Hello');\n   * await sleep(2000);\n   * console.log('World');\n   */\n  sleep\n}\n"]}