tersify




Create a readable terse representation of the subject.
You can specify maxLength
to further trim the resulting string.
You can also override the result by providing your own tersify()
function on the subject.
import { tersify } from 'tersify'
tersify(() => { return 'foo' })
tersify(function (x, y) { return x + y })
tersify(function foo(y) { return y++ })
tersify({...}, { maxLength: 80 })
tersify({ a: 1 })
tersify(() => { return Symbol.for(abc) })
tersible
Inject a tersify()
function to the subject.
import { tersible } from 'tersify'
const increment = tersible(
a => a + 1,
() => 'a++'
)
increment.tersify()
tersible({ a: 1 }, function () {
return `{ a: ${this.a} }`
}).tersify()
const decrement = tersible(a => a--, 'a--')
decrement.tersify()
tersible({ a: 1 }, options => `a: ${options.maxLength}`).tersify({ maxLength: 10 })
Tersiblized
Mixin Tersible
to a class.
import { Tersiblized } from 'tersify'
class Foo {
a = 1
}
class Boo extends Tersiblized(Foo, function () {
return `{ a: ${this.a} }`
}) {}
const boo = new Boo()
boo.a = 3
boo.tersify()