twing
Version:
First-class Twig engine for Node.js
29 lines (28 loc) • 823 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isTraversable = isTraversable;
const is_plain_object_1 = require("./is-plain-object");
/**
* Check that an object is traversable in the sense of PHP,
* i.e. implements PHP Traversable interface
*
* @param value
* @returns {boolean}
*/
function isTraversable(value) {
if ((0, is_plain_object_1.isPlainObject)(value)) {
return true;
}
if ((value !== null) && (value !== undefined)) {
if (typeof value === 'string') {
return false;
}
if (typeof value['entries'] === 'function') {
return true;
}
if ((typeof value[Symbol.iterator] === 'function') || (typeof value['next'] === 'function')) {
return true;
}
}
return false;
}