Icard/angular-clarity-master(work.../node_modules/primeng/esm2022/utils/objectutils.mjs

258 lines
34 KiB
JavaScript

export class ObjectUtils {
static isArray(value, empty = true) {
return Array.isArray(value) && (empty || value.length !== 0);
}
static isObject(value, empty = true) {
return typeof value === 'object' && !Array.isArray(value) && value != null && (empty || Object.keys(value).length !== 0);
}
static equals(obj1, obj2, field) {
if (field)
return this.resolveFieldData(obj1, field) === this.resolveFieldData(obj2, field);
else
return this.equalsByValue(obj1, obj2);
}
static equalsByValue(obj1, obj2) {
if (obj1 === obj2)
return true;
if (obj1 && obj2 && typeof obj1 == 'object' && typeof obj2 == 'object') {
var arrA = Array.isArray(obj1), arrB = Array.isArray(obj2), i, length, key;
if (arrA && arrB) {
length = obj1.length;
if (length != obj2.length)
return false;
for (i = length; i-- !== 0;)
if (!this.equalsByValue(obj1[i], obj2[i]))
return false;
return true;
}
if (arrA != arrB)
return false;
var dateA = this.isDate(obj1), dateB = this.isDate(obj2);
if (dateA != dateB)
return false;
if (dateA && dateB)
return obj1.getTime() == obj2.getTime();
var regexpA = obj1 instanceof RegExp, regexpB = obj2 instanceof RegExp;
if (regexpA != regexpB)
return false;
if (regexpA && regexpB)
return obj1.toString() == obj2.toString();
var keys = Object.keys(obj1);
length = keys.length;
if (length !== Object.keys(obj2).length)
return false;
for (i = length; i-- !== 0;)
if (!Object.prototype.hasOwnProperty.call(obj2, keys[i]))
return false;
for (i = length; i-- !== 0;) {
key = keys[i];
if (!this.equalsByValue(obj1[key], obj2[key]))
return false;
}
return true;
}
return obj1 !== obj1 && obj2 !== obj2;
}
static resolveFieldData(data, field) {
if (data && field) {
if (this.isFunction(field)) {
return field(data);
}
else if (field.indexOf('.') == -1) {
return data[field];
}
else {
let fields = field.split('.');
let value = data;
for (let i = 0, len = fields.length; i < len; ++i) {
if (value == null) {
return null;
}
value = value[fields[i]];
}
return value;
}
}
else {
return null;
}
}
static isFunction(obj) {
return !!(obj && obj.constructor && obj.call && obj.apply);
}
static reorderArray(value, from, to) {
let target;
if (value && from !== to) {
if (to >= value.length) {
to %= value.length;
from %= value.length;
}
value.splice(to, 0, value.splice(from, 1)[0]);
}
}
static insertIntoOrderedArray(item, index, arr, sourceArr) {
if (arr.length > 0) {
let injected = false;
for (let i = 0; i < arr.length; i++) {
let currentItemIndex = this.findIndexInList(arr[i], sourceArr);
if (currentItemIndex > index) {
arr.splice(i, 0, item);
injected = true;
break;
}
}
if (!injected) {
arr.push(item);
}
}
else {
arr.push(item);
}
}
static findIndexInList(item, list) {
let index = -1;
if (list) {
for (let i = 0; i < list.length; i++) {
if (list[i] == item) {
index = i;
break;
}
}
}
return index;
}
static contains(value, list) {
if (value != null && list && list.length) {
for (let val of list) {
if (this.equals(value, val))
return true;
}
}
return false;
}
static removeAccents(str) {
if (str) {
str = str.normalize('NFKD').replace(/\p{Diacritic}/gu, '');
}
return str;
}
static isDate(input) {
return Object.prototype.toString.call(input) === '[object Date]';
}
static isEmpty(value) {
return value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0) || (!this.isDate(value) && typeof value === 'object' && Object.keys(value).length === 0);
}
static isNotEmpty(value) {
return !this.isEmpty(value);
}
static compare(value1, value2, locale, order = 1) {
let result = -1;
const emptyValue1 = this.isEmpty(value1);
const emptyValue2 = this.isEmpty(value2);
if (emptyValue1 && emptyValue2)
result = 0;
else if (emptyValue1)
result = order;
else if (emptyValue2)
result = -order;
else if (typeof value1 === 'string' && typeof value2 === 'string')
result = value1.localeCompare(value2, locale, { numeric: true });
else
result = value1 < value2 ? -1 : value1 > value2 ? 1 : 0;
return result;
}
static sort(value1, value2, order = 1, locale, nullSortOrder = 1) {
const result = ObjectUtils.compare(value1, value2, locale, order);
let finalSortOrder = order;
// nullSortOrder == 1 means Excel like sort nulls at bottom
if (ObjectUtils.isEmpty(value1) || ObjectUtils.isEmpty(value2)) {
finalSortOrder = nullSortOrder === 1 ? order : nullSortOrder;
}
return finalSortOrder * result;
}
static merge(obj1, obj2) {
if (obj1 == undefined && obj2 == undefined) {
return undefined;
}
else if ((obj1 == undefined || typeof obj1 === 'object') && (obj2 == undefined || typeof obj2 === 'object')) {
return { ...(obj1 || {}), ...(obj2 || {}) };
}
else if ((obj1 == undefined || typeof obj1 === 'string') && (obj2 == undefined || typeof obj2 === 'string')) {
return [obj1 || '', obj2 || ''].join(' ');
}
return obj2 || obj1;
}
static isPrintableCharacter(char = '') {
return this.isNotEmpty(char) && char.length === 1 && char.match(/\S| /);
}
static getItemValue(obj, ...params) {
return this.isFunction(obj) ? obj(...params) : obj;
}
static findLastIndex(arr, callback) {
let index = -1;
if (this.isNotEmpty(arr)) {
try {
index = arr.findLastIndex(callback);
}
catch {
index = arr.lastIndexOf([...arr].reverse().find(callback));
}
}
return index;
}
static findLast(arr, callback) {
let item;
if (this.isNotEmpty(arr)) {
try {
item = arr.findLast(callback);
}
catch {
item = [...arr].reverse().find(callback);
}
}
return item;
}
static deepEquals(a, b) {
if (a === b)
return true;
if (a && b && typeof a == 'object' && typeof b == 'object') {
var arrA = Array.isArray(a), arrB = Array.isArray(b), i, length, key;
if (arrA && arrB) {
length = a.length;
if (length != b.length)
return false;
for (i = length; i-- !== 0;)
if (!this.deepEquals(a[i], b[i]))
return false;
return true;
}
if (arrA != arrB)
return false;
var dateA = a instanceof Date, dateB = b instanceof Date;
if (dateA != dateB)
return false;
if (dateA && dateB)
return a.getTime() == b.getTime();
var regexpA = a instanceof RegExp, regexpB = b instanceof RegExp;
if (regexpA != regexpB)
return false;
if (regexpA && regexpB)
return a.toString() == b.toString();
var keys = Object.keys(a);
length = keys.length;
if (length !== Object.keys(b).length)
return false;
for (i = length; i-- !== 0;)
if (!Object.prototype.hasOwnProperty.call(b, keys[i]))
return false;
for (i = length; i-- !== 0;) {
key = keys[i];
if (!this.deepEquals(a[key], b[key]))
return false;
}
return true;
}
return a !== a && b !== b;
}
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib2JqZWN0dXRpbHMuanMiLCJzb3VyY2VSb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iBhbnksIGZpZWxkPzogc3RyaW5nKTogYm9vbGVhbiB7XG4gICAgICAgIGlmIChmaWVsZCkgcmV0dXJuIHRoaXMucmVzb2x2ZUZpZWxkRGF0YShvYmoxLCBmaWVsZCkgPT09IHRoaXMucmVzb2x2ZUZpZWxkRGF0YShvYmoyLCBmaWVsZCk7XG4gICAgICAgIGVsc2UgcmV0dXJuIHRoaXMuZXF1YWxzQnlWYWx1ZShvYmoxLCBvYmoyKTtcbiAgICB9XG5cbiAgICBwdWJsaWMgc3RhdGljIGVxdWFsc0J5VmFsdWUob2JqMTogYW55LCBvYmoyOiBhbnkpOiBib29sZWFuIHtcbiAgICAgICAgaWYgKG9iajEgPT09IG9iajIpIHJldHVybiB0cnVlO1xuXG4gICAgICAgIGlmIChvYmoxICYmIG9iajIgJiYgdHlwZW9mIG9iajEgPT0gJ29iamVjdCcgJiYgdHlwZW9mIG9iajIgPT0gJ29iamVjdCcpIHtcbiAgICAgICAgICAgIHZhciBhcnJBID0gQXJyYXkuaXNBcnJheShvYmoxKSxcbiAgICAgICAgICAgICAgICBhcnJCID0gQXJyYXkuaXNBcnJheShvYmoyKSxcbiAgICAgICAgICAgICAgICBpLFxuICAgICAgICAgICAgICAgIGxlbmd0aCxcbiAgICAgICAgICAgICAgICBrZXk7XG5cbiAgICAgICAgICAgIGlmIChhcnJBICYmIGFyckIpIHtcbiAgICAgICAgICAgICAgICBsZW5ndGggPSBvYmoxLmxlbmd0aDtcbiAgICAgICAgICAgICAgICBpZiAobGVuZ3RoICE9IG9iajIubGVuZ3RoKSByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICAgICAgZm9yIChpID0gbGVuZ3RoOyBpLS0gIT09IDA7ICkgaWYgKCF0aGlzLmVxdWFsc0J5VmFsdWUob2JqMVtpXSwgb2JqMltpXSkpIHJldHVybiBmYWxzZTtcbiAgICAgICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgICAgIH1cblxuICAgICAgICAgICAgaWYgKGFyck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ICghdGhpcy5lcXVhbHNCeVZhbHVlKG9iajFba2V5XSwgb2JqMltrZXldKSkgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICByZXR1cm4gdHJ1ZTtcbiAgICAgICAgfVxuXG4gICAgICAgIHJldHVybiBvYmoxICE9PSBvYmoxICYmIG9iajIgIT09IG9iajI7XG4gICAgfVxuXG4gICAgcHVibGljIHN0YXRpYyByZXNvbHZlRmllbGREYXRhKGRhdGE6IGFueSwgZmllbGQ6IGFueSk6IGFueSB7XG4gICAgICAgIGlmIChkYXRhICYmIGZpZWxkKSB7XG4gICAgICAgICAgICBpZiAodGhpcy5pc0Z1bmN0aW9uKGZpZWxkKSkge1xuICAgICAgICAgICAgICAgIHJldHVybiBmaWVsZChkYXRhKTtcbiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmllbGQuaW5kZXhPZignLicpID09IC0xKSB7XG4gICAgICAgICAgICAgICAgcmV0dXJuIGRhdGFbZmllbGRdO1xuICAgICAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgICAgICBsZXQgZmllbGRzOiBzdHJpbmdbXSA9IGZpZWxkLnNwbGl0KCcuJyk7XG4gICAgICAgICAgICAgICAgbGV0IHZhbHVlID0gZGF0YTtcbiAgICAgICAgICAgICAgICBmb3IgKGxldCBpID0gMCwgbGVuID0gZmllbGRzLmxlbmd0aDsgaSA8IGxlbjsgKytpKSB7XG4gICAgICAgICAgICAgICAgICAgIGlmICh2YWx1ZSA9PSBudWxsKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDtcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICB2YWx1ZSA9IHZhbHVlW2ZpZWxkc1tpXV07XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIHJldHVybiB2YWx1ZTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIHJldHVybiBudWxsO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcHVibGljIHN0YXRpYyBpc0Z1bmN0aW9uKG9iajogYW55KSB7XG4gICAgICAgIHJldHVybiAhIShvYmogJiYgb2JqLmNvbnN0cnVjdG9yICYmIG9iai5jYWxsICYmIG9iai5hcHBseSk7XG4gICAgfVxuXG4gICAgcHVibGljIHN0YXRpYyByZW9yZGVyQXJyYXkodmFsdWU6IGFueVtdLCBmcm9tOiBudW1iZXIsIHRvOiBudW1iZXIpIHtcbiAgICAgICAgbGV0IHRhcmdldDogbnVtYmVyO1xuICAgICAgICBpZiAodmFsdWUgJiYgZnJvbSAhPT0gdG8pIHtcbiAgICAgICAgICAgIGlmICh0byA+PSB2YWx1ZS5sZW5ndGgpIHtcbiAgICAgICAgICAgICAgICB0byAlPSB2YWx1ZS5sZW5ndGg7XG4gICAgICAgICAgICAgICAgZnJvbSAlPSB2YWx1ZS5sZW5ndGg7XG4gICAgICAgICAgICB9XG4gICAgICAgICAgICB2YWx1ZS5zcGxpY2UodG8sIDAsIHZhbHVlLnNwbGljZShmcm9tLCAxKVswXSk7XG4gICAgICAgIH1cbiAgICB9XG5cbiAgICBwdWJsaWMgc3RhdGljIGluc2VydEludG9PcmRlcmVkQXJyYXkoaXRlbTogYW55LCBpbmRleDogbnVtYmVyLCBhcnI6IGFueVtdLCBzb3VyY2VBcnI6IGFueVtdKTogdm9pZCB7XG4gICAgICAgIGlmIChhcnIubGVuZ3RoID4gMCkge1xuICAgICAgICAgICAgbGV0IGluamVjdGVkID0gZmFsc2U7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGFyci5sZW5ndGg7IGkrKykge1xuICAgICAgICAgICAgICAgIGxldCBjdXJyZW50SXRlbUluZGV4ID0gdGhpcy5maW5kSW5kZXhJbkxpc3QoYXJyW2ldLCBzb3VyY2VBcnIpO1xuICAgICAgICAgICAgICAgIGlmIChjdXJyZW50SXRlbUluZGV4ID4gaW5kZXgpIHtcbiAgICAgICAgICAgICAgICAgICAgYXJyLnNwbGljZShpLCAwLCBpdGVtKTtcbiAgICAgICAgICAgICAgICAgICAgaW5qZWN0ZWQgPSB0cnVlO1xuICAgICAgICAgICAgICAgICAgICBicmVhaztcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIGlmICghaW5qZWN0ZWQpIHtcbiAgICAgICAgICAgICAgICBhcnIucHVzaChpdGVtKTtcbiAgICAgICAgICAgIH1cbiAgICAgICAgfSBlbHNlIHtcbiAgICAgICAgICAgIGFyci5wdXNoKGl0ZW0pO1xuICAgICAgICB9XG4gICAgfVxuXG4gICAgcHVibGljIHN0YXRpYyBmaW5kSW5kZXhJbkxpc3QoaXRlbTogYW55LCBsaXN0OiBhbnkpOiBudW1iZXIge1xuICAgICAgICBsZXQgaW5kZXg6IG51bWJlciA9IC0xO1xuXG4gICAgICAgIGlmIChsaXN0KSB7XG4gICAgICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyBpKyspIHtcbiAgICAgICAgICAgICAgICBpZiAobGlzdFtpXSA9PSBpdGVtKSB7XG4gICAgICAgICAgICAgICAgICAgIGluZGV4ID0gaTtcbiAgICAgICAgICAgICAgICAgICAgYnJlYWs7XG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGluZGV4O1xuICAgIH1cblxuICAgIHB1YmxpYyBzdGF0aWMgY29udGFpbnModmFsdWUsIGxpc3QpIHtcbiAgICAgICAgaWYgKHZhbHVlICE9IG51bGwgJiYgbGlzdCAmJiBsaXN0Lmxlbmd0aCkge1xuICAgICAgICAgICAgZm9yIChsZXQgdmFsIG9mIGxpc3QpIHtcbiAgICAgICAgICAgICAgICBpZiAodGhpcy5lcXVhbHModmFsdWUsIHZhbCkpIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dX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gICByZXR1cm4gdGhpcy5pc0Z1bmN0aW9uKG9iaikgPyBvYmooLi4ucGFyYW1zKSA6IG9iajtcbiAgICB9XG5cbiAgICBwdWJsaWMgc3RhdGljIGZpbmRMYXN0SW5kZXgoYXJyLCBjYWxsYmFjaykge1xuICAgICAgICBsZXQgaW5kZXggPSAtMTtcblxuICAgICAgICBpZiAodGhpcy5pc05vdEVtcHR5KGFycikpIHtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgaW5kZXggPSBhcnIuZmluZExhc3RJbmRleChjYWxsYmFjayk7XG4gICAgICAgICAgICB9IGNhdGNoIHtcbiAgICAgICAgICAgICAgICBpbmRleCA9IGFyci5sYXN0SW5kZXhPZihbLi4uYXJyXS5yZXZlcnNlKCkuZmluZChjYWxsYmFjaykpO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGluZGV4O1xuICAgIH1cblxuICAgIHB1YmxpYyBzdGF0aWMgZmluZExhc3QoYXJyLCBjYWxsYmFjaykge1xuICAgICAgICBsZXQgaXRlbTtcblxuICAgICAgICBpZiAodGhpcy5pc05vdEVtcHR5KGFycikpIHtcbiAgICAgICAgICAgIHRyeSB7XG4gICAgICAgICAgICAgICAgaXRlbSA9IGFyci5maW5kTGFzdChjYWxsYmFjayk7XG4gICAgICAgICAgICB9IGNhdGNoIHtcbiAgICAgICAgICAgICAgICBpdGVtID0gWy4uLmFycl0ucmV2ZXJzZSgpLmZpbmQoY2FsbGJhY2spO1xuICAgICAgICAgICAgfVxuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGl0ZW07XG4gICAgfVxuXG4gICAgcHVibGljIHN0YXRpYyBkZWVwRXF1YWxzKGEsIGIpIHtcbiAgICAgICAgaWYgKGEgPT09IGIpIHJldHVybiB0cnVlO1xuXG4gICAgICAgIGlmIChhICYmIGIgJiYgdHlwZW9mIGEgPT0gJ29iamVjdCcgJiYgdHlwZW9mIGIgPT0gJ29iamVjdCcpIHtcbiAgICAgICAgICAgIHZhciBhcnJBID0gQXJyYXkuaXNBcnJheShhKSxcbiAgICAgICAgICAgICAgICBhcnJCID0gQXJyYXkuaXNBcnJheShiKSxcbiAgICAgICAgICAgICAgICBpLFxuICAgICAgICAgICAgICAgIGxlbmd0aCxcbiAgICAgICAgICAgICAgICBrZXk7XG5cbiAgICAgICAgICAgIGlmIChhcnJBICYmIGFyckIpIHtcbiAgICAgICAgICAgICAgICBsZW5ndGggPSBhLmxlbmd0aDtcbiAgICAgICAgICAgICAgICBpZiAobGVuZ3RoICE9IGIubGVuZ3RoKSByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICAgICAgZm9yIChpID0gbGVuZ3RoOyBpLS0gIT09IDA7ICkgaWYgKCF0aGlzLmRlZXBFcXVhbHMoYVtpXSwgYltpXSkpIHJldHVybiBmYWxzZTtcblxuICAgICAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICBpZiAoYXJyQSAhPSBhcnJCKSByZXR1cm4gZmFsc2U7XG5cbiAgICAgICAgICAgIHZhciBkYXRlQSA9IGEgaW5zdGFuY2VvZiBEYXRlLFxuICAgICAgICAgICAgICAgIGRhdGVCID0gYiBpbnN0YW5jZW9mIERhdGU7XG5cbiAgICAgICAgICAgIGlmIChkYXRlQSAhPSBkYXRlQikgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgaWYgKGRhdGVBICYmIGRhdGVCKSByZXR1cm4gYS5nZXRUaW1lKCkgPT0gYi5nZXRUaW1lKCk7XG5cbiAgICAgICAgICAgIHZhciByZWdleHBBID0gYSBpbnN0YW5jZW9mIFJlZ0V4cCxcbiAgICAgICAgICAgICAgICByZWdleHBCID0gYiBpbnN0YW5jZW9mIFJlZ0V4cDtcblxuICAgICAgICAgICAgaWYgKHJlZ2V4cEEgIT0gcmVnZXhwQikgcmV0dXJuIGZhbHNlO1xuICAgICAgICAgICAgaWYgKHJlZ2V4cEEgJiYgcmVnZXhwQikgcmV0dXJuIGEudG9TdHJpbmcoKSA9PSBiLnRvU3RyaW5nKCk7XG5cbiAgICAgICAgICAgIHZhciBrZXlzID0gT2JqZWN0LmtleXMoYSk7XG5cbiAgICAgICAgICAgIGxlbmd0aCA9IGtleXMubGVuZ3RoO1xuXG4gICAgICAgICAgICBpZiAobGVuZ3RoICE9PSBPYmplY3Qua2V5cyhiKS5sZW5ndGgpIHJldHVybiBmYWxzZTtcblxuICAgICAgICAgICAgZm9yIChpID0gbGVuZ3RoOyBpLS0gIT09IDA7ICkgaWYgKCFPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwoYiwga2V5c1tpXSkpIHJldHVybiBmYWxzZTtcblxuICAgICAgICAgICAgZm9yIChpID0gbGVuZ3RoOyBpLS0gIT09IDA7ICkge1xuICAgICAgICAgICAgICAgIGtleSA9IGtleXNbaV07XG4gICAgICAgICAgICAgICAgaWYgKCF0aGlzLmRlZXBFcXVhbHMoYVtrZXldLCBiW2tleV0pKSByZXR1cm4gZmFsc2U7XG4gICAgICAgICAgICB9XG5cbiAgICAgICAgICAgIHJldHVybiB0cnVlO1xuICAgICAgICB9XG5cbiAgICAgICAgcmV0dXJuIGEgIT09IGEgJiYgYiAhPT0gYjtcbiAgICB9XG59XG4iXX0=