cafe-utility 10.14.0 → 10.15.0

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 (3) hide show
  1. package/index.d.ts +1 -1
  2. package/index.js +10 -5
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -18,7 +18,7 @@ declare function makeSeededRng(seed: number): () => number;
18
18
  declare function intBetween(min: number, max: number, generator?: () => number): number;
19
19
  declare function floatBetween(min: number, max: number, generator?: () => number): number;
20
20
  declare function signedRandom(): number;
21
- declare function chance(threshold: number): boolean;
21
+ declare function chance(threshold: number, generator?: () => number): boolean;
22
22
  declare function pick<T>(array: T[], generator?: () => number): T;
23
23
  declare function pickMany<T>(array: T[], count: number, generator?: () => number): T[];
24
24
  declare function pickManyUnique<T>(array: T[], count: number, equalityFunction: (a: T, b: T) => boolean, generator?: () => number): T[];
package/index.js CHANGED
@@ -138,8 +138,8 @@ function signedRandom() {
138
138
  return Math.random() * 2 - 1
139
139
  }
140
140
 
141
- function chance(threshold) {
142
- return Math.random() < threshold
141
+ function chance(threshold, generator = Math.random) {
142
+ return generator() < threshold
143
143
  }
144
144
 
145
145
  function pick(array, generator = Math.random) {
@@ -1567,11 +1567,16 @@ function describeMarkdown(string) {
1567
1567
 
1568
1568
  function isBalanced(string, opening = '(', closing = ')') {
1569
1569
  let weight = 0
1570
- for (const character of string) {
1571
- if (character === opening) {
1570
+ let i = 0
1571
+ while (i < string.length) {
1572
+ if (string.startsWith(opening, i)) {
1572
1573
  weight++
1573
- } else if (character === closing) {
1574
+ i += opening.length
1575
+ } else if (string.startsWith(closing, i)) {
1574
1576
  weight--
1577
+ i += closing.length
1578
+ } else {
1579
+ i++
1575
1580
  }
1576
1581
  if (weight < 0) {
1577
1582
  return false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "10.14.0",
3
+ "version": "10.15.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {