(poly: unknown)
| 59 | } |
| 60 | |
| 61 | export 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 | |
| 84 | function checkPoly(poly: ChallengeFile) { |
| 85 | if (!isPoly(poly)) throw Error('Not a PolyVinyl: ' + JSON.stringify(poly)); |
no test coverage detected