mirror of
https://github.com/primefaces/primevue.git
synced 2025-05-09 08:52:34 +00:00
Added stringify
function to ObjectUtils
This commit is contained in:
parent
41ed99a9fa
commit
d6737b53f2
2 changed files with 25 additions and 0 deletions
|
@ -341,5 +341,29 @@ export default {
|
|||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue