Comparing version 3.0.3 to 3.1.0
@@ -8,2 +8,8 @@ # Changelog | ||
## [3.1.0] - 2021-11-10 | ||
### Fixed | ||
* TypeScript interface to allow sorting readonly arrays if inPlaceSorting is not used | ||
## [3.0.0] - 2021-04-08 | ||
@@ -36,2 +42,3 @@ | ||
## [3.0.0] - 2021-04-08 | ||
### Changed | ||
@@ -38,0 +45,0 @@ |
@@ -20,3 +20,3 @@ declare type IOrder = 1 | -1; | ||
export declare type ISortByObjectSorter<T> = ISortByAscSorter<T> | ISortByDescSorter<T>; | ||
export declare const createNewSortInstance: (opts: ISortInstanceOptions) => <T>(_ctx: T[]) => { | ||
interface IFastSort<T> { | ||
/** | ||
@@ -28,3 +28,3 @@ * Sort array in ascending order. | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.firstName, | ||
* u => u.lastName, | ||
@@ -40,3 +40,3 @@ * ]); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.firstName, | ||
* u => u.lastName, | ||
@@ -51,76 +51,14 @@ * ]); | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* { asc: u => u.score }, | ||
* { desc: u => u.age }, | ||
* ]); | ||
*/ | ||
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[]; | ||
}; | ||
export declare const sort: <T>(_ctx: T[]) => { | ||
/** | ||
* Sort array in ascending order. | ||
* @example | ||
* sort([3, 1, 4]).asc(); | ||
* sort(users).asc(u => u.firstName); | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in descending order. | ||
* @example | ||
* sort([3, 1, 4]).desc(); | ||
* sort(users).desc(u => u.firstName); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in ascending or descending order. It allows sorting on multiple props | ||
* in different order for each of them. | ||
* @example | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* ]); | ||
*/ | ||
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[]; | ||
}; | ||
export declare const inPlaceSort: <T>(_ctx: T[]) => { | ||
/** | ||
* Sort array in ascending order. | ||
* @example | ||
* sort([3, 1, 4]).asc(); | ||
* sort(users).asc(u => u.firstName); | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in descending order. | ||
* @example | ||
* sort([3, 1, 4]).desc(); | ||
* sort(users).desc(u => u.firstName); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in ascending or descending order. It allows sorting on multiple props | ||
* in different order for each of them. | ||
* @example | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* ]); | ||
*/ | ||
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[]; | ||
}; | ||
} | ||
export declare function createNewSortInstance(opts: ISortInstanceOptions & { | ||
inPlaceSorting?: false; | ||
}): <T>(_ctx: readonly T[]) => IFastSort<T>; | ||
export declare function createNewSortInstance(opts: ISortInstanceOptions): <T>(_ctx: T[]) => IFastSort<T>; | ||
export declare const sort: <T>(_ctx: readonly T[]) => IFastSort<T>; | ||
export declare const inPlaceSort: <T>(_ctx: T[]) => IFastSort<T>; | ||
export {}; |
@@ -77,4 +77,3 @@ // >>> INTERFACES <<< | ||
}; | ||
// >>> Public <<< | ||
var createNewSortInstance = function (opts) { | ||
function createNewSortInstance(opts) { | ||
var comparer = castComparer(opts.comparer); | ||
@@ -86,37 +85,8 @@ return function (_ctx) { | ||
return { | ||
/** | ||
* Sort array in ascending order. | ||
* @example | ||
* sort([3, 1, 4]).asc(); | ||
* sort(users).asc(u => u.firstName); | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
asc: function (sortBy) { | ||
return sortArray(1, ctx, sortBy, comparer); | ||
}, | ||
/** | ||
* Sort array in descending order. | ||
* @example | ||
* sort([3, 1, 4]).desc(); | ||
* sort(users).desc(u => u.firstName); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
desc: function (sortBy) { | ||
return sortArray(-1, ctx, sortBy, comparer); | ||
}, | ||
/** | ||
* Sort array in ascending or descending order. It allows sorting on multiple props | ||
* in different order for each of them. | ||
* @example | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* ]); | ||
*/ | ||
by: function (sortBy) { | ||
@@ -127,3 +97,3 @@ return sortArray(1, ctx, sortBy, comparer); | ||
}; | ||
}; | ||
} | ||
var defaultComparer = function (a, b, order) { | ||
@@ -130,0 +100,0 @@ if (a == null) |
@@ -83,4 +83,3 @@ (function (global, factory) { | ||
}; | ||
// >>> Public <<< | ||
var createNewSortInstance = function (opts) { | ||
function createNewSortInstance(opts) { | ||
var comparer = castComparer(opts.comparer); | ||
@@ -92,37 +91,8 @@ return function (_ctx) { | ||
return { | ||
/** | ||
* Sort array in ascending order. | ||
* @example | ||
* sort([3, 1, 4]).asc(); | ||
* sort(users).asc(u => u.firstName); | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
asc: function (sortBy) { | ||
return sortArray(1, ctx, sortBy, comparer); | ||
}, | ||
/** | ||
* Sort array in descending order. | ||
* @example | ||
* sort([3, 1, 4]).desc(); | ||
* sort(users).desc(u => u.firstName); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
desc: function (sortBy) { | ||
return sortArray(-1, ctx, sortBy, comparer); | ||
}, | ||
/** | ||
* Sort array in ascending or descending order. It allows sorting on multiple props | ||
* in different order for each of them. | ||
* @example | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* ]); | ||
*/ | ||
by: function (sortBy) { | ||
@@ -133,3 +103,3 @@ return sortArray(1, ctx, sortBy, comparer); | ||
}; | ||
}; | ||
} | ||
var defaultComparer = function (a, b, order) { | ||
@@ -136,0 +106,0 @@ if (a == null) |
@@ -20,3 +20,3 @@ declare type IOrder = 1 | -1; | ||
export declare type ISortByObjectSorter<T> = ISortByAscSorter<T> | ISortByDescSorter<T>; | ||
export declare const createNewSortInstance: (opts: ISortInstanceOptions) => <T>(_ctx: T[]) => { | ||
interface IFastSort<T> { | ||
/** | ||
@@ -28,3 +28,3 @@ * Sort array in ascending order. | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.firstName, | ||
* u => u.lastName, | ||
@@ -40,3 +40,3 @@ * ]); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.firstName, | ||
* u => u.lastName, | ||
@@ -51,76 +51,14 @@ * ]); | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* { asc: u => u.score }, | ||
* { desc: u => u.age }, | ||
* ]); | ||
*/ | ||
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[]; | ||
}; | ||
export declare const sort: <T>(_ctx: T[]) => { | ||
/** | ||
* Sort array in ascending order. | ||
* @example | ||
* sort([3, 1, 4]).asc(); | ||
* sort(users).asc(u => u.firstName); | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in descending order. | ||
* @example | ||
* sort([3, 1, 4]).desc(); | ||
* sort(users).desc(u => u.firstName); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in ascending or descending order. It allows sorting on multiple props | ||
* in different order for each of them. | ||
* @example | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* ]); | ||
*/ | ||
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[]; | ||
}; | ||
export declare const inPlaceSort: <T>(_ctx: T[]) => { | ||
/** | ||
* Sort array in ascending order. | ||
* @example | ||
* sort([3, 1, 4]).asc(); | ||
* sort(users).asc(u => u.firstName); | ||
* sort(users).asc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
asc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in descending order. | ||
* @example | ||
* sort([3, 1, 4]).desc(); | ||
* sort(users).desc(u => u.firstName); | ||
* sort(users).desc([ | ||
* U => u.firstName | ||
* u => u.lastName, | ||
* ]); | ||
*/ | ||
desc(sortBy?: ISortBy<T> | ISortBy<T>[]): T[]; | ||
/** | ||
* Sort array in ascending or descending order. It allows sorting on multiple props | ||
* in different order for each of them. | ||
* @example | ||
* sort(users).by([ | ||
* { asc: u => u.score } | ||
* { desc: u => u.age } | ||
* ]); | ||
*/ | ||
by(sortBy: ISortByObjectSorter<T> | ISortByObjectSorter<T>[]): T[]; | ||
}; | ||
} | ||
export declare function createNewSortInstance(opts: ISortInstanceOptions & { | ||
inPlaceSorting?: false; | ||
}): <T>(_ctx: readonly T[]) => IFastSort<T>; | ||
export declare function createNewSortInstance(opts: ISortInstanceOptions): <T>(_ctx: T[]) => IFastSort<T>; | ||
export declare const sort: <T>(_ctx: readonly T[]) => IFastSort<T>; | ||
export declare const inPlaceSort: <T>(_ctx: T[]) => IFastSort<T>; | ||
export {}; |
{ | ||
"name": "fast-sort", | ||
"version": "3.0.3", | ||
"version": "3.1.0", | ||
"description": "Fast and powerful array sorting. Sort by any property in any direction with easy to read syntax.", | ||
@@ -9,2 +9,4 @@ "main": "dist/sort.min.js", | ||
"contributors": [ | ||
"Linus Unnebäck: https://github.com/LinusU", | ||
"Luca Ban: https://github.com/mesqueeb", | ||
"Tony Gutierrez: https://github.com/tony-gutierrez" | ||
@@ -11,0 +13,0 @@ ], |
@@ -188,2 +188,5 @@ # fast-sort | ||
Independent benchmark results from MacBook Air can be found in following PR: | ||
https://github.com/snovakovic/fast-sort/pull/48 | ||
![benchmark results](https://github.com/snovakovic/fast-sort/raw/master/benchmark.jpg) | ||
@@ -190,0 +193,0 @@ |
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
204
28938
364