-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add collate helper for custom sort orders.
- Loading branch information
Showing
7 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import isFunction from '../util/is-function.js'; | ||
import wrap from './wrap.js'; | ||
|
||
/** | ||
* Annotate a table expression with collation metadata, indicating how | ||
* expression values should be compared and sorted. The orderby verb uses | ||
* collation metadata to determine sort order. The collation information can | ||
* either take the form a standard two-argument comparator function, or as | ||
* locale and option arguments compatible with `Intl.Collator`. | ||
* @param {string|Function|object} expr The table expression to annotate | ||
* with collation metadata. | ||
* @param {Intl.LocalesArgument | ((a: any, b: any) => number)} comparator | ||
* A comparator function or the locale(s) to collate by. | ||
* @param {Intl.CollatorOptions} [options] Collation options, applicable | ||
* with locales only. | ||
* @return {object} A wrapper object representing the collated value. | ||
* @example orderby(collate('colA', 'de')) | ||
*/ | ||
export default function(expr, comparator, options) { | ||
return wrap(expr, { | ||
collate: isFunction(comparator) | ||
? comparator | ||
: new Intl.Collator(comparator, options).compare | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/** | ||
* @returns {value is Function} | ||
*/ | ||
export default function(value) { | ||
return typeof value === 'function'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters