/*!
 * React Native Globalize
 *
 * Copyright 2015-2020 Josh Swan
 * Released under the MIT license
 * https://github.com/joshswan/react-native-globalize/blob/master/LICENSE
 */
export function createCache() {
    return {
        currency: {},
        date: {},
        dateParsers: {},
        message: {},
        number: {},
        numberParsers: {},
        plural: {},
        relativeTime: {},
        unit: {},
    };
}
function orderedProps(obj) {
    return Object.keys(obj).sort().map((key) => ({ [key]: obj[key] }));
}
function getCacheKey(args) {
    return JSON.stringify(args.map((arg) => (!!arg && typeof arg === 'object' ? orderedProps(arg) : arg)));
}
export const memoizeFormatter = (formatterCreator, cache) => (...args) => {
    const cacheId = getCacheKey(args);
    if (!cache[cacheId]) {
        // eslint-disable-next-line no-param-reassign
        cache[cacheId] = formatterCreator(...args);
    }
    return cache[cacheId];
};
