We can support global registried symbol and well-known symbol.
this means stringifyObject(Symbol.for('sym'))
can output Symbol.for('sym')
,
and stringifyObject(Symbol.iterator)
output Symbol.iterator
.
I am not sure whether to support other symbols, because their stringified literal values will never equal,
but they may be same symbols before stringified.
Currently we can support symbol as object value or array item with a transform callback, but not the object key.
following is my transform code:
import stro from 'stringify-object'
const symbolGlobalList = Object.getOwnPropertyNames(Symbol)
.map(k => Symbol[k]).filter(s => typeof s == 'symbol')
const symbolToLiteral = s => {
if (~symbolGlobalList.indexOf(s)) return s.description
const t = stro(s.description)
if (Symbol.keyFor(s) == undefined) return `Symbol(${t})`
else return `Symbol.for(${t})`
}
const strf = x => stro(x, {
indent: ' ', inlineCharacterLimit: 40,
transform(d, k, o) {
const v = d[k]
if (typeof v == 'symbol') o = symbolToLiteral(v)
return o
}
})
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too