This commit is contained in:
2025-08-25 20:24:23 +08:00
parent 30106e0129
commit 0ae8d7a709
1044 changed files with 321581 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import castArray from 'lodash/castArray';
import isArray from 'lodash/isArray';
export function assertType(nodes, type) {
const nodesArray = castArray(nodes);
const validate = isArray(type) ? node => type.includes(node.type) : node => type === node.type;
const invalidNode = nodesArray.find(node => !validate(node));
if (invalidNode) {
throw Error(`Expected node of type "${type}", received "${invalidNode.type}".`);
}
return true;
}