MCPcopy Create free account
hub / github.com/BCsabaEngine/svelteesp32 / parseSize

Function parseSize

src/commandLine.ts:156–176  ·  view source on GitHub ↗
(value: string, name: string)

Source from the content-addressed store, hash-verified

154}
155
156function parseSize(value: string, name: string): number {
157 const trimmed = value.trim();
158 const match = trimmed.match(/^(\d+(?:\.\d+)?)\s*([KMkm])?$/);
159
160 if (!match || !match[1])
161 throw new Error(`${name} must be a positive number with optional k/K (×1024) or m/M (×1024²) suffix: ${value}`);
162
163 const numericPart = Number(match[1]);
164 const suffix = match[2]?.toLowerCase();
165
166 let bytes: number;
167 if (suffix === 'k') bytes = numericPart * 1024;
168 else if (suffix === 'm') bytes = numericPart * 1024 * 1024;
169 else bytes = numericPart;
170
171 bytes = Math.round(bytes);
172
173 if (bytes <= 0 || !Number.isFinite(bytes)) throw new Error(`${name} must be a positive integer: ${value}`);
174
175 return bytes;
176}
177
178function findRcFile(customConfigPath?: string): string | undefined {
179 // If --config specified, use that exclusively

Callers 3

validateSizeOptionFunction · 0.85
applyFlagFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected