@webdeveric/utils 0.49.1 → 0.50.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.
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNumberRangePredicate = void 0;
4
+ const assertIsNumber_js_1 = require("../assertion/assertIsNumber.js");
5
+ const isNumber_js_1 = require("../predicate/isNumber.js");
6
+ const createNumberRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
7
+ (0, assertIsNumber_js_1.assertIsNumber)(min, 'min is not a number');
8
+ (0, assertIsNumber_js_1.assertIsNumber)(max, 'max is not a number');
9
+ if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
10
+ throw new RangeError('min and max cannot be -Infinity and Infinity');
11
+ }
12
+ if (min > max) {
13
+ throw new RangeError('min cannot be greater than max');
14
+ }
15
+ if (min === max) {
16
+ throw new RangeError('min and max cannot be the same');
17
+ }
18
+ return (input) => (0, isNumber_js_1.isNumber)(input) && input >= min && input <= max;
19
+ };
20
+ exports.createNumberRangePredicate = createNumberRangePredicate;
@@ -19,6 +19,8 @@ __exportStar(require("./anyOf.js"), exports);
19
19
  __exportStar(require("./createIsEnumPredicate.js"), exports);
20
20
  __exportStar(require("./createIsInstanceOfPredicate.js"), exports);
21
21
  __exportStar(require("./createIsTuplePredicate.js"), exports);
22
+ __exportStar(require("./createNumberRangePredicate.js"), exports);
23
+ __exportStar(require("./createObjectShapePredicate.js"), exports);
22
24
  __exportStar(require("./createStringLengthRangePredicate.js"), exports);
23
25
  __exportStar(require("./createStringMatchingPredicate.js"), exports);
24
26
  __exportStar(require("./everyItem.js"), exports);
@@ -0,0 +1,16 @@
1
+ import { assertIsNumber } from '../assertion/assertIsNumber.js';
2
+ import { isNumber } from '../predicate/isNumber.js';
3
+ export const createNumberRangePredicate = (min, max = Number.POSITIVE_INFINITY) => {
4
+ assertIsNumber(min, 'min is not a number');
5
+ assertIsNumber(max, 'max is not a number');
6
+ if (min === Number.NEGATIVE_INFINITY && max === Number.POSITIVE_INFINITY) {
7
+ throw new RangeError('min and max cannot be -Infinity and Infinity');
8
+ }
9
+ if (min > max) {
10
+ throw new RangeError('min cannot be greater than max');
11
+ }
12
+ if (min === max) {
13
+ throw new RangeError('min and max cannot be the same');
14
+ }
15
+ return (input) => isNumber(input) && input >= min && input <= max;
16
+ };
@@ -3,6 +3,8 @@ export * from './anyOf.js';
3
3
  export * from './createIsEnumPredicate.js';
4
4
  export * from './createIsInstanceOfPredicate.js';
5
5
  export * from './createIsTuplePredicate.js';
6
+ export * from './createNumberRangePredicate.js';
7
+ export * from './createObjectShapePredicate.js';
6
8
  export * from './createStringLengthRangePredicate.js';
7
9
  export * from './createStringMatchingPredicate.js';
8
10
  export * from './everyItem.js';
@@ -0,0 +1,2 @@
1
+ import type { TypePredicateFn } from '../types/functions.js';
2
+ export declare const createNumberRangePredicate: <Type extends number = number>(min: number, max?: number) => TypePredicateFn<Type>;
@@ -3,6 +3,8 @@ export * from './anyOf.js';
3
3
  export * from './createIsEnumPredicate.js';
4
4
  export * from './createIsInstanceOfPredicate.js';
5
5
  export * from './createIsTuplePredicate.js';
6
+ export * from './createNumberRangePredicate.js';
7
+ export * from './createObjectShapePredicate.js';
6
8
  export * from './createStringLengthRangePredicate.js';
7
9
  export * from './createStringMatchingPredicate.js';
8
10
  export * from './everyItem.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@webdeveric/utils",
3
3
  "description": "Just another collection of utilities.",
4
- "version": "0.49.1",
4
+ "version": "0.50.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },