@metrichor/jmespath
Version:
Typescript implementation of the JMESPath spec (100% compliant)
76 lines • 2.47 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAlphaNum = exports.isNum = exports.isAlpha = exports.isFalse = exports.strictDeepEqual = exports.isObject = void 0;
const isObject = (obj) => {
return obj !== null && Object.prototype.toString.call(obj) === '[object Object]';
};
exports.isObject = isObject;
const strictDeepEqual = (first, second) => {
if (first === second) {
return true;
}
if (typeof first !== typeof second) {
return false;
}
if (Array.isArray(first) && Array.isArray(second)) {
if (first.length !== second.length) {
return false;
}
for (let i = 0; i < first.length; i += 1) {
if (!exports.strictDeepEqual(first[i], second[i])) {
return false;
}
}
return true;
}
if (exports.isObject(first) && exports.isObject(second)) {
const firstEntries = Object.entries(first);
const secondKeys = new Set(Object.keys(second));
if (firstEntries.length !== secondKeys.size) {
return false;
}
for (const [key, value] of firstEntries) {
if (!exports.strictDeepEqual(value, second[key])) {
return false;
}
secondKeys.delete(key);
}
return secondKeys.size === 0;
}
return false;
};
exports.strictDeepEqual = strictDeepEqual;
const isFalse = (obj) => {
if (obj === '' || obj === false || obj === null || obj === undefined) {
return true;
}
if (Array.isArray(obj) && obj.length === 0) {
return true;
}
if (exports.isObject(obj)) {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
return false;
}
}
return true;
}
return false;
};
exports.isFalse = isFalse;
const isAlpha = (ch) => {
// tslint:disable-next-line: strict-comparisons
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch === '_';
};
exports.isAlpha = isAlpha;
const isNum = (ch) => {
// tslint:disable-next-line: strict-comparisons
return (ch >= '0' && ch <= '9') || ch === '-';
};
exports.isNum = isNum;
const isAlphaNum = (ch) => {
// tslint:disable-next-line: strict-comparisons
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch === '_';
};
exports.isAlphaNum = isAlphaNum;
//# sourceMappingURL=index.js.map