It appears you have a well-structured Git repository with various files, including SVG icons and HTML documents. Here's a brief overview:
This commit is contained in:
201
backend/node_modules/thenby/LICENSE.TXT
generated
vendored
Normal file
201
backend/node_modules/thenby/LICENSE.TXT
generated
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
159
backend/node_modules/thenby/README.md
generated
vendored
Normal file
159
backend/node_modules/thenby/README.md
generated
vendored
Normal file
@ -0,0 +1,159 @@
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
|
||||
|
||||
- [thenBy.js usage](#thenbyjs-usage)
|
||||
- [Sort by property names](#sort-by-property-names)
|
||||
- [Sort by unary functions](#sort-by-unary-functions)
|
||||
- [Extra options](#extra-options)
|
||||
- [Sort descending](#sort-descending)
|
||||
- [Case insensitive sorting](#case-insensitive-sorting)
|
||||
- [Custom compare function](#custom-compare-function)
|
||||
- [Internationalization: Using javascripts native `Intl.Collator`](#internationalization-using-javascripts-native-intlcollator)
|
||||
- [A word on performance](#a-word-on-performance)
|
||||
- [Installing](#installing)
|
||||
- [Install in your HTML](#install-in-your-html)
|
||||
- [Install using npm or yarn](#install-using-npm-or-yarn)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
# thenBy.js usage
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
|
||||
`thenBy` is a javascript micro library that helps sorting arrays on multiple keys. It allows you to use the [native Array::sort() method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) of javascript, but pass in multiple functions to sort that are composed with `firstBy().thenBy().thenBy()` style.
|
||||
|
||||
Example:
|
||||
```javascript
|
||||
// first by length of name, then by population, then by ID
|
||||
data.sort(
|
||||
firstBy(function (v1, v2) { return v1.name.length - v2.name.length; })
|
||||
.thenBy(function (v1, v2) { return v1.population - v2.population; })
|
||||
.thenBy(function (v1, v2) { return v1.id - v2.id; })
|
||||
);
|
||||
```
|
||||
`thenBy` also offers some nice shortcuts that make the most common ways of sorting even easier and more readable.
|
||||
|
||||
### Sort by property names
|
||||
Javascript sorting relies heavily on passing discriminator functions that return -1, 0 or 1 for a pair of items. While this is very flexible, often you want to sort on the value of a simple property. As a convenience, thenBy.js builds the appropriate compare function for you if you pass in a property name (instead of a function). The example above would then look like this:
|
||||
```javascript
|
||||
// first by length of name, then by population, then by ID
|
||||
data.sort(
|
||||
firstBy(function (v1, v2) { return v1.name.length - v2.name.length; })
|
||||
.thenBy("population")
|
||||
.thenBy("id")
|
||||
);
|
||||
```
|
||||
|
||||
If an element doesn't have the property defined, it will sort like the empty string (""). Typically, this will be at the top.
|
||||
|
||||
### Sort by unary functions
|
||||
You can also pass a function that takes a single item and returns its sorting key. This turns the above expression into:
|
||||
```javascript
|
||||
// first by length of name, then by population, then by ID
|
||||
data.sort(
|
||||
firstBy(function (v) { return v.name.length; })
|
||||
.thenBy("population")
|
||||
.thenBy("id")
|
||||
);
|
||||
```
|
||||
|
||||
Note that javascript contains a number of standard functions that can be passed in here as well. The Number() function will make your sorting sort on numeric values instead of lexical values:
|
||||
```javascript
|
||||
var values = ["2", "20", "03", "-2", "0", 200, "2"];
|
||||
var sorted = values.sort(firstBy(Number));
|
||||
```
|
||||
## Extra options
|
||||
### Sort descending
|
||||
thenBy.js allows you to pass in a second parameter for `direction`. If you pass in 'desc' or -1, the sorting will be reversed. So:
|
||||
```javascript
|
||||
// first by length of name descending, then by population descending, then by ID ascending
|
||||
data.sort(
|
||||
firstBy(function (v1, v2) { return v1.name.length - v2.name.length; }, -1)
|
||||
.thenBy("population", "desc")
|
||||
.thenBy("id")
|
||||
);
|
||||
```
|
||||
|
||||
### Case insensitive sorting
|
||||
(as of v1.2.0) All of the shortcut methods allow you to sort case insensitive as well. The second parameter expects an options object (if it is a number, it is interpreted as `direction` as above). The ignoreCase property can be set to true, like this:
|
||||
```javascript
|
||||
// first by name, case insensitive, then by population
|
||||
data.sort(
|
||||
firstBy("name", {ignoreCase:true})
|
||||
.thenBy("population")
|
||||
);
|
||||
```
|
||||
If you want to use both descending and ignoreCase, you have to use the options syntax for direction as well:
|
||||
```javascript
|
||||
// sort by name, case insensitive and descending
|
||||
data.sort(firstBy("name", {ignoreCase:true, direction:"desc"}));
|
||||
```
|
||||
### Custom compare function
|
||||
If you have more specific wishes for the exact sort order, but still want to use the convenience of unary functions or sorting on property names, you can pass in you own compare function in the options. Here we use a compare function that known about the relative values of playing cards::
|
||||
|
||||
```javascript
|
||||
const cards = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'];
|
||||
var cardCompare = (c1, c2) =>{
|
||||
return cards.indexOf(c1) - cards.indexOf(c2);
|
||||
}
|
||||
var handOfCards = [
|
||||
{ id: 7, suit:"c", card:"A" },
|
||||
{ id: 8, suit:"d", card:"10" },
|
||||
// etc
|
||||
];
|
||||
handOfCards.sort(firstBy("card", {cmp: cardCompare, direction: "desc"}));
|
||||
|
||||
```
|
||||
You can use the `cmp` function together with `direction`, but not with `ignoreCase` (for obvious reasons).
|
||||
|
||||
### Internationalization: Using javascripts native `Intl.Collator`
|
||||
One of the more interesting custom compare functions you may want to pass in is the native `compare` function that is exposed by `Intl.Collator`. This compare function knows about the different sorting rules in different cultures. Many browsers have these implemented, but in NodeJS, the API is implemented, but only for the English culture. You would use it with thenBy like this:
|
||||
|
||||
```javascript
|
||||
// in German, ä sorts with a
|
||||
var germanCompare = new Intl.Collator('de').compare;
|
||||
// in Swedish, ä sorts after z
|
||||
var swedishCompare = new Intl.Collator('sv').compare;
|
||||
data.sort(
|
||||
firstBy("name", {cmp: swedishCompare})
|
||||
);
|
||||
```
|
||||
Check the [details on using Intl.Collator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Collator).
|
||||
|
||||
## A word on performance
|
||||
thenBy constructs a comparer function for you. It does this by combining the functions you pass in with a number of small utility functions that perform tasks like "reverting", "combining the current sort order with the previous one", etc. Also, these operations try to work correctly, no matter what content is in the sorted array. There are two steps here that cost time: constructing the über-function and running it. The construction time should always be negligible. The run time however can be slower than when you carefully handcraft the compare function. Still, *normally you shouldn't worry about this*, but if you're sorting very large sets, it could matter. For example, there is some overhead in making several small functions call each other instead of creating one piece of code. Also, if you know your data well, and know that a specific field is *alwways present* and is *always a number*, you could code a significantly faster compare function then thenBy's results. The unit tests contain an extreme example.
|
||||
|
||||
If you use thenBy to combine multiple compare functions into one (where each function expects two parameters), the difference is small. Using unary functions adds some overhead, using direction:desc adds some, using only a property name adds a little, but will check for missing values, which could be optimized. Ignoring case will slow down, but not more so than when handcoded.
|
||||
|
||||
## Installing
|
||||
### Install in your HTML
|
||||
To include it into your page/project, just paste the minified code from https://raw.github.com/Teun/thenBy.js/master/thenBy.min.js into yours (699 characters). If you don't want the `firstBy` function in your global namespace, you can assign it to a local variable (see sample.htm).
|
||||
|
||||
### Install using npm or yarn
|
||||
```npm install thenby```
|
||||
|
||||
or
|
||||
|
||||
```yarn add thenby```
|
||||
|
||||
then in your app:
|
||||
|
||||
```var firstBy = require('thenby');```
|
||||
|
||||
or in TypeScript/ES6:
|
||||
|
||||
```import {firstBy} from "thenby";```
|
||||
|
||||
For a small demo of how TypeScript support looks in a good editor (i.e. VS Code), [check this short video](https://youtu.be/mKJovFLyxro).
|
||||
|
||||
|
||||
Thanks a lot to [bergus](https://github.com/bergus), [hagabaka](https://github.com/hagabaka), [infolyzer](https://github.com/infolyzer) and [Foxhoundn](https://github.com/Foxhoundn) for their improvements.
|
||||
Thanks to [jsgoupil](https://github.com/jsgoupil) and [HonoluluHenk](https://github.com/HonoluluHenk) for their help on the TypeScript declaration.
|
||||
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/thenby.svg
|
||||
[npm-url]: https://npmjs.org/package/thenby
|
||||
[downloads-image]: https://img.shields.io/npm/dm/thenby.svg
|
||||
[downloads-url]: https://npmjs.org/package/thenby
|
45
backend/node_modules/thenby/package.json
generated
vendored
Normal file
45
backend/node_modules/thenby/package.json
generated
vendored
Normal file
@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "thenby",
|
||||
"version": "1.3.4",
|
||||
"description": "Micro library for sorting arrays using the firstBy().thenBy().thenBy() syntax",
|
||||
"main": "thenBy.module.js",
|
||||
"types": "thenBy.module.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Teun/thenBy.js.git"
|
||||
},
|
||||
"keywords": [
|
||||
"sort",
|
||||
"order",
|
||||
"sorting",
|
||||
"arrays",
|
||||
"multiple"
|
||||
],
|
||||
"files": [
|
||||
"thenBy.module.js",
|
||||
"thenBy.module.d.ts",
|
||||
"thenBy.min.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "gulp",
|
||||
"build": "gulp build"
|
||||
},
|
||||
"author": "Teun Duynstee",
|
||||
"license": "Apache-2.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Teun/thenBy.js/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Teun/thenBy.js",
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
"gulp": "^4.0.2",
|
||||
"gulp-insert": "^0.5.0",
|
||||
"gulp-mocha": "^7.0.2",
|
||||
"gulp-rename": "^1.2.2",
|
||||
"gulp-replace": "^0.5.4",
|
||||
"gulp-uglify": "^2.1.2",
|
||||
"gulp-umd": "^2.0.0",
|
||||
"performance-now": "^0.2.0"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
2
backend/node_modules/thenby/thenBy.min.js
generated
vendored
Normal file
2
backend/node_modules/thenby/thenBy.min.js
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/*** Copyright 2020 Teun Duynstee Licensed under the Apache License, Version 2.0 ***/
|
||||
!function(n,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?module.exports=t():n.firstBy=t()}(this,function(){return function(){function n(n){return n}function t(n){return"string"==typeof n?n.toLowerCase():n}function e(e,r){if(r="object"==typeof r?r:{direction:r},"function"!=typeof e){var i=e;e=function(n){return n[i]?n[i]:""}}if(1===e.length){var o=e,f=r.ignoreCase?t:n,u=r.cmp||function(n,t){return n<t?-1:n>t?1:0};e=function(n,t){return u(f(o(n)),f(o(t)))}}const c={"-1":"",desc:""};return r.direction in c?function(n,t){return-e(n,t)}:e}function r(n,t){var i="function"==typeof this&&!this.firstBy&&this,o=e(n,t),f=i?function(n,t){return i(n,t)||o(n,t)}:o;return f.thenBy=r,f}return r.firstBy=r,r}()});
|
51
backend/node_modules/thenby/thenBy.module.d.ts
generated
vendored
Normal file
51
backend/node_modules/thenby/thenBy.module.d.ts
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
// Type definitions for thenBy
|
||||
// Definitions by: Teun Duynstee (with significant help from @HonoluluHenk)
|
||||
type SortOrder = "asc" | "desc" | -1 | 1;
|
||||
declare class opt {
|
||||
direction?:SortOrder;
|
||||
ignoreCase?:boolean;
|
||||
}
|
||||
declare class typedOpt<T> extends opt {
|
||||
cmp?: (a:T, b:T)=> number;
|
||||
}
|
||||
interface IThenBy<T> {
|
||||
(v1: T, v2: T) : number;
|
||||
/**
|
||||
* Full format to compare two elements and determine which sorts first.
|
||||
* @param compare function that receives two values from the sorted array and returns a number indicating which comes first: < 0: first comes first, 0: doesn't matter, > 0: second comes first.
|
||||
* @param direction can be used to reverse the sorting by passing -1
|
||||
**/
|
||||
thenBy<T>(compare: ((v1: T, v2: T) => number), direction?: SortOrder | opt): IThenBy<T>;
|
||||
/**
|
||||
* Shorthand for selecting a value to sort on from the sorted element.
|
||||
* @param select function that receives a value from the sorted array and selects the thing to sort on
|
||||
* @param direction reverse by passing -1. opt for other options
|
||||
**/
|
||||
thenBy<T, U>(select: ((v: T) => U), direction?: SortOrder | typedOpt<U>): IThenBy<T>;
|
||||
/**
|
||||
* Shorthand for sorting on a simple property.
|
||||
* @param byPropertyName is the name of the property to sort on as a string
|
||||
* @param direction reverse by passing -1. opt for other options
|
||||
**/
|
||||
thenBy<T>(byPropertyName: (keyof T), direction?: SortOrder | typedOpt<any>): IThenBy<T>;
|
||||
}
|
||||
declare module "thenby" {
|
||||
/**
|
||||
* Full format to compare two elements and determine which sorts first.
|
||||
* @param compare function that receives two values from the sorted array and returns a number indicating which comes first: < 0: first comes first, 0: doesn't matter, > 0: second comes first.
|
||||
* @param direction can be used to reverse the sorting by passing -1
|
||||
**/
|
||||
export function firstBy<T>(compare: ((v1: T, v2: T) => number), direction?: SortOrder | opt): IThenBy<T>;
|
||||
/**
|
||||
* Shorthand for selecting a value to sort on from the sorted element.
|
||||
* @param select function that receives a value from the sorted array and selects the thing to sort on
|
||||
* @param direction reverse by passing -1. opt for other options
|
||||
**/
|
||||
export function firstBy<T,U>(select: ((v: T) => U), direction?: SortOrder | typedOpt<U>): IThenBy<T>;
|
||||
/**
|
||||
* Shorthand for sorting on a simple property.
|
||||
* @param byPropertyName is the name of the property to sort on as a string
|
||||
* @param direction reverse by passing -1. opt for other options
|
||||
**/
|
||||
export function firstBy<T>(byPropertyName: (keyof T), direction?: SortOrder | typedOpt<any>): IThenBy<T>;
|
||||
}
|
60
backend/node_modules/thenby/thenBy.module.js
generated
vendored
Normal file
60
backend/node_modules/thenby/thenBy.module.js
generated
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/***
|
||||
Copyright 2013 Teun Duynstee
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
module.exports = (function() {
|
||||
|
||||
function identity(v){return v;}
|
||||
|
||||
function ignoreCase(v){return typeof(v)==="string" ? v.toLowerCase() : v;}
|
||||
|
||||
function makeCompareFunction(f, opt){
|
||||
opt = typeof(opt)==="object" ? opt : {direction:opt};
|
||||
|
||||
if(typeof(f)!="function"){
|
||||
var prop = f;
|
||||
// make unary function
|
||||
f = function(v1){return !!v1[prop] ? v1[prop] : "";}
|
||||
}
|
||||
if(f.length === 1) {
|
||||
// f is a unary function mapping a single item to its sort score
|
||||
var uf = f;
|
||||
var preprocess = opt.ignoreCase?ignoreCase:identity;
|
||||
var cmp = opt.cmp || function(v1,v2) {return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;}
|
||||
f = function(v1,v2) {return cmp(preprocess(uf(v1)), preprocess(uf(v2)));}
|
||||
}
|
||||
const descTokens = {"-1":'', desc:''};
|
||||
if(opt.direction in descTokens) return function(v1,v2){return -f(v1,v2)};
|
||||
return f;
|
||||
}
|
||||
|
||||
/* adds a secondary compare function to the target function (`this` context)
|
||||
which is applied in case the first one returns 0 (equal)
|
||||
returns a new compare function, which has a `thenBy` method as well */
|
||||
function tb(func, opt) {
|
||||
/* should get value false for the first call. This can be done by calling the
|
||||
exported function, or the firstBy property on it (for es6 module compatibility)
|
||||
*/
|
||||
var x = (typeof(this) == "function" && !this.firstBy) ? this : false;
|
||||
var y = makeCompareFunction(func, opt);
|
||||
var f = x ? function(a, b) {
|
||||
return x(a,b) || y(a,b);
|
||||
}
|
||||
: y;
|
||||
f.thenBy = tb;
|
||||
return f;
|
||||
}
|
||||
tb.firstBy = tb;
|
||||
return tb;
|
||||
})();
|
Reference in New Issue
Block a user