UNPKG

@bemedev/types

Version:

Type definitions for Bemedev projects

60 lines (57 loc) 1.71 kB
import { PARTIAL, CUSTOM, PRIMITIVES, PRIMITIVE_OBJECTS } from './constants.js'; /* eslint-disable @typescript-eslint/no-unused-vars */ const _transform = (object) => { let out; const isArray = Array.isArray(object); if (isArray) { out = object.map(_transform); return out; } const isObject = typeof object === 'object'; if (isObject) { out = {}; const entries = Object.entries(object).filter(([key]) => key !== PARTIAL); if (entries.length === 0) return out; const isCustom = Object.keys(object).every(key => key === CUSTOM); if (isCustom) return out; entries.forEach(([key, value]) => { out[key] = _transform(value); }); return out; } for (const primitive of PRIMITIVES) { if (object === primitive) return out; } for (const primitive of PRIMITIVE_OBJECTS.filter(value => value !== 'date')) { if (object === primitive) { out = {}; return out; } } return out; }; const transform = (object) => _transform(object); transform.const = (object) => { return _transform(object); }; transform.custom = (_) => { const out = {}; out[CUSTOM] = undefined; return out; }; transform.partial = (value) => { const entries = Object.entries(value).filter(([key]) => key !== PARTIAL); const out = {}; entries.forEach(([key, value]) => { out[key] = value; }); out[PARTIAL] = undefined; return out; }; transform.tuple = (...els) => transform(els); transform.union = (..._) => transform.custom(); export { transform }; //# sourceMappingURL=functions.js.map