File tree Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Expand file tree Collapse file tree 4 files changed +39
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { createLogger } from './factories/createLogger' ;
2
2
import { createRoarrInitialGlobalState } from './factories/createRoarrInitialGlobalState' ;
3
3
import { type MessageSerializer , type RoarrGlobalState } from './types' ;
4
- import safeStringify from 'safe-stable- stringify' ;
4
+ import { stringify } from './utilities/ stringify' ;
5
5
6
6
const ROARR = createRoarrInitialGlobalState (
7
7
( globalThis . ROARR as RoarrGlobalState ) || { } ,
@@ -10,7 +10,7 @@ const ROARR = createRoarrInitialGlobalState(
10
10
globalThis . ROARR = ROARR ;
11
11
12
12
const serializeMessage : MessageSerializer = ( message ) => {
13
- return safeStringify ( message ) ;
13
+ return stringify ( message ) ;
14
14
} ;
15
15
16
16
const Roarr = createLogger ( ( message ) => {
Original file line number Diff line number Diff line change 1
1
import { createLogger } from './factories/createLogger' ;
2
2
import { createRoarrInitialGlobalStateBrowser } from './factories/createRoarrInitialGlobalStateBrowser' ;
3
3
import { type MessageSerializer , type RoarrGlobalState } from './types' ;
4
- import safeStringify from 'safe-stable- stringify' ;
4
+ import { stringify } from './utilities/ stringify' ;
5
5
6
6
const ROARR = createRoarrInitialGlobalStateBrowser (
7
7
( globalThis . ROARR as RoarrGlobalState ) || { } ,
@@ -10,7 +10,7 @@ const ROARR = createRoarrInitialGlobalStateBrowser(
10
10
globalThis . ROARR = ROARR ;
11
11
12
12
const serializeMessage : MessageSerializer = ( message ) => {
13
- return safeStringify ( message ) ;
13
+ return stringify ( message ) ;
14
14
} ;
15
15
16
16
const 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