How to use the @aws-amplify/core.JS.sortByField function in @aws-amplify/core

To help you get started, we’ve selected a few @aws-amplify/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-js / packages / aws-amplify-react / src / Storage / S3Album.js View on Github external
sort(list) {
        const { sort } = this.props;
        const typeof_sort = typeof sort;
        if (typeof_sort === 'function') { return sort(list); }

        if (['string', 'undefined'].includes(typeof_sort)) {
            const sort_str = sort? sort : 'lastModified';
            const parts = sort_str.split(/\s+/);
            const field = parts[0];
            let dir = parts.length > 1? parts[1] : '';
            if (field === 'lastModified') {
                dir = (dir === 'asc')? 'asc' : 'desc';
            } else {
                dir = (dir === 'desc')? 'desc' : 'asc';
            }
            JS.sortByField(list, field, dir);

            return list;
        }

        logger.warn('invalid sort. done nothing. should be a string or function');
        return list;
    }