UNPKG

nativestyler

Version:

An advanced styling toolkit for React Native applications, providing dynamic, prop-based styling with efficient caching.

34 lines (33 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.hashFunction = exports.cache = void 0; var tiny_lru_1 = require("tiny-lru"); var flatted_1 = require("flatted"); var cache = (0, tiny_lru_1.lru)(100); // Set max size to 100 or adjust as needed exports.cache = cache; function hashFunction(props, theme) { var relevantProps = Object.entries(props).reduce(function (acc, _a) { var key = _a[0], value = _a[1]; if (typeof value !== 'object' && typeof value !== 'function') { acc[key] = value; } else if (typeof value === 'object' && value !== null) { acc[key] = (0, flatted_1.stringify)(value); // Careful with nested objects } return acc; }, {}); var relevantTheme = Object.entries(theme).reduce(function (acc, _a) { var key = _a[0], value = _a[1]; if (typeof value !== 'object' && typeof value !== 'function') { acc[key] = value; } else if (typeof value === 'object' && value !== null) { acc[key] = (0, flatted_1.stringify)(value); // Careful with nested objects } return acc; }, {}); var propsString = (0, flatted_1.stringify)(relevantProps); var themeString = (0, flatted_1.stringify)(relevantTheme); return "".concat(propsString, "|").concat(themeString); } exports.hashFunction = hashFunction;