@cjser/math-clamp 2.2.1-cjser.2

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,38 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // packages/@cjser/math-clamp.tmp-26-1778153485081/index.js
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ default: () => mathClamp
23
+ });
24
+ module.exports = __toCommonJS(index_exports);
25
+ function mathClamp(number, { min, minimum, max, maximum }) {
26
+ min ??= minimum;
27
+ max ??= maximum;
28
+ if (min > max) {
29
+ throw new RangeError("`min` should be lower than `max`");
30
+ }
31
+ if (number < min) {
32
+ return min;
33
+ }
34
+ if (number > max) {
35
+ return max;
36
+ }
37
+ return number;
38
+ }
package/index.d.ts ADDED
@@ -0,0 +1,33 @@
1
+ import type {RequireAtLeastOne, MergeExclusive} from 'type-fest';
2
+
3
+ /**
4
+ @deprecated
5
+ */
6
+ type LegacyOptions = RequireAtLeastOne<{
7
+ minimum: number;
8
+ maximum: number;
9
+ }>;
10
+
11
+ export type Options = MergeExclusive<RequireAtLeastOne<{
12
+ min: number;
13
+ max: number;
14
+ }>, LegacyOptions>;
15
+
16
+ /**
17
+ [Clamp](https://en.wikipedia.org/wiki/Clamping_(graphics)) a number
18
+
19
+ @example
20
+ ```
21
+ import mathClamp from '@cjser/math-clamp';
22
+
23
+ mathClamp(1, {min: 2, max: 4});
24
+ //=> 2
25
+
26
+ mathClamp(1, {min: 2});
27
+ //=> 2
28
+
29
+ mathClamp(5, {max: 4});
30
+ //=> 4
31
+ ```
32
+ */
33
+ export default function mathClamp(number: number, options: Options): number;
package/index.js ADDED
@@ -0,0 +1,19 @@
1
+ export default function mathClamp(number, {min, minimum, max, maximum}) {
2
+ // TODO: Remove `minimum` and `maximum` options in the next breaking release
3
+ min ??= minimum;
4
+ max ??= maximum;
5
+
6
+ if (min > max) {
7
+ throw new RangeError('`min` should be lower than `max`');
8
+ }
9
+
10
+ if (number < min) {
11
+ return min;
12
+ }
13
+
14
+ if (number > max) {
15
+ return max;
16
+ }
17
+
18
+ return number;
19
+ }
package/license ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@cjser/math-clamp",
3
+ "version": "2.2.1-cjser.2",
4
+ "description": "Clamp a number",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://code.moenext.com/3rdeye/cjser.git"
9
+ },
10
+ "funding": "https://github.com/sponsors/sindresorhus",
11
+ "author": {
12
+ "name": "Sindre Sorhus",
13
+ "email": "sindresorhus@gmail.com",
14
+ "url": "https://sindresorhus.com"
15
+ },
16
+ "type": "module",
17
+ "exports": {
18
+ "types": "./index.d.ts",
19
+ "require": "./dist-cjser/index.cjs",
20
+ "default": "./index.js"
21
+ },
22
+ "sideEffects": false,
23
+ "engines": {
24
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
25
+ },
26
+ "scripts": {
27
+ "test": "xo && ava && tsd"
28
+ },
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "dist-cjser"
33
+ ],
34
+ "keywords": [
35
+ "math",
36
+ "number",
37
+ "numbers",
38
+ "clamp",
39
+ "limit",
40
+ "min",
41
+ "max",
42
+ "minimum",
43
+ "maximum",
44
+ "between",
45
+ "range"
46
+ ],
47
+ "dependencies": {
48
+ "type-fest": "^4.9.0"
49
+ },
50
+ "devDependencies": {
51
+ "ava": "^3.15.0",
52
+ "tsd": "^0.30.4",
53
+ "xo": "^0.44.0"
54
+ },
55
+ "types": "./index.d.ts",
56
+ "main": "./dist-cjser/index.cjs",
57
+ "cjser": {
58
+ "sourceVersion": "2.2.1",
59
+ "cjserVersion": 2,
60
+ "original": {
61
+ "name": "math-clamp",
62
+ "version": "2.2.1",
63
+ "exports": {
64
+ "types": "./index.d.ts",
65
+ "default": "./index.js"
66
+ },
67
+ "repository": "sindresorhus/math-clamp",
68
+ "dependencies": {
69
+ "type-fest": "^4.9.0"
70
+ },
71
+ "files": [
72
+ "index.js",
73
+ "index.d.ts"
74
+ ],
75
+ "scripts": {
76
+ "test": "xo && ava && tsd"
77
+ }
78
+ }
79
+ }
80
+ }
package/readme.md ADDED
@@ -0,0 +1,38 @@
1
+ # math-clamp
2
+
3
+ > [Clamp](https://en.wikipedia.org/wiki/Clamping_(graphics)) a number
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install math-clamp
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```js
14
+ import mathClamp from 'math-clamp';
15
+
16
+ mathClamp(1, {min: 2, max: 4});
17
+ //=> 2
18
+
19
+ mathClamp(1, {min: 2});
20
+ //=> 2
21
+
22
+ mathClamp(5, {max: 4});
23
+ //=> 4
24
+ ```
25
+
26
+ ## API
27
+
28
+ ### mathClamp(number, {min?, max?})
29
+
30
+ ## Related
31
+
32
+ - [math-sum](https://github.com/sindresorhus/math-sum) - Sum numbers
33
+ - [math-average](https://github.com/sindresorhus/math-average) - Get the average of numbers
34
+
35
+ ## cjser
36
+
37
+ This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
38
+ Original repository: https://github.com/sindresorhus/math-clamp