@bedrock-ui/utils
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -7,2 +7,5 @@ "use strict"; | ||
array.forEach((element) => { | ||
if (map.has(element[property])) { | ||
console.warn(`duplicate key for keyBy: "${element[property]}" already exists in the map`); | ||
} | ||
map.set(element[property], element); | ||
@@ -9,0 +12,0 @@ }); |
@@ -1,1 +0,2 @@ | ||
export declare function orderBy<T>(array: T, property: string): T; | ||
import type { TypeofArray } from '../../types/array'; | ||
export declare function orderBy<T extends TypeofArray<T>[], P extends keyof TypeofArray<T>>(array: T, property: P): T[number][]; |
@@ -5,4 +5,17 @@ "use strict"; | ||
function orderBy(array, property) { | ||
return array; | ||
return [...array].sort((a, b) => { | ||
const aValue = a[property]; | ||
const bValue = b[property]; | ||
if (typeof aValue === 'string' && typeof bValue === 'string') { | ||
return aValue.localeCompare(bValue, 'en', { sensitivity: 'base' }); | ||
} | ||
if (aValue < bValue) { | ||
return -1; | ||
} | ||
if (aValue > bValue) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
} | ||
exports.orderBy = orderBy; |
export function keyBy(array, property) { | ||
const map = new Map(); | ||
array.forEach((element) => { | ||
if (map.has(element[property])) { | ||
console.warn(`duplicate key for keyBy: "${element[property]}" already exists in the map`); | ||
} | ||
map.set(element[property], element); | ||
@@ -5,0 +8,0 @@ }); |
@@ -1,1 +0,2 @@ | ||
export declare function orderBy<T>(array: T, property: string): T; | ||
import type { TypeofArray } from '../../types/array'; | ||
export declare function orderBy<T extends TypeofArray<T>[], P extends keyof TypeofArray<T>>(array: T, property: P): T[number][]; |
export function orderBy(array, property) { | ||
return array; | ||
return [...array].sort((a, b) => { | ||
const aValue = a[property]; | ||
const bValue = b[property]; | ||
if (typeof aValue === 'string' && typeof bValue === 'string') { | ||
return aValue.localeCompare(bValue, 'en', { sensitivity: 'base' }); | ||
} | ||
if (aValue < bValue) { | ||
return -1; | ||
} | ||
if (aValue > bValue) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
} |
{ | ||
"name": "@bedrock-ui/utils", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Bedrock UI Utils", | ||
@@ -35,4 +35,5 @@ "author": "Matthew Wolfe", | ||
"test": "jest", | ||
"test:coverage": "jest --coverage", | ||
"typecheck": "tsc --noEmit" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8953
181