mirror of
https://github.com/hashicorp/vault.git
synced 2025-12-25 11:21:11 +01:00
* license: update headers to IBM Corp. * `make proto` * update offset because source file changed Signed-off-by: Ryan Cragun <me@ryan.ec> Co-authored-by: Ryan Cragun <me@ryan.ec>
24 lines
682 B
JavaScript
24 lines
682 B
JavaScript
/**
|
|
* Copyright IBM Corp. 2016, 2025
|
|
* SPDX-License-Identifier: BUSL-1.1
|
|
*/
|
|
|
|
/*
|
|
this util sorts the original array
|
|
pass in a copy of the array, i.e. myArray.slice(), if you do not want to modify the original array
|
|
*/
|
|
export default function sortObjects(array, key) {
|
|
if (Array.isArray(array) && array?.every((e) => e[key] && typeof e[key] === 'string')) {
|
|
return array.sort((a, b) => {
|
|
// ignore upper vs lowercase
|
|
const valueA = a[key].toUpperCase();
|
|
const valueB = b[key].toUpperCase();
|
|
if (valueA < valueB) return -1;
|
|
if (valueA > valueB) return 1;
|
|
return 0;
|
|
});
|
|
}
|
|
// if not sortable, return original array
|
|
return array;
|
|
}
|