Files
2025-11-28 19:45:44 -07:00

43 lines
996 B
JavaScript

import { isPlainObject } from './isPlainObject.mjs';
function isJSONValue(value) {
switch (typeof value) {
case 'object': {
return value === null || isJSONArray(value) || isJSONObject(value);
}
case 'string':
case 'number':
case 'boolean': {
return true;
}
default: {
return false;
}
}
}
function isJSONArray(value) {
if (!Array.isArray(value)) {
return false;
}
return value.every(item => isJSONValue(item));
}
function isJSONObject(obj) {
if (!isPlainObject(obj)) {
return false;
}
const keys = Reflect.ownKeys(obj);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = obj[key];
if (typeof key !== 'string') {
return false;
}
if (!isJSONValue(value)) {
return false;
}
}
return true;
}
export { isJSONArray, isJSONObject, isJSONValue };