11import either , { type Either , type Right } from '@matt.kantor/either'
22import parsing from '@matt.kantor/parsing'
3- import kleur from 'kleur '
3+ import { styleText } from 'node:util '
44import type { UnserializableValueError } from '../errors.js'
55import type { Atom , Molecule } from '../parsing.js'
66import { unquotedAtomParser } from '../parsing/atom.js'
@@ -76,7 +76,7 @@ export const moleculeAsKeyValuePairStrings = (
7676 unparseAtomOrMolecule : UnparseAtomOrMolecule ,
7777 options : { readonly ordinalKeys : 'omit' | 'preserve' } ,
7878) : Either < UnserializableValueError , readonly string [ ] > => {
79- const { colon } = punctuation ( kleur )
79+ const { colon } = punctuation ( styleText )
8080 const entries = Object . entries ( value )
8181
8282 const keyValuePairsAsStrings : string [ ] = [ ]
@@ -96,8 +96,7 @@ export const moleculeAsKeyValuePairStrings = (
9696 ordinalPropertyKeyCounter += 1n
9797 } else {
9898 keyValuePairsAsStrings . push (
99- kleur
100- . cyan ( quoteAtomIfNecessary ( propertyKey ) . concat ( colon ) )
99+ styleText ( 'cyan' , quoteAtomIfNecessary ( propertyKey ) . concat ( colon ) )
101100 . concat ( ' ' )
102101 . concat ( valueAsStringResult . value ) ,
103102 )
@@ -109,15 +108,15 @@ export const moleculeAsKeyValuePairStrings = (
109108export const unparseAtom = ( atom : string ) : Right < string > =>
110109 either . makeRight (
111110 / ^ @ [ ^ @ ] / . test ( atom )
112- ? kleur . bold ( kleur . underline ( quoteAtomIfNecessary ( atom ) ) )
111+ ? styleText ( [ 'bold' , ' underline' ] , quoteAtomIfNecessary ( atom ) )
113112 : quoteAtomIfNecessary ( atom ) ,
114113 )
115114
116115const requiresQuotation = ( atom : string ) : boolean =>
117116 either . isLeft ( parsing . parse ( unquotedAtomParser , atom ) )
118117
119118const quoteAtomIfNecessary = ( value : string ) : string => {
120- const { quote } = punctuation ( kleur )
119+ const { quote } = punctuation ( styleText )
121120 if ( requiresQuotation ( value ) ) {
122121 return quote . concat ( escapeStringContents ( value ) ) . concat ( quote )
123122 } else {
@@ -126,7 +125,7 @@ const quoteAtomIfNecessary = (value: string): string => {
126125}
127126
128127const quoteKeyPathComponentIfNecessary = ( value : string ) : string => {
129- const { quote } = punctuation ( kleur )
128+ const { quote } = punctuation ( styleText )
130129 const unquotedAtomResult = parsing . parse ( unquotedAtomParser , value )
131130 if ( either . isLeft ( unquotedAtomResult ) || value . includes ( '.' ) ) {
132131 return quote . concat ( escapeStringContents ( value ) ) . concat ( quote )
@@ -153,7 +152,7 @@ const unparseSugaredApply = (
153152 expression : ApplyExpression ,
154153 unparseAtomOrMolecule : UnparseAtomOrMolecule ,
155154) => {
156- const { closeParenthesis, openParenthesis } = punctuation ( kleur )
155+ const { closeParenthesis, openParenthesis } = punctuation ( styleText )
157156 return either . flatMap (
158157 either . map (
159158 either . flatMap (
@@ -188,8 +187,8 @@ const unparseSugaredFunction = (
188187 either . flatMap ( serializeIfNeeded ( expression [ 1 ] . body ) , serializedBody =>
189188 either . map ( unparseAtomOrMolecule ( serializedBody ) , bodyAsString =>
190189 [
191- kleur . cyan ( expression [ 1 ] . parameter ) ,
192- punctuation ( kleur ) . arrow ,
190+ styleText ( 'cyan' , expression [ 1 ] . parameter ) ,
191+ punctuation ( styleText ) . arrow ,
193192 bodyAsString ,
194193 ] . join ( ' ' ) ,
195194 ) ,
@@ -238,7 +237,7 @@ const unparseSugaredIndex = (
238237 message : 'invalid key path' ,
239238 } )
240239 } else {
241- const { dot } = punctuation ( kleur )
240+ const { dot } = punctuation ( styleText )
242241 return either . makeRight (
243242 unparsedObject
244243 . concat ( dot )
@@ -254,8 +253,9 @@ const unparseSugaredLookup = (
254253 _unparseAtomOrMolecule : UnparseAtomOrMolecule ,
255254) =>
256255 either . makeRight (
257- kleur . cyan (
258- punctuation ( kleur ) . colon . concat (
256+ styleText (
257+ 'cyan' ,
258+ punctuation ( styleText ) . colon . concat (
259259 quoteKeyPathComponentIfNecessary ( expression [ 1 ] . key ) ,
260260 ) ,
261261 ) ,
@@ -280,7 +280,7 @@ const unparseSugaredGeneralizedKeywordExpression = (
280280 'expression cannot be faithfully represented using generalized keyword expression sugar' ,
281281 } )
282282 } else {
283- const unparsedKeyword = kleur . bold ( kleur . underline ( expression [ '0' ] ) )
283+ const unparsedKeyword = styleText ( [ 'bold' , ' underline' ] , expression [ '0' ] )
284284 if ( '1' in expression ) {
285285 return either . map (
286286 either . flatMap (
0 commit comments