pixi.js
Version:
<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">
1 lines • 3.13 kB
Source Map (JSON)
{"version":3,"file":"clean.mjs","sources":["../../../src/utils/data/clean.ts"],"sourcesContent":["/**\n * Takes a hash and removes all the `undefined`/`null` values from it.\n * In PixiJS, we tend to null properties instead of using 'delete' for performance reasons.\n * However, in some cases, this could be a problem if the hash grows too large over time,\n * this function can be used to clean a hash.\n * @param hash - The hash to clean.\n * @returns A new hash with all the `undefined`/`null` values removed.\n * @category utils\n * @internal\n */\nexport function cleanHash<T>(hash: Record<string, T>): Record<string, T>\n{\n let clean = false;\n\n for (const i in hash)\n {\n // eslint-disable-next-line eqeqeq\n if (hash[i] == undefined)\n {\n clean = true;\n break;\n }\n }\n\n if (!clean) return hash;\n\n const cleanHash = Object.create(null);\n\n for (const i in hash)\n {\n const value = hash[i];\n\n if (value)\n {\n cleanHash[i] = value;\n }\n }\n\n return cleanHash;\n}\n\n/**\n * Removes all `undefined`/`null` elements from the given array and compacts the array.\n *\n * This function iterates through the array, shifting non-undefined elements to the left\n * to fill gaps created by `undefined` elements. The length of the array is then adjusted\n * to remove the trailing `undefined` elements.\n * @param arr - The array to be cleaned.\n * @returns The cleaned array with all `undefined` elements removed.\n * @example\n * // Example usage:\n * const arr = [1, undefined, 2, undefined, 3];\n * const cleanedArr = cleanArray(arr);\n * console.log(cleanedArr); // Output: [1, 2, 3]\n * @category utils\n * @internal\n */\nexport function cleanArray<T>(arr: T[]): T[]\n{\n let offset = 0;\n\n for (let i = 0; i < arr.length; i++)\n {\n // eslint-disable-next-line eqeqeq\n if (arr[i] == undefined)\n {\n offset++;\n }\n else\n {\n arr[i - offset] = arr[i];\n }\n }\n\n arr.length -= offset;\n\n return arr;\n}\n"],"names":["cleanHash"],"mappings":";AAUO,SAAS,UAAa,IAC7B,EAAA;A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