Skip to content

Commit

Permalink
$mol_key: bigint support
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Nov 16, 2023
1 parent f361259 commit 4a64303
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions key/key.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace $ {
$mol_assert_equal( $mol_key( false ), 'false' )
$mol_assert_equal( $mol_key( true ), 'true' )
$mol_assert_equal( $mol_key( 0 ), '0' )
$mol_assert_equal( $mol_key( 1n<<64n ), '18446744073709551616n' )
$mol_assert_equal( $mol_key( '' ), '""' )

},
Expand Down
2 changes: 2 additions & 0 deletions key/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ namespace $ {
/** Returns string key for any value. */
export function $mol_key< Value >( value : Value ) : string {

if( typeof value === 'bigint' ) return value.toString() + 'n'
if( !value ) return JSON.stringify( value )
if( typeof value !== 'object' && typeof value !== 'function' ) return JSON.stringify( value )

return JSON.stringify( value, ( field, value )=> {

if( typeof value === 'bigint' ) return value.toString() + 'n'
if( !value ) return value
if( typeof value !== 'object' && typeof value !== 'function' ) return value
if( Array.isArray( value ) ) return value
Expand Down

0 comments on commit 4a64303

Please sign in to comment.