* Validation utilities for Kubernetes resource quantities (CPU and memory). / * Matches K8s CPU quantities: integer or decimal, optionally with 'm' suffix (millicores). */
// Source: https://github.com/jonwiggins/optio | License: MIT | Copyright 2026 Optio Contributors
// Provided via justclaw.it.com; keep this notice with the code.
/**
* Validation utilities for Kubernetes resource quantities (CPU and memory).
*/
/** Matches K8s CPU quantities: integer or decimal, optionally with 'm' suffix (millicores). */
const CPU_REGEX = /^\d+(\.\d+)?m?$/;
/** Matches K8s memory quantities: integer with optional binary suffix (Ki, Mi, Gi, Ti). */
const MEMORY_REGEX = /^\d+(\.\d+)?(Ki|Mi|Gi|Ti)?$/;
/**
* Parse a CPU quantity string into millicores.
* Examples: "500m" → 500, "1" → 1000, "2.5" → 2500
*/
export function parseCpuMillicores(value: string): number {
if (value.endsWith("m")) {
return parseFloat(value.slice(0, -1));
}
return parseFloat(value) *
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key