Files
cannaiq/frontend/node_modules/es-toolkit/dist/predicate/isJSONValue.js
2025-11-28 19:45:44 -07:00

49 lines
1.1 KiB
JavaScript

'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const isPlainObject = require('./isPlainObject.js');
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.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;
}
exports.isJSONArray = isJSONArray;
exports.isJSONObject = isJSONObject;
exports.isJSONValue = isJSONValue;