UNPKG

@chakra-v2/styled-system

Version:

Style function for css-in-js building component libraries

36 lines (33 loc) 901 B
'use strict'; function get(obj, path, fallback, index) { const key = typeof path === "string" ? path.split(".") : [path]; for (index = 0; index < key.length; index += 1) { if (!obj) break; obj = obj[key[index]]; } return obj === void 0 ? fallback : obj; } const memoize = (fn) => { const cache = /* @__PURE__ */ new WeakMap(); const memoizedFn = (obj, path, fallback, index) => { if (typeof obj === "undefined") { return fn(obj, path, fallback); } if (!cache.has(obj)) { cache.set(obj, /* @__PURE__ */ new Map()); } const map = cache.get(obj); if (map.has(path)) { return map.get(path); } const value = fn(obj, path, fallback, index); map.set(path, value); return value; }; return memoizedFn; }; const memoizedGet = memoize(get); exports.get = get; exports.memoize = memoize; exports.memoizedGet = memoizedGet;