You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pk8f3pmu2/utils/leancloudutils.js

21 lines
543 B

5 years ago
const isPlainObject = target =>
target &&
target.toString() == '[object Object]' &&
Object.getPrototypeOf(target) == Object.prototype;
const _jsonify = target => {
if (target && typeof target.toJSON === 'function') return target.toJSON();
if (Array.isArray(target)) return target.map(_jsonify);
return target;
};
exports.jsonify = target =>
isPlainObject(target)
? Object.keys(target).reduce(
(result, key) => ({
...result,
[key]: _jsonify(target[key])
}),
{}
)
: _jsonify(target);