@pkmn/randoms 0.10.7 → 0.10.9

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.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ type Comparable = number | string | boolean | Comparable[] | {
2
+ reverse: Comparable;
3
+ };
4
+ /** Forces num to be an integer (between min and max). */
5
+ declare function clampIntRange(num: any, min?: number, max?: number): number;
6
+ /**
7
+ * Compares two variables; intended to be used as a smarter comparator.
8
+ * The two variables must be the same type (TypeScript will not check this).
9
+ *
10
+ * - Numbers are sorted low-to-high, use `-val` to reverse
11
+ * - Strings are sorted A to Z case-semi-insensitively, use `{reverse: val}` to reverse
12
+ * - Booleans are sorted true-first (REVERSE of casting to numbers), use `!val` to reverse
13
+ * - Arrays are sorted lexically in the order of their elements
14
+ *
15
+ * In other words: `[num, str]` will be sorted A to Z, `[num, {reverse: str}]` will be sorted Z to A.
16
+ */
17
+ declare function compare(a: Comparable, b: Comparable): number;
18
+ /**
19
+ * Sorts an array according to the callback's output on its elements.
20
+ *
21
+ * The callback's output is compared according to `PSUtils.compare`
22
+ * (numbers low to high, strings A-Z, booleans true-first, arrays in order).
23
+ */
24
+ declare function sortBy<T>(array: T[], callback: (a: T) => Comparable): T[];
25
+ /**
26
+ * Sorts an array according to `PSUtils.compare`
27
+ * (numbers low to high, strings A-Z, booleans true-first, arrays in order).
28
+ *
29
+ * Note that array.sort() only works on strings, not numbers, so you'll need
30
+ * this to sort numbers.
31
+ */
32
+ declare function sortBy<T extends Comparable>(array: T[]): T[];
33
+ declare class Multiset<T> extends Map<T, number> {
34
+ get(key: T): number;
35
+ add(key: T): this;
36
+ remove(key: T): boolean;
37
+ }
38
+ export declare const Utils: {
39
+ clampIntRange: typeof clampIntRange;
40
+ compare: typeof compare;
41
+ sortBy: typeof sortBy;
42
+ Multiset: typeof Multiset;
43
+ };
44
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pkmn/randoms",
3
- "version": "0.10.7",
3
+ "version": "0.10.9",
4
4
  "description": "Random team generation logic for Pokémon Showdown's Random Battle formats",
5
5
  "repository": "github:pkmn/ps",
6
6
  "license": "MIT",
@@ -15,7 +15,7 @@
15
15
  "build"
16
16
  ],
17
17
  "dependencies": {
18
- "@pkmn/sim": "^0.10.7"
18
+ "@pkmn/sim": "^0.10.9"
19
19
  },
20
20
  "scripts": {
21
21
  "lint": "eslint --cache src",