@naturalcycles/js-lib 14.234.0 → 14.235.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.
@@ -22,8 +22,11 @@ export declare function _runLessOften(percent: number): boolean;
22
22
  * _isBetween(3, 1, 5) // true
23
23
  * _isBetween(5, 1, 5) // false
24
24
  * _isBetween(7, 1, 5) // false
25
+ *
26
+ * Also works with strings:
27
+ * _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
25
28
  */
26
- export declare function _isBetween(x: number, min: number, max: number, incl?: Inclusiveness): boolean;
29
+ export declare function _isBetween<T extends number | string>(x: T, min: T, max: T, incl?: Inclusiveness): boolean;
27
30
  export declare function _clamp(x: number, minIncl: number, maxIncl: number): number;
28
31
  /**
29
32
  * This function exists, because in JS you cannot just .sort() numbers,
@@ -34,6 +34,9 @@ exports._runLessOften = _runLessOften;
34
34
  * _isBetween(3, 1, 5) // true
35
35
  * _isBetween(5, 1, 5) // false
36
36
  * _isBetween(7, 1, 5) // false
37
+ *
38
+ * Also works with strings:
39
+ * _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
37
40
  */
38
41
  function _isBetween(x, min, max, incl = '[)') {
39
42
  if (incl === '[)') {
@@ -45,7 +48,6 @@ function _isBetween(x, min, max, incl = '[)') {
45
48
  else if (incl === '(]') {
46
49
  return x > min && x <= max;
47
50
  }
48
- // ()
49
51
  return x > min && x < max;
50
52
  }
51
53
  exports._isBetween = _isBetween;
@@ -28,6 +28,9 @@ export function _runLessOften(percent) {
28
28
  * _isBetween(3, 1, 5) // true
29
29
  * _isBetween(5, 1, 5) // false
30
30
  * _isBetween(7, 1, 5) // false
31
+ *
32
+ * Also works with strings:
33
+ * _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
31
34
  */
32
35
  export function _isBetween(x, min, max, incl = '[)') {
33
36
  if (incl === '[)') {
@@ -39,7 +42,6 @@ export function _isBetween(x, min, max, incl = '[)') {
39
42
  else if (incl === '(]') {
40
43
  return x > min && x <= max;
41
44
  }
42
- // ()
43
45
  return x > min && x < max;
44
46
  }
45
47
  export function _clamp(x, minIncl, maxIncl) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
- "version": "14.234.0",
3
+ "version": "14.235.0",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "build-prod": "build-prod-esm-cjs",
@@ -34,11 +34,14 @@ export function _runLessOften(percent: number): boolean {
34
34
  * _isBetween(3, 1, 5) // true
35
35
  * _isBetween(5, 1, 5) // false
36
36
  * _isBetween(7, 1, 5) // false
37
+ *
38
+ * Also works with strings:
39
+ * _isBetween('2020-01-03', '2020-01-01', '2020-01-05') // true
37
40
  */
38
- export function _isBetween(
39
- x: number,
40
- min: number,
41
- max: number,
41
+ export function _isBetween<T extends number | string>(
42
+ x: T,
43
+ min: T,
44
+ max: T,
42
45
  incl: Inclusiveness = '[)',
43
46
  ): boolean {
44
47
  if (incl === '[)') {
@@ -48,7 +51,6 @@ export function _isBetween(
48
51
  } else if (incl === '(]') {
49
52
  return x > min && x <= max
50
53
  }
51
- // ()
52
54
  return x > min && x < max
53
55
  }
54
56