@squiz/json-schema-library
Version:
Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
19 lines (17 loc) • 437 B
text/typescript
import getTypeOf from "../getTypeOf";
export function isEmpty(v: unknown): boolean {
const type = getTypeOf(v);
switch (type) {
case "string":
case "array":
// @ts-ignore
return v.length === 0;
case "null":
case "undefined":
return true;
case "object":
return Object.keys(v).length === 0;
default:
return false;
}
}