Throws what `fail` makes of the problem unless `script` is one init script.
(script: unknown, fail: (problem: string) => Error)
| 82 | |
| 83 | /** Throws what `fail` makes of the problem unless `script` is one init script. */ |
| 84 | function assertInitScript(script: unknown, fail: (problem: string) => Error): asserts script is WebInitScript { |
| 85 | if (typeof script === 'string' || typeof script === 'function') return; |
| 86 | if (typeof script !== 'object' || script === null || Array.isArray(script)) { |
| 87 | const got = script === null ? 'null' : Array.isArray(script) ? 'an array' : typeof script; |
| 88 | throw fail(`must be a string of source, a { path }, or a function, got ${got}`); |
| 89 | } |
| 90 | const unknown = Object.keys(script).filter((key) => key !== 'path'); |
| 91 | if (unknown.length > 0) throw fail(`takes only path, got ${unknown.join(', ')}`); |
| 92 | if (!('path' in script) || typeof script.path !== 'string' || script.path === '') throw fail('path must be a non-empty string'); |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * The page source of one script. A function is called with its JSON argument |
no test coverage detected