@rickard.antonsson/ts-utility 0.0.0 → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +25 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,2 +1,27 @@
1
1
  # ts-utility
2
2
  simple utility functions
3
+
4
+ ## Array functions
5
+
6
+ ### simpleSort
7
+ Sorts an array using supplied functions to get values to sort by.
8
+ Takes functions returning either strings or numbers.
9
+
10
+ Alternatively functions can return a tuple of [string or number, 'asc' | 'desc'].
11
+ Otherwise sortOrder will be ascending.
12
+
13
+ ```typescript
14
+ const list: {text:string, sortOrder:number} = [<...>];
15
+ const sortedList = simpleSort(list, i => i.sortOrder, i => [i.text, 'desc']); // sorts by sortOrder ascending and then by text descending
16
+ ```
17
+
18
+ #### sortedList could after this be something like:
19
+ {
20
+ sortOrder: 1, text: 'second',
21
+ sortOrder: 1, text: 'first',
22
+ sortOrder: 1, text: 'fifth',
23
+ sortOrder: 2, text: 'third',
24
+ sortOrder: 3, text: 'fourth'
25
+ }
26
+
27
+ For more examples see tests
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickard.antonsson/ts-utility",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "",
5
5
  "main": "build/src/index.js",
6
6
  "types": "build/src/index.d.ts",