UNPKG

rn-custom-style-sheet

Version:

React Native component to select a specific value from a range of values.

43 lines 1.7 kB
import { hasValidBreakpointPropertyFormat } from '../../../BreakPoint'; function isBuffer(obj) { return obj && obj.constructor && typeof obj.constructor.isBuffer === 'function' && obj.constructor.isBuffer(obj); } function keyIdentity(key) { return key; } function flatten(target, guideLineBreakpoint, opts = {}) { const delimiter = opts.delimiter || '.'; const maxDepth = opts.maxDepth; const transformKey = opts.transformKey || keyIdentity; const output = {}; function step(object, prev, currentDepth = 1) { Object.keys(object).forEach(function (key) { const value = object[key]; const isarray = opts.safe && Array.isArray(value); const isbreakpoint = hasValidBreakpointPropertyFormat(value, guideLineBreakpoint); const type = Object.prototype.toString.call(value); const isbuffer = isBuffer(value); const isobject = type === '[object Object]' || type === '[object Array]'; const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key); if (!isarray && !isbuffer && isobject && !isbreakpoint && Object.keys(value).length && (!opts.maxDepth || currentDepth < maxDepth)) { return step(value, newKey, currentDepth + 1); } output[newKey] = value; }); } step(target); return output; } export function getObjectDepth(obj, guideLineBreakpoint) { if (obj === null || obj === undefined || typeof obj !== 'object') { return 0; } const flat = flatten(obj, guideLineBreakpoint); const keys = Object.keys(flat); if (keys.length === 0) { return 1; } const depthOfKeys = keys.map(key => key.split('.').length); return Math.max(...depthOfKeys); } //# sourceMappingURL=Flatten.js.map