MCPcopy Index your code
hub / github.com/deepnote/deepnote / analyzeToonEfficiency

Function analyzeToonEfficiency

packages/cli/src/utils/toon-analysis.ts:12–37  ·  view source on GitHub ↗
(
  data: unknown,
  encodedToon?: string
)

Source from the content-addressed store, hash-verified

10 * @returns Object with toon/json sizes and whether TOON is recommended
11 */
12export function analyzeToonEfficiency(
13 data: unknown,
14 encodedToon?: string
15): {
16 toonSize: number
17 jsonSize: number
18 savingsPercent: number
19 toonRecommended: boolean
20} {
21 const toonOutput = encodedToon ?? toonEncode(data)
22 // Compare against minified JSON for fair comparison
23 const jsonOutput = JSON.stringify(data)
24
25 const toonSize = toonOutput.length
26 const jsonSize = jsonOutput.length
27
28 // Calculate savings (positive = TOON is smaller)
29 // Guard against division by zero when jsonSize is 0
30 const savingsPercent = jsonSize === 0 ? 0 : ((jsonSize - toonSize) / jsonSize) * 100
31
32 // TOON is recommended if it provides at least 10% savings over minified JSON
33 // Below this threshold, JSON might be preferred for compatibility
34 const toonRecommended = savingsPercent >= 10
35
36 return { toonSize, jsonSize, savingsPercent, toonRecommended }
37}

Callers 2

outputToonFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected