UNPKG

@easy-breezy/core

Version:
21 lines (20 loc) 524 B
import { isPlainObject } from '#helper/is-plain-object'; const comparator = (a, b) => { return a.localeCompare(b); }; export const deepSortObject = (src) => { if (Array.isArray(src)) { return src.map((item) => deepSortObject(item)); } if (isPlainObject(src)) { const result = {}; Object .keys(src) .sort(comparator) .forEach((key) => { result[key] = deepSortObject(src[key]); }); return result; } return src; };