Added `stringify` function to ObjectUtils
parent
41ed99a9fa
commit
d6737b53f2
|
@ -341,5 +341,29 @@ export default {
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}, []);
|
}, []);
|
||||||
|
},
|
||||||
|
|
||||||
|
stringify(value, indent = 2, currentIndent = 0) {
|
||||||
|
const currentIndentStr = ' '.repeat(currentIndent);
|
||||||
|
const nextIndentStr = ' '.repeat(currentIndent + indent);
|
||||||
|
|
||||||
|
if (this.isArray(value)) {
|
||||||
|
return '[' + value.map((v) => this.stringify(v, indent, currentIndent + indent)).join(', ') + ']';
|
||||||
|
} else if (this.isDate(value)) {
|
||||||
|
return value.toISOString();
|
||||||
|
} else if (this.isFunction(value)) {
|
||||||
|
return value.toString();
|
||||||
|
} else if (this.isObject(value)) {
|
||||||
|
return (
|
||||||
|
'{\n' +
|
||||||
|
Object.entries(value)
|
||||||
|
.map(([k, v]) => `${nextIndentStr}${k}: ${this.stringify(v, indent, currentIndent + indent)}`)
|
||||||
|
.join(',\n') +
|
||||||
|
`\n${currentIndentStr}` +
|
||||||
|
'}'
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return JSON.stringify(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -99,6 +99,7 @@ export declare class ObjectUtils {
|
||||||
static sort(value1: any, value2: any, order: number, comparator: (a: any, b: any) => any, nullSortOrder: number): number;
|
static sort(value1: any, value2: any, order: number, comparator: (a: any, b: any) => any, nullSortOrder: number): number;
|
||||||
static compare(value1: any, value2: any, comparator: (a: any, b: any) => any, order: number): number;
|
static compare(value1: any, value2: any, comparator: (a: any, b: any) => any, order: number): number;
|
||||||
static nestedKeys(obj: object, parentKey?: string): string[];
|
static nestedKeys(obj: object, parentKey?: string): string[];
|
||||||
|
static stringify(value: any, indent?: number, currentIndent?: number): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare namespace ZIndexUtils {
|
export declare namespace ZIndexUtils {
|
||||||
|
|
Loading…
Reference in New Issue