### Install hugeicons-react (Legacy) Source: https://context7.com/hugeicons/hugeicons-react/llms.txt Commands to install the deprecated hugeicons-react package using npm, yarn, or pnpm. This is not recommended for new projects. ```bash npm install hugeicons-react # or yarn add hugeicons-react # or pnpm add hugeicons-react ``` -------------------------------- ### Install Official Hugeicons React Packages Source: https://github.com/hugeicons/hugeicons-react/blob/main/README.md Commands to install the official '@hugeicons/react' renderer and '@hugeicons/core-free-icons' package pack using different package managers. ```bash npm install @hugeicons/react @hugeicons/core-free-icons # or yarn add @hugeicons/react @hugeicons/core-free-icons # or pnpm add @hugeicons/react @hugeicons/core-free-icons # or bun add @hugeicons/react @hugeicons/core-free-icons ``` -------------------------------- ### Migrate from hugeicons-react to Official Packages Source: https://context7.com/hugeicons/hugeicons-react/llms.txt Steps to uninstall the deprecated hugeicons-react package and install the official `@hugeicons/react` and `@hugeicons/core-free-icons` packages. ```bash # Step 1: Remove deprecated package npm uninstall hugeicons-react # Step 2: Install official packages npm install @hugeicons/react @hugeicons/core-free-icons ``` -------------------------------- ### Usage with Official Hugeicons Packages Source: https://context7.com/hugeicons/hugeicons-react/llms.txt Example of using the official `@hugeicons/react` renderer with icons from `@hugeicons/core-free-icons`. This demonstrates the new integration pattern with props like `icon`, `size`, `color`, and `strokeWidth`. ```tsx import { HugeiconsIcon } from "@hugeicons/react"; import { Home01Icon, Settings01Icon, UserIcon } from "@hugeicons/core-free-icons"; export default function SidebarExample() { return (
Dashboard
Customers
Settings
); } ``` -------------------------------- ### GET /picomatch Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html The core function to create a matcher from one or more glob patterns. It returns a function that evaluates a string against the provided glob. ```APIDOC ## GET /picomatch ### Description Creates a matcher function from one or more glob patterns. The returned function takes a string to match as its first argument and returns true if the string is a match. ### Method GET ### Endpoint /picomatch ### Parameters #### Query Parameters - **glob** (String|Array) - Required - One or more glob patterns to match against. - **options** (Object) - Optional - Configuration options for the matching process (e.g., dot, bash, capture). ### Request Example { "glob": "*.js", "options": { "dot": true } } ### Response #### Success Response (200) - **isMatch** (Boolean) - Whether the input string matches the glob pattern. - **result** (Object) - Detailed match information if returnState is enabled. #### Response Example { "isMatch": true, "output": "*.js" } ``` -------------------------------- ### AI/Vibe-Coding Correction Prompt for Hugeicons Source: https://github.com/hugeicons/hugeicons-react/blob/main/README.md A prompt to provide to AI coding assistants to correct their usage of the deprecated 'hugeicons-react' package and refactor to the official Hugeicons React setup. ```text You used a deprecated package (hugeicons-react). Refactor to the official Hugeicons React setup: 1) Remove hugeicons-react 2) Install: npm i @hugeicons/react @hugeicons/core-free-icons 3) Use: - import { HugeiconsIcon } from "@hugeicons/react" - import { SomeIcon } from "@hugeicons/core-free-icons" - Render: Output the final working code and the final package.json dependencies. ``` -------------------------------- ### Mathematical Tick Generation Utilities Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Functions to calculate tick intervals and values for data visualization axes. These utilities handle start, stop, and count parameters to generate evenly spaced numeric ticks. ```javascript function ticks(start, stop, count) { stop = +stop, start = +start, count = +count; if (!(count > 0)) return []; if (start === stop) return [start]; const reverse = stop < start, [i1, i2, inc] = reverse ? tickSpec(stop, start, count) : tickSpec(start, stop, count); if (!(i2 >= i1)) return []; const n = i2 - i1 + 1, ticks = new Array(n); if (reverse) { if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) / -inc; else for (let i = 0; i < n; ++i) ticks[i] = (i2 - i) * inc; } else { if (inc < 0) for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) / -inc; else for (let i = 0; i < n; ++i) ticks[i] = (i1 + i) * inc; } return ticks; } ``` -------------------------------- ### GET /scan Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Analyzes a provided glob pattern string and returns an object containing metadata about the pattern, including whether it is a glob, its base path, and if it is negated. ```APIDOC ## GET /scan ### Description Analyzes a glob pattern string to extract structural information like base paths, glob status, and negation flags. ### Method GET ### Endpoint /scan ### Parameters #### Query Parameters - **input** (string) - Required - The glob pattern string to scan. - **parts** (boolean) - Optional - Whether to return individual path parts. - **scanToEnd** (boolean) - Optional - Whether to scan the entire string even after identifying a glob. ### Request Example { "input": "foo/bar/*.js" } ### Response #### Success Response (200) - **isGlob** (boolean) - Indicates if the input is a glob pattern. - **input** (string) - The original input string. - **base** (string) - The leading non-glob path. - **glob** (string) - The actual glob pattern part. #### Response Example { "isGlob": true, "input": "foo/bar/*.js", "base": "foo/bar", "glob": "*.js" } ``` -------------------------------- ### Configure Available Size Options Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Determines which size metrics are available based on provided configuration options. Returns an array of property names like renderedLength, gzipLength, or brotliLength. ```javascript const getAvailableSizeOptions = (options) => { const availableSizeProperties = ["renderedLength"]; if (options.gzip) { availableSizeProperties.push("gzipLength"); } if (options.brotli) { availableSizeProperties.push("brotliLength"); } return availableSizeProperties; }; ``` -------------------------------- ### Create Continuous Scale Transformer Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Initializes a continuous scale transformer that handles domain-to-range mapping. It supports custom interpolation, clamping, and unknown value handling. ```javascript function transformer$1() { var domain = unit, range = unit, interpolate$1 = interpolate, transform, untransform, unknown, clamp = identity$1, piecewise, output, input; function rescale() { var n = Math.min(domain.length, range.length); if (clamp !== identity$1) clamp = clamper(domain[0], domain[n - 1]); piecewise = n > 2 ? polymap : bimap; output = input = null; return scale; } function scale(x) { return x == null || isNaN(x = +x) ? unknown : (output || (output = piecewise(domain.map(transform), range, interpolate$1)))(transform(clamp(x))); } // ... scale methods omitted for brevity return function(t, u) { transform = t, untransform = u; return rescale(); }; } ``` -------------------------------- ### D3 Range and Interpolator Initialization Utility Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Utility functions for initializing D3 scales' domain and range, and interpolators. These functions handle different argument counts to set up scales for visualization purposes. They are generic and can be used with various D3 scale types. ```javascript function initRange(domain, range) { switch (arguments.length) { case 0: break; case 1: this.range(domain); break; default: this.range(range).domain(domain); break; } return this; } function initInterpolator(domain, interpolator) { switch (arguments.length) { case 0: break; case 1: { if (typeof domain === "function") t ``` -------------------------------- ### Basic Icon Usage in React (Legacy) Source: https://context7.com/hugeicons/hugeicons-react/llms.txt Demonstrates how to import and render icons as React components using the hugeicons-react library. Icons are rendered with default size (24px) and color (#000000). ```jsx import { Home01Icon, MarketingIcon } from "hugeicons-react"; function App() { return (
{/* Default size is 24px, default color is #000000 */}
); } export default App; ``` -------------------------------- ### Tick Specification Calculation (JavaScript) Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html The `tickSpec` function calculates parameters for generating tick values on an axis, given a start, stop, and desired count. It determines the optimal interval (`inc`) and the start/end points for the ticks. ```javascript const e10 = Math.sqrt(50), e5 = Math.sqrt(10), e2 = Math.sqrt(2); function tickSpec(start, stop, count) { const step = (stop - start) / Math.max(0, count), power = Math.floor(Math.log10(step)), error = step / Math.pow(10, power), factor = error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1; let i1, i2, inc; if (power < 0) { inc = Math.pow(10, -power) / factor; i1 = Math.round(start * inc); i2 = Math.round(stop * inc); if (i1 / inc < start) ++i1; if (i2 / inc > stop) --i2; inc = -inc; } else { inc = Math.pow(10, power) * factor; i1 = Math.round(start / inc); i2 = Math.round(stop / inc); } return {i1, i2, inc}; } ``` -------------------------------- ### Compile Glob Pattern to Regex Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Demonstrates how to parse a glob pattern and compile it into a regular expression using picomatch.compileRe. This is useful for converting glob-based matching logic into standard regex objects. ```javascript const picomatch = require('picomatch'); const state = picomatch.parse('*.js'); console.log(picomatch.compileRe(state)); //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/ ``` -------------------------------- ### Byte Formatting Utility Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html A utility module for parsing and formatting byte sizes into human-readable strings. It supports various units from bytes to petabytes. ```javascript var map = { b: 1, kb: 1 << 10, mb: 1 << 20, gb: 1 << 30, tb: Math.pow(1024, 4), pb: Math.pow(1024, 5), }; ``` -------------------------------- ### Convert Regex Source to RegExp Object Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Shows how to convert a regex source string into a native RegExp object using picomatch.toRegex. It handles optional flags and provides error handling for invalid patterns. ```javascript const picomatch = require('picomatch'); const { output } = picomatch.parse('*.js'); console.log(picomatch.toRegex(output)); //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/ ``` -------------------------------- ### Icon Project Data Structure Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html A JSON representation of the icon library tree, mapping file paths to unique identifiers for the React icon components. ```json const data = {"version":2,"tree":{"name":"root","children":[{"name":"hugeicons-react.js","children":[{"name":"src/hugeicons-react.ts","uid":"3c2fdcfe-1"}]},{"name":"icons/AbacusIcon.js","children":[{"name":"src/icons/AbacusIcon.tsx","uid":"3c2fdcfe-3"}]}]}}; ``` -------------------------------- ### Test Input with Regex using picomatch.test Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Tests an input string against a provided regular expression. It returns an object containing the match status, the match results, and the processed output string. ```javascript const picomatch = require('picomatch'); console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/)); // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' } ``` -------------------------------- ### Implement Number Formatting Types Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html A map of formatting functions that handle different types like exponential notation, percentages, and base conversions (binary, octal, hexadecimal). ```javascript var formatTypes = { "%": (x, p) => (x * 100).toFixed(p), "b": (x) => Math.round(x).toString(2), "c": (x) => x + "", "d": formatDecimal, "e": (x, p) => x.toExponential(p), "f": (x, p) => x.toFixed(p), "g": (x, p) => x.toPrecision(p), "o": (x) => Math.round(x).toString(8), "p": (x, p) => formatRounded(x * 100, p), "r": formatRounded, "s": formatPrefixAuto, "X": (x) => Math.round(x).toString(16).toUpperCase(), "x": (x) => Math.round(x).toString(16) }; ``` -------------------------------- ### Byte Formatting and Parsing Utility (JavaScript) Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Provides functions to format byte values into human-readable strings (e.g., KB, MB, GB) and to parse string representations back into byte integers. It handles various options for decimal places, separators, and units. This utility is crucial for displaying file sizes accurately. ```javascript var formatDecimalsRegExp = /\.0+$/; var formatThousandsRegExp = /\B(?=(\d{3})+(?!\d))/g; var map = { b: 1, kb: 1024, mb: 1048576, gb: 1073741824, tb: 1099511627776, pb: 1125899906842624 }; var parseRegExp = /^(\d*\.?\d+)?(kb|mb|gb|tb|pb)$/i; /** * Convert the given value in bytes into a string or parse to string to an integer in bytes. * * @param {string|number} value * @param {{ * case: [string], * decimalPlaces: [number] * fixedDecimals: [boolean] * thousandsSeparator: [string] * unitSeparator: [string] * }} [options] bytes options. * * @returns {string|number|null} */ function bytes(value, options) { if (typeof value === 'string') { return parse(value); } if (typeof value === 'number') { return format(value, options); } return null; } /** * Format the given value in bytes into a string. * * If the value is negative, it is kept as such. If it is a float, * it is rounded. * * @param {number} value * @param {object} [options] * @param {number} [options.decimalPlaces=2] * @param {number} [options.fixedDecimals=false] * @param {string} [options.thousandsSeparator=] * @param {string} [options.unit=] * @param {string} [options.unitSeparator=] * * @returns {string|null} * @public */ function format(value, options) { if (!Number.isFinite(value)) { return null; } var mag = Math.abs(value); var thousandsSeparator = (options && options.thousandsSeparator) || ''; var unitSeparator = (options && options.unitSeparator) || ''; var decimalPlaces = (options && options.decimalPlaces !== undefined) ? options.decimalPlaces : 2; var fixedDecimals = Boolean(options && options.fixedDecimals); var unit = (options && options.unit) || ''; if (!unit || !map[unit.toLowerCase()]) { if (mag >= map.pb) { unit = 'PB'; } else if (mag >= map.tb) { unit = 'TB'; } else if (mag >= map.gb) { unit = 'GB'; } else if (mag >= map.mb) { unit = 'MB'; } else if (mag >= map.kb) { unit = 'KB'; } else { unit = 'B'; } } var val = value / map[unit.toLowerCase()]; var str = val.toFixed(decimalPlaces); if (!fixedDecimals) { str = str.replace(formatDecimalsRegExp, '$1'); } if (thousandsSeparator) { str = str.split('.').map(function (s, i) { return i === 0 ? s.replace(formatThousandsRegExp, thousandsSeparator) : s }).join('.'); } return str + unitSeparator + unit; } /** * Parse the string value into an integer in bytes. * * If no unit is given, it is assumed the value is in bytes. * * @param {number|string} val * * @returns {number|null} * @public */ function parse(val) { if (typeof val === 'number' && !isNaN(val)) { return val; } if (typeof val !== 'string') { return null; } // Test if the string passed is valid var results = parseRegExp.exec(val); var floatValue; var unit = 'b'; if (!results) { // Nothing could be extracted from the given string floatValue = parseInt(val, 10); unit = 'b'; } else { // Retrieve the value and the unit floatValue = parseFloat(results[1]); unit = results[4].toLowerCase(); } if (isNaN(floatValue)) { return null; } return Math.floor(map[unit] * floatValue); } var bytesExports = requireBytes(); ``` -------------------------------- ### Initialize and Resize Chart Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html This script initializes a chart on the DOM content load and re-renders it whenever the browser window is resized. It utilizes a global data object and a default draw function to update the chart dimensions. ```javascript const run = () => { const width = window.innerWidth; const height = window.innerHeight; const chartNode = document.querySelector("main"); drawChart.default(chartNode, data, width, height); }; window.addEventListener('resize', run); document.addEventListener('DOMContentLoaded', run); ``` -------------------------------- ### Color Formatting and Clamping Utilities Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Helper functions to format color objects into CSS-compatible strings and ensure color components remain within valid ranges (0-255 for RGB, 0-1 for opacity). ```javascript function rgb_formatRgb() { const a = clampa(this.opacity); return `${a === 1 ? "rgb(" : "rgba("}${clampi(this.r)}, ${clampi(this.g)}, ${clampi(this.b)}${a === 1 ? ")" : `, ${a})`}`; } function clampa(opacity) { return isNaN(opacity) ? 1 : Math.max(0, Math.min(1, opacity)); } function clampi(value) { return Math.max(0, Math.min(255, Math.round(value) || 0)); } ``` -------------------------------- ### Control Icon Size in React (Legacy) Source: https://context7.com/hugeicons/hugeicons-react/llms.txt Shows how to adjust the size of icons rendered from the hugeicons-react library using the `size` prop, specifying dimensions in pixels. ```jsx import { Home01Icon } from "hugeicons-react"; function IconSizes() { return (
{/* Default size is 24px */} {/* Custom sizes in pixels */}
); } export default IconSizes; ``` -------------------------------- ### Token Management Helpers Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Helper functions for managing the tokenization state, including advancing the cursor, peeking at characters, and pushing new tokens onto the stack. ```javascript const eos = () => state.index === len - 1; const peek = state.peek = (n = 1) => input[state.index + n]; const advance = state.advance = () => input[++state.index] || ''; const push = tok => { if (tok.value || tok.output) append(tok); if (prev && prev.type === 'text' && tok.type === 'text') { prev.output = (prev.output || prev.value) + tok.value; prev.value += tok.value; return; } tok.prev = prev; tokens.push(tok); prev = tok; }; ``` -------------------------------- ### Path and String Manipulation Utilities Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Provides functions for escaping regex special characters, converting path separators, removing backslashes, and extracting basenames from paths. It also includes utilities for removing prefixes and wrapping output strings for pattern matching. ```javascript const REGEX_SPECIAL_CHARS_GLOBAL = /([.*+?^=!:${}()|[\]/\\])/g; const REGEX_BACKSLASH = /\\/g; const REGEX_REMOVE_BACKSLASH = /\\(.)|\\/g; exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str); exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1'); exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/'); exports.isWindows = () => { if (typeof navigator !== 'undefined' && navigator.platform) { const platform = navigator.platform.toLowerCase(); return platform === 'win32' || platform === 'windows'; } if (typeof process !== 'undefined' && process.platform) { return process.platform === 'win32'; } return false; }; exports.removeBackslashes = str => { return str.replace(REGEX_REMOVE_BACKSLASH, match => { return match === '\\\' ? '' : match; }); }; exports.escapeLast = (input, char, lastIdx) => { const idx = input.lastIndexOf(char, lastIdx); if (idx === -1) return input; if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1); return `${input.slice(0, idx)}\\${input.slice(idx)}`; }; exports.removePrefix = (input, state = {}) => { let output = input; if (output.startsWith('./')) { output = output.slice(2); state.prefix = './'; } return output; }; exports.wrapOutput = (input, state = {}, options = {}) => { const prepend = options.contains ? '' : '^'; const append = options.contains ? '' : '$'; let output = `${prepend}(?:${input})${append}`; if (state.negated === true) { output = `(?:^(?!${output}).*$)`; } return output; }; exports.basename = (path, { windows } = {}) => { const segs = path.split(windows ? /[\\/]/ : '/'); const last = segs[segs.length - 1]; if (last === '') { return segs[segs.length - 2]; } return last; }; ``` -------------------------------- ### Component Lifecycle and Rendering (JavaScript) Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Manages the instantiation, rendering, and updating of React components. It handles component lifecycles, state and props updates, and integrates with React's internal mechanisms for efficient DOM diffing and patching. ```javascript function j$1(n,u,t,i,r,o,e,f,c,s){var a,h,p,v,y,g,m,b,C,S,M,P,I,A,H,L,T,F=u.type;if(void 0!==u.constructor)return null;128&t.__u&&(c=!!(32&t.__u),o=[f=u.__e=t.__e]),(a=l$1.__b)&&a(u);n:if('function'==typeof F)try{if(b=u.props,C='prototype'in F&&F.prototype.render,S=(a=F.contextType)&&i[a.__c],M=a?S?S.props.value:a.__:i,t.__c?(m=(h=u.__c=t.__c).__=h.__E):(C?u.__c=h=new F(b,M):(u.__c=h=new x$1(b,M),h.constructor=F,h.render=B$1),S&&S.sub(h),h.props=b,h.state||(h.state={}),h.context=M,h.__n=i,p=!0,h.__h=[],h._sb=[]),C&&null==h.__s&&(h.__s=h.state),C&&null!=F.getDerivedStateFromProps&&(h.__s==h.state&&(h.__s=w$1({},h.__s)),w$1(h.__s,F.getDerivedStateFromProps(b,h.__s))),v=h.props,y=h.state,h.__v=u,p)C&&null==F.getDerivedStateFromProps&&null!=h.componentWillMount&&h.componentWillMount(),C&&null!=h.componentDidMount&&h.__h.push(h.componentDidMount);else{if(C&&null==F.getDerivedStateFromProps&&b!==v&&null!=h.componentWillReceiveProps&&h.componentWillReceiveProps(b,M),!h.__e&&(null!=h.shouldComponentUpdate&&!1===h.shouldComponentUpdate(b,h.__s,M)||u.__v==t.__v)){for(u.__v!=t.__v&&(h.props=b,h.state=h.__s,h.__d=!1),u.__e=t.__e,u.__k=t.__k,u.__k.some(function(n){n&&(n.__=u);}),P=0;P { if (Array.isArray(glob)) { const fns = glob.map(input => picomatch(input, options, returnState)); return str => { for (const isMatch of fns) { const state = isMatch(str); if (state) return state; } return false; }; } const regex = isState ? picomatch.compileRe(glob, options) : picomatch.makeRe(glob, options, false, true); return (input, returnObject = false) => { const { isMatch, match, output } = picomatch.test(input, regex, options, { glob, posix }); // ... result handling ... }; }; ``` -------------------------------- ### React Utility Function for Constants Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Initializes and returns constants, ensuring they are only required once. This pattern is used to manage application-wide constants efficiently, preventing redundant loading. ```javascript var constants$1; var hasRequiredConstants; function requireConstants () { if (hasRequiredConstants) return constants$1; hasRequiredConstants = 1; const WIN_SLASH = '\\\\/'; const WIN_NO_SLASH = `[^${WI ``` -------------------------------- ### Create Custom Filter Logic Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Implements a filtering mechanism that evaluates bundle and file identifiers against include/exclude glob patterns. It uses picomatch to generate test functions for matching. ```javascript const createFilter = (include, exclude) => { const includeMatchers = ensureArray(include).map(getMatcher); const excludeMatchers = ensureArray(exclude).map(getMatcher); return (bundleId, id) => { for (let i = 0; i < excludeMatchers.length; ++i) { const { bundleTest, fileTest } = excludeMatchers[i]; if (bundleTest.test(bundleId) && fileTest.test(id)) return false; } for (let i = 0; i < includeMatchers.length; ++i) { const { bundleTest, fileTest } = includeMatchers[i]; if (bundleTest.test(bundleId) && fileTest.test(id)) return true; } return !includeMatchers.length; }; }; ``` -------------------------------- ### Bytes Utility Functions Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Methods for formatting numeric byte values into strings and parsing byte-string representations into integers. ```APIDOC ## bytes(value, options) ### Description Converts a value in bytes into a formatted string or parses a string representation into an integer in bytes. ### Method N/A (Utility Function) ### Parameters - **value** (string|number) - Required - The value to convert or parse. - **options** (object) - Optional - Formatting options (decimalPlaces, fixedDecimals, thousandsSeparator, unitSeparator). ### Request Example bytes('1kb'); // Returns 1024 bytes(1024, { unit: 'KB' }); // Returns '1KB' ## format(value, options) ### Description Formats a numeric byte value into a human-readable string. ### Parameters - **value** (number) - Required - The byte value to format. - **options** (object) - Optional - Configuration for formatting. ### Response - **string** - The formatted byte string (e.g., '1.5MB'). ## parse(val) ### Description Parses a string value into an integer in bytes. ### Parameters - **val** (string|number) - Required - The value to parse. ### Response - **number** - The integer representation in bytes. ``` -------------------------------- ### Color Interpolation Utilities (JavaScript) Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Provides functions for interpolating between colors, including RGB and HSL color spaces, with support for gamma correction. It defines how to interpolate color components and format them into strings. ```javascript var constant = x => () => x; function nogamma(a, b) { var d = b - a; return d ? linear$1(a, d) : constant(isNaN(a) ? b : a); } var rgb = (function rgbGamma(y) { var color = gamma(y); function rgb(start, end) { var r = color((start = rgb$1(start)).r, (end = rgb$1(end)).r), g = color(start.g, end.g), b = color(start.b, end.b), opacity = nogamma(start.opacity, end.opacity); return function(t) { start.r = r(t); start.g = g(t); start.b = b(t); start.opacity = opacity(t); return start + ""; }; } rgb.gamma = rgbGamma; return rgb; })(1); // Helper functions (assumed to be defined elsewhere or within scope): // function gamma(y) { ... } // function linear$1(a, d) { ... } // function rgb$1(c) { ... } // Parses color string/object ``` -------------------------------- ### Color Parsing and RGB/HSL Object Management Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Functions to parse color strings into color objects and define the Rgb and Hsl prototypes. These utilities handle input validation, normalization, and conversion between different color representations. ```javascript function color(format) { var m, l; format = (format + "").trim().toLowerCase(); return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) : l === 3 ? new Rgb((m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), ((m & 0xf) << 4) | (m & 0xf), 1) : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) : l === 4 ? rgba((m >> 12 & 0xf) | (m >> 8 & 0xf0), (m >> 8 & 0xf) | (m >> 4 & 0xf0), (m >> 4 & 0xf) | (m & 0xf0), (((m & 0xf) << 4) | (m & 0xf)) / 0xff) : null) : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) : null; } function Rgb(r, g, b, opacity) { this.r = +r; this.g = +g; this.b = +b; this.opacity = +opacity; } function Hsl(h, s, l, opacity) { this.h = +h; this.s = +s; this.l = +l; this.opacity = +opacity; } ``` -------------------------------- ### Parse Glob Pattern Input Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html The parse function validates the input string, applies replacements, and initializes the state for tokenization. It enforces length constraints and sets up the token stream based on provided options. ```javascript const parse = (input, options) => { if (typeof input !== 'string') { throw new TypeError('Expected a string'); } input = REPLACEMENTS[input] || input; const opts = { ...options }; const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH; let len = input.length; if (len > max) { throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`); } const bos = { type: 'bos', value: '', output: opts.prepend || '' }; const tokens = [bos]; return { tokens, input, opts }; }; ``` -------------------------------- ### Sorting Functions (JavaScript) Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Provides standard `ascending` and `descending` comparison functions for sorting. These functions handle null values by returning `NaN` and correctly compare numbers and other comparable types. ```javascript function ascending(a, b) { return a == null || b == null ? NaN : a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN; } function descending(a, b) { return a == null || b == null ? NaN : b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN; } ``` -------------------------------- ### Manage Globstar and Star Patterns in JavaScript Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html This code manages the interpretation and transformation of '*' and '**' (globstar) patterns in file path matching. It handles various edge cases, including consecutive globstars, integration with other pattern types like extglobs and braces, and options for bash compatibility and regex output. It modifies the parser's state and output based on the pattern's context. ```javascript if (prev && (prev.type === 'globstar' || prev.star === true)) { prev.type = 'star'; prev.star = true; prev.value += value; prev.output = star; state.backtrack = true; state.globstar = true; consume(value); continue; } let rest = remaining(); if (opts.noextglob !== true && /^\([^?]/.test(rest)) { extglobOpen('star', value); continue; } if (prev.type === 'star') { if (opts.noglobstar === true) { consume(value); continue; } const prior = prev.prev; const before = prior.prev; const isStart = prior.type === 'slash' || prior.type === 'bos'; const afterStar = before && (before.type === 'star' || before.type === 'globstar'); if (opts.bash === true && (!isStart || (rest[0] && rest[0] !== '/'))) { push({ type: 'star', value, output: '' }); continue; } const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace'); const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren'); if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) { push({ type: 'star', value, output: '' }); continue; } // strip consecutive `/**` while (rest.slice(0, 3) === '/**') { const after = input[state.index + 4]; if (after && after !== '/') { break; } rest = rest.slice(3); consume('/**', 3); } if (prior.type === 'bos' && eos()) { prev.type = 'globstar'; prev.value += value; prev.output = globstar(opts); state.output = prev.output; state.globstar = true; consume(value); continue; } if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) { state.output = state.output.slice(0, -(prior.output + prev.output).length); prior.output = `(?:${prior.output}`; prev.type = 'globstar'; prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$'); prev.value += value; state.globstar = true; state.output += prior.output + prev.output; consume(value); continue; } if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') { const end = rest[1] !== void 0 ? '|$' : ''; state.output = state.output.slice(0, -(prior.output + prev.output).length); prior.output = `(?:${prior.output}`; prev.type = 'globstar'; prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`; prev.value += value; state.output += prior.output + prev.output; state.globstar = true; consume(value + advance()); push({ type: 'slash', value: '/', output: '' }); continue; } if (prior.type === 'bos' && rest[0] === '/') { prev.type = 'globstar'; prev.value += value; prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`; state.output = prev.output; state.globstar = true; consume(value + advance()); push({ type: 'slash', value: '/', output: '' }); continue; } // remove single star from output state.output = state.output.slice(0, -prev.output.length); // reset previous token to globstar prev.type = 'globstar'; prev.output = globstar(opts); prev.value += value; // reset output with globstar state.output += prev.output; state.globstar = true; consume(value); continue; } const token = { type: 'star', value, output: star }; if (opts.bash === true) { token.output = '.\*?'; if (prev.type === 'bos' || prev.type === 'slash') { token.output = nodot + token.output; } push(token); continue; } if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) { token.output = value; push(token); continue; } if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') { if (prev.type === 'dot') { state.output += NO_DOT_SLASH; prev.output += NO_DOT_SLASH; } else if (opts.dot === true) { state.output += NO_DOTS_SLASH; prev.output += NO_DOTS_SLASH; } else { state.output += nodot; prev.output += nodot; } if (peek() !== '*') { state.output += ONE_CHAR; prev.output += ONE_CHAR; } } push(token); } ``` -------------------------------- ### picomatch.test Source: https://github.com/hugeicons/hugeicons-react/blob/main/stats.html Tests an input string against a regular expression to determine if it matches. ```APIDOC ## POST /picomatch/test ### Description Tests an input string against a given regex pattern to check for a match. ### Method POST ### Endpoint /picomatch/test ### Parameters #### Request Body - **input** (String) - Required - The string to test. - **regex** (RegExp) - Required - The regular expression to test against. - **options** (Object) - Optional - Configuration options for the test. ### Request Example { "input": "foo/bar", "regex": "/^(?:([^/]*?)\/([^/]*?))$/" } ### Response #### Success Response (200) - **isMatch** (Boolean) - Whether the input matched the regex. - **match** (Array) - The match results. - **output** (String) - The processed output string. #### Response Example { "isMatch": true, "match": ["foo/", "foo", "bar"], "output": "foo/bar" } ```