@cloudinary-util/util
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -27,3 +27,4 @@ "use strict"; | ||
objectHasKey: () => objectHasKey, | ||
parseUrl: () => parseUrl | ||
parseUrl: () => parseUrl, | ||
sortByKey: () => sortByKey | ||
}); | ||
@@ -72,2 +73,29 @@ module.exports = __toCommonJS(src_exports); | ||
} | ||
function sortByKey(array = [], key, type = "asc") { | ||
function compare(a, b) { | ||
let keyA = a[key]; | ||
let keyB = b[key]; | ||
if (typeof keyA === "string") { | ||
keyA = keyA.toLowerCase(); | ||
} | ||
if (typeof keyB === "string") { | ||
keyB = keyB.toLowerCase(); | ||
} | ||
if (keyA < keyB) { | ||
return -1; | ||
} | ||
if (keyA > keyB) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
let newArray = [...array]; | ||
if (typeof key !== "string") | ||
return newArray; | ||
newArray = newArray.sort(compare); | ||
if (type === "desc") { | ||
return newArray.reverse(); | ||
} | ||
return newArray; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -79,3 +107,4 @@ 0 && (module.exports = { | ||
objectHasKey, | ||
parseUrl | ||
parseUrl, | ||
sortByKey | ||
}); |
@@ -44,3 +44,8 @@ /** | ||
declare function objectHasKey<T>(obj: T, key: PropertyKey): key is keyof T; | ||
/** | ||
* sortByKey | ||
* @description Sort the given array by the key of an object | ||
*/ | ||
declare function sortByKey(array: object[] | undefined, key: string, type?: string): object[]; | ||
export { encodeBase64, getPublicId, getTransformations, objectHasKey, parseUrl }; | ||
export { encodeBase64, getPublicId, getTransformations, objectHasKey, parseUrl, sortByKey }; |
@@ -27,3 +27,4 @@ "use strict"; | ||
objectHasKey: () => objectHasKey, | ||
parseUrl: () => parseUrl | ||
parseUrl: () => parseUrl, | ||
sortByKey: () => sortByKey | ||
}); | ||
@@ -72,2 +73,29 @@ module.exports = __toCommonJS(src_exports); | ||
} | ||
function sortByKey(array = [], key, type = "asc") { | ||
function compare(a, b) { | ||
let keyA = a[key]; | ||
let keyB = b[key]; | ||
if (typeof keyA === "string") { | ||
keyA = keyA.toLowerCase(); | ||
} | ||
if (typeof keyB === "string") { | ||
keyB = keyB.toLowerCase(); | ||
} | ||
if (keyA < keyB) { | ||
return -1; | ||
} | ||
if (keyA > keyB) { | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
let newArray = [...array]; | ||
if (typeof key !== "string") | ||
return newArray; | ||
newArray = newArray.sort(compare); | ||
if (type === "desc") { | ||
return newArray.reverse(); | ||
} | ||
return newArray; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -79,3 +107,4 @@ 0 && (module.exports = { | ||
objectHasKey, | ||
parseUrl | ||
parseUrl, | ||
sortByKey | ||
}); |
{ | ||
"name": "@cloudinary-util/util", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"main": "./dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "./dist/index.mjs", |
Sorry, the diff of this file is not supported yet
14128
333