Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3048b74b2f |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.28.2",
|
"version": "0.28.3",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -122,6 +122,8 @@ export function sortByProp(prop: string, reverse = false) {
|
|||||||
return function (a: any, b: any) {
|
return function (a: any, b: any) {
|
||||||
const aVal = dotNotation<any>(a, prop);
|
const aVal = dotNotation<any>(a, prop);
|
||||||
const bVal = dotNotation<any>(b, prop);
|
const bVal = dotNotation<any>(b, prop);
|
||||||
|
if(aVal === undefined) return 1;
|
||||||
|
if(bVal === undefined) return -1;
|
||||||
if(typeof aVal == 'number' && typeof bVal == 'number')
|
if(typeof aVal == 'number' && typeof bVal == 'number')
|
||||||
return (reverse ? -1 : 1) * (aVal - bVal);
|
return (reverse ? -1 : 1) * (aVal - bVal);
|
||||||
if(aVal > bVal) return reverse ? -1 : 1;
|
if(aVal > bVal) return reverse ? -1 : 1;
|
||||||
|
|||||||
@@ -62,6 +62,11 @@ describe('Object utilities', () => {
|
|||||||
dotNotation(obj, 'd.e.f', 5);
|
dotNotation(obj, 'd.e.f', 5);
|
||||||
expect(obj.d.e.f).toBe(5);
|
expect(obj.d.e.f).toBe(5);
|
||||||
});
|
});
|
||||||
|
it('undefined', () => {
|
||||||
|
const obj: any = {a: 1};
|
||||||
|
const resp = dotNotation(obj, 'a.b');
|
||||||
|
expect(resp).toBe(undefined);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('encodeQuery', () => {
|
describe('encodeQuery', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user