@parischap/pretty-print
Version:
A functional library to pretty-print and treeify objects
107 lines • 2.75 kB
JavaScript
/**
* This module implements a map of the different marks that appear in a value to stringify.
*
* With the make function, you can define your own instances if the provided ones don't suit your
* needs.
*/
import { MInspectable, MPipeable, MTypes } from '@parischap/effect-lib';
import { Equal, Hash, HashMap, pipe, Predicate, Struct } from 'effect';
/**
* Module tag
*
* @category Models
*/
export const moduleTag = '@parischap/pretty-print/MarkMap/';
const _TypeId = /*#__PURE__*/Symbol.for(moduleTag);
/**
* Type guard
*
* @category Guards
*/
export const has = u => Predicate.hasProperty(u, _TypeId);
/**
* Equivalence
*
* @category Equivalences
*/
export const equivalence = (self, that) => that.id === self.id;
/** Prototype */
const _TypeIdHash = /*#__PURE__*/Hash.hash(_TypeId);
const proto = {
[_TypeId]: _TypeId,
[Equal.symbol](that) {
return has(that) && equivalence(this, that);
},
[Hash.symbol]() {
return pipe(this.id, Hash.hash, Hash.combine(_TypeIdHash), Hash.cached(this));
},
[MInspectable.IdSymbol]() {
return this.id;
},
... /*#__PURE__*/MInspectable.BaseProto(moduleTag),
...MPipeable.BaseProto
};
/**
* Constructor
*
* @category Constructors
*/
export const make = params => MTypes.objectFromDataAndProto(proto, params);
/**
* Returns the `id` property of `self`
*
* @category Destructors
*/
export const id = /*#__PURE__*/Struct.get('id');
/**
* Returns the `marks` property of `self`
*
* @category Destructors
*/
export const marks = /*#__PURE__*/Struct.get('marks');
/**
* Default MarkMap instance
*
* @category Instances
*/
export const utilInspectLike = /*#__PURE__*/make({
id: 'Defaults',
marks: /*#__PURE__*/HashMap.make(['FunctionNameStartDelimiter', {
text: 'Function: ',
partName: 'Message'
}], ['FunctionNameEndDelimiter', {
text: '',
partName: 'Message'
}], ['MessageStartDelimiter', {
text: '[',
partName: 'Message'
}], ['MessageEndDelimiter', {
text: ']',
partName: 'Message'
}], ['CircularObject', {
text: 'Circular *',
partName: 'Message'
}], ['CircularReferenceStartDelimiter', {
text: '<Ref *',
partName: 'Message'
}], ['CircularReferenceEndDelimiter', {
text: '> ',
partName: 'Message'
}], ['TabIndent', {
text: ' ',
partName: 'Indentation'
}], ['TreeIndentForFirstLineOfInitProps', {
text: '├─ ',
partName: 'Indentation'
}], ['TreeIndentForTailLinesOfInitProps', {
text: '│ ',
partName: 'Indentation'
}], ['TreeIndentForFirstLineOfLastProp', {
text: '└─ ',
partName: 'Indentation'
}], ['TreeIndentForTailLinesOfLastProp', {
text: ' ',
partName: 'Indentation'
}])
});
//# sourceMappingURL=MarkMap.js.map