Skip to content

Commit

Permalink
Use @osd/std to stringify JSON when formatting objects for display
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki committed Sep 18, 2024
1 parent cc5531b commit f796925
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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 f796925

Please sign in to comment.