@widergy/web-utils
Version:
Utility GO! Web utils
46 lines (45 loc) • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectValuesContainWord = exports.objectKeysToCamel = exports.findKey = exports.objectIsEmpty = void 0;
const string_1 = require("./string");
const objectIsEmpty = (object) => !object || (Object.keys(object).length === 0 && object.constructor === Object);
exports.objectIsEmpty = objectIsEmpty;
const findKey = (object, predicate) => {
let result;
if (object == null)
return result;
Object.keys(object).some((key) => {
const value = object[key];
if (predicate(value, key, object)) {
result = key;
return true;
}
});
return result;
};
exports.findKey = findKey;
const objectKeysToCamel = (object) => {
const camelKeyObject = {};
Object.keys(object).forEach((key) => {
camelKeyObject[(0, string_1.toCamel)(key)] = object[key];
});
return camelKeyObject;
};
exports.objectKeysToCamel = objectKeysToCamel;
const objectValuesContainWord = (object, word, keysToFilter = []) => {
if (Array.isArray(keysToFilter) && keysToFilter.length < 1) {
return Object.values(object).some((value) => (typeof value === 'string' || typeof value === 'number') &&
`${value}`.toUpperCase().includes(word.toUpperCase()));
}
else {
return keysToFilter.some((key) => `${object[key]}`.toUpperCase().includes(word.toUpperCase()));
}
};
exports.objectValuesContainWord = objectValuesContainWord;
const OBJECT_UTILS = {
objectIsEmpty: exports.objectIsEmpty,
findKey: exports.findKey,
objectKeysToCamel: exports.objectKeysToCamel,
objectValuesContainWord: exports.objectValuesContainWord,
};
exports.default = OBJECT_UTILS;