MCPcopy
hub / github.com/prisma/prisma / parseSize

Function parseSize

packages/query-plan-executor/src/formats/size.ts:27–52  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

25 * @throws Error if the value is invalid
26 */
27export function parseSize(value: string): number {
28 // If the value is a plain number, treat it as bytes
29 if (/^\d+$/.test(value)) {
30 return parseInteger(value)
31 }
32
33 // Match a number followed by a unit
34 const match = value.match(/^([\d.]+)\s*([A-Za-z]+)$/)
35 if (!match) {
36 throw new Error(`Invalid size format: ${value}`)
37 }
38
39 const [_, numStr, unit] = match
40 const num = parseFloat(numStr)
41
42 if (Number.isNaN(num)) {
43 throw new Error(`Invalid size value: ${numStr}`)
44 }
45
46 const multiplier = sizeUnits[unit]
47 if (multiplier === undefined) {
48 throw new Error(`Unknown size unit: ${unit}`)
49 }
50
51 return Math.floor(num * multiplier)
52}

Callers 3

size.test.tsFile · 0.90
parseSizeFromHeadersFunction · 0.90
handleStartFunction · 0.85

Calls 1

parseIntegerFunction · 0.90

Tested by

no test coverage detected