Skip to content

Commit

Permalink
Use @osd/std to prettify objects for display (opensearch-project#8232)
Browse files Browse the repository at this point in the history
* Use @osd/std to stringify JSON when formatting objects for display

Signed-off-by: Miki <[email protected]>

* Changeset file for PR opensearch-project#8232 created/updated

---------

Signed-off-by: Miki <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and virajsanghvi committed Sep 24, 2024
1 parent f8a5fb2 commit cff56e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8232.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Use @osd/std to prettify objects for display ([#8232](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8232))
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ describe('asPrettyString', () => {
});

test('Converts objects values into presentable strings', () => {
expect(asPrettyString({ key: 'value' })).toBe('{\n "key": "value"\n}');
const longPositive = BigInt(Number.MAX_SAFE_INTEGER) * 2n;
const longNegative = BigInt(Number.MIN_SAFE_INTEGER) * 2n;
expect(asPrettyString({ key: 'value', longPositive, longNegative })).toBe(
`{\n "key": "value",\n "longPositive": ${longPositive.toString()},\n "longNegative": ${longNegative.toString()}\n}`
);
});

test('Converts other non-string values into strings', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
* under the License.
*/

import { stringify } from '@osd/std';

/**
* Convert a value to a presentable string
*/
Expand All @@ -37,7 +39,7 @@ export function asPrettyString(val: any): string {
case 'string':
return val;
case 'object':
return JSON.stringify(val, null, ' ');
return stringify(val, null, ' ');
default:
return '' + val;
}
Expand Down

0 comments on commit cff56e1

Please sign in to comment.