UNPKG

@parischap/pretty-print

Version:
174 lines (172 loc) 5.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.removeSymbolicKeys = exports.removeStringKeys = exports.removeNotFulfillingKeyPredicateMaker = exports.removeNonFunctions = exports.removeNonEnumerables = exports.removeFunctions = exports.removeEnumerables = exports.moduleTag = exports.make = exports.id = exports.has = exports.equivalence = void 0; var _effectLib = /*#__PURE__*/require("@parischap/effect-lib"); var _effect = /*#__PURE__*/require("effect"); var PPValue = /*#__PURE__*/_interopRequireWildcard(/*#__PURE__*/require("./Value.js")); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * This module implements a type that takes care of filtering properties when printing non-primitive * values. * * With the make function, you can define your own instances if the provided ones don't suit your * needs. */ /** * Module tag * * @category Models */ const moduleTag = exports.moduleTag = '@parischap/pretty-print/PropertyFilter/'; const _TypeId = /*#__PURE__*/Symbol.for(moduleTag); /** * Type guard * * @category Guards */ const has = u => _effect.Predicate.hasProperty(u, _TypeId); /** * Equivalence * * @category Equivalences */ exports.has = has; const equivalence = (self, that) => that.id === self.id; /** Base */ exports.equivalence = equivalence; const _TypeIdHash = /*#__PURE__*/_effect.Hash.hash(_TypeId); const base = { [_TypeId]: _TypeId, [_effect.Equal.symbol](that) { return has(that) && equivalence(this, that); }, [_effect.Hash.symbol]() { return (0, _effect.pipe)(this.id, _effect.Hash.hash, _effect.Hash.combine(_TypeIdHash), _effect.Hash.cached(this)); }, [_effectLib.MInspectable.IdSymbol]() { return this.id; }, ... /*#__PURE__*/_effectLib.MInspectable.BaseProto(moduleTag), ..._effectLib.MPipeable.BaseProto }; /** * Constructor * * @category Constructors */ const make = ({ id, action }) => Object.assign(_effectLib.MFunction.clone(action), { id, ...base }); /** * Returns the `id` property of `self` * * @category Destructors */ exports.make = make; const id = exports.id = /*#__PURE__*/_effect.Struct.get('id'); /** * PropertyFilter instance that removes properties of non-primitive values whose value is not a * function * * @category Instances */ const removeNonFunctions = exports.removeNonFunctions = /*#__PURE__*/make({ id: 'RemoveNonFunctions', action: /*#__PURE__*/_effect.Array.filter(PPValue.isFunction) }); /** * PropertyFilter instance that removes properties of non-primitive values whose value is a function * * @category Instances */ const removeFunctions = exports.removeFunctions = /*#__PURE__*/make({ id: 'RemoveFunctions', action: /*#__PURE__*/_effect.Array.filter(/*#__PURE__*/_effect.Predicate.not(PPValue.isFunction)) }); /** * PropertyFilter instance that removes non-enumerable properties of non-primitive values * * @category Instances */ const removeNonEnumerables = exports.removeNonEnumerables = /*#__PURE__*/make({ id: 'RemoveNonEnumerables', action: /*#__PURE__*/_effect.Array.filter(PPValue.isEnumerable) }); /** * PropertyFilter instance that removes enumerable properties of non-primitive values * * @category Instances */ const removeEnumerables = exports.removeEnumerables = /*#__PURE__*/make({ id: 'RemoveEnumerables', action: /*#__PURE__*/_effect.Array.filter(/*#__PURE__*/_effect.Predicate.not(PPValue.isEnumerable)) }); /** * PropertyFilter instance that removes properties of non-primitive values with a string key * * @category Instances */ const removeStringKeys = exports.removeStringKeys = /*#__PURE__*/make({ id: 'RemoveStringKeys', action: /*#__PURE__*/_effect.Array.filter(PPValue.hasSymbolicKey) }); /** * PropertyFilter instance that removes properties of non-primitive values with a symbolic key * * @category Instances */ const removeSymbolicKeys = exports.removeSymbolicKeys = /*#__PURE__*/make({ id: 'RemoveSymbolicKeys', action: /*#__PURE__*/_effect.Array.filter(/*#__PURE__*/_effect.Predicate.not(PPValue.hasSymbolicKey)) }); /** * Constructor of a propertyFilter instance that removes properties of non-primitive values whose * key is: * * - A string that does not fulfill `predicate` * - A symbol * * @category Constructors */ const removeNotFulfillingKeyPredicateMaker = ({ id, predicate }) => make({ id, action: _effect.Array.filter(_effectLib.MPredicate.struct({ oneLineStringKey: predicate, hasSymbolicKey: _effect.Boolean.not })) }); exports.removeNotFulfillingKeyPredicateMaker = removeNotFulfillingKeyPredicateMaker; //# sourceMappingURL=PropertyFilter.js.map