MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / isPoly

Function isPoly

packages/shared/src/utils/polyvinyl.ts:61–82  ·  view source on GitHub ↗
(poly: unknown)

Source from the content-addressed store, hash-verified

59}
60
61export function isPoly(poly: unknown): poly is ChallengeFile {
62 function hasProperties(poly: unknown): poly is Record<string, unknown> {
63 return (
64 !!poly &&
65 typeof poly === 'object' &&
66 'contents' in poly &&
67 'name' in poly &&
68 'ext' in poly &&
69 'fileKey' in poly &&
70 'history' in poly
71 );
72 }
73
74 const hasCorrectTypes = (poly: Record<string, unknown>): boolean =>
75 typeof poly.contents === 'string' &&
76 typeof poly.name === 'string' &&
77 exts.includes(poly.ext as Ext) &&
78 typeof poly.fileKey === 'string' &&
79 Array.isArray(poly.history);
80
81 return hasProperties(poly) && hasCorrectTypes(poly);
82}
83
84function checkPoly(poly: ChallengeFile) {
85 if (!isPoly(poly)) throw Error('Not a PolyVinyl: ' + JSON.stringify(poly));

Callers 3

isFilesAllPolyFunction · 0.90
checkPolyFunction · 0.85

Calls 2

hasPropertiesFunction · 0.85
hasCorrectTypesFunction · 0.85

Tested by

no test coverage detected