Skip to content

Commit

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



* Changeset file for PR #8232 created/updated

---------



(cherry picked from commit 6e3351c)

Signed-off-by: Miki <miki@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 21, 2024
1 parent 9a2f697 commit c0fc91e
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 c0fc91e

Please sign in to comment.