File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { createLogger } from './factories/createLogger' ;
22import { createRoarrInitialGlobalState } from './factories/createRoarrInitialGlobalState' ;
33import { type MessageSerializer , type RoarrGlobalState } from './types' ;
4- import safeStringify from 'safe-stable- stringify' ;
4+ import { stringify } from './utilities/ stringify' ;
55
66const ROARR = createRoarrInitialGlobalState (
77 ( globalThis . ROARR as RoarrGlobalState ) || { } ,
@@ -10,7 +10,7 @@ const ROARR = createRoarrInitialGlobalState(
1010globalThis . ROARR = ROARR ;
1111
1212const serializeMessage : MessageSerializer = ( message ) => {
13- return safeStringify ( message ) ;
13+ return stringify ( message ) ;
1414} ;
1515
1616const Roarr = createLogger ( ( message ) => {
Original file line number Diff line number Diff line change 11import { createLogger } from './factories/createLogger' ;
22import { createRoarrInitialGlobalStateBrowser } from './factories/createRoarrInitialGlobalStateBrowser' ;
33import { type MessageSerializer , type RoarrGlobalState } from './types' ;
4- import safeStringify from 'safe-stable- stringify' ;
4+ import { stringify } from './utilities/ stringify' ;
55
66const ROARR = createRoarrInitialGlobalStateBrowser (
77 ( globalThis . ROARR as RoarrGlobalState ) || { } ,
@@ -10,7 +10,7 @@ const ROARR = createRoarrInitialGlobalStateBrowser(
1010globalThis . ROARR = ROARR ;
1111
1212const serializeMessage : MessageSerializer = ( message ) => {
13- return safeStringify ( message ) ;
13+ return stringify ( message ) ;
1414} ;
1515
1616const Roarr = createLogger ( ( message ) => {
Original file line number Diff line number Diff line change 1+ import { configure } from 'safe-stable-stringify' ;
2+
3+ const safeStringify = configure ( {
4+ circularValue : 'Magic circle!' ,
5+ deterministic : false ,
6+ strict : false ,
7+ } ) ;
8+
9+ export const stringify = ( value : unknown ) : string => {
10+ try {
11+ return safeStringify ( value ) ?? '' ;
12+ } catch ( error ) {
13+ // eslint-disable-next-line no-console
14+ console . error ( 'could not serialize value' , value ) ;
15+
16+ throw error ;
17+ }
18+ } ;
Original file line number Diff line number Diff line change 1+ import { stringify } from '../../../src/utilities/stringify' ;
2+ import test from 'ava' ;
3+
4+ test ( 'stringifies key=value' , ( t ) => {
5+ t . is (
6+ stringify ( {
7+ foo : 'bar' ,
8+ } ) ,
9+ '{"foo":"bar"}' ,
10+ ) ;
11+ t . is (
12+ stringify ( {
13+ foo : undefined ,
14+ } ) ,
15+ '{}' ,
16+ ) ;
17+ } ) ;
You can’t perform that action at this time.
0 commit comments