@ptolemy2002/js-math-utils 1.0.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/README.md +56 -0
  2. package/index.js +35 -0
  3. package/package.json +35 -0
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # JS Math Utils
2
+ This library contains mathematical utilities for JavaScript development.
3
+
4
+ The functions are not exported as default, so you can import them in one of the following ways:
5
+ ```
6
+ // ES6
7
+ import { functionName } from '@ptolemy2002/js-math-utils';
8
+ // CommonJS
9
+ const { functionName } = require('@ptolemy2002/js-math-utils');
10
+ ```
11
+
12
+ ## Functions
13
+ The following functions are available in the library:
14
+
15
+ ### clamp
16
+ #### Description
17
+ Clamps a number between a minimum and maximum value.
18
+
19
+ #### Parameters
20
+ - `value` (Number): The value to be clamped.
21
+ - `min` (Number): The minimum value.
22
+ - `max` (Number): The maximum value.
23
+
24
+ #### Returns
25
+ Number - The clamped value.
26
+
27
+ ### wrapNumber
28
+ #### Description
29
+ Wraps a number between a minimum and maximum value, non-inclusive on the maximum side (so `min - 1` gets converted to `max - 1` and `max` gets converted to `min`).
30
+
31
+ #### Parameters
32
+ - `n` (Number): The number to be wrapped.
33
+ - `min` (Number): The minimum value.
34
+ - `max` (Number): The maximum value.
35
+
36
+ #### Returns
37
+ Number - The wrapped value.
38
+
39
+ ## Meta
40
+ This is a React Library Created by Ptolemy2002's [cra-template-react-library](https://www.npmjs.com/package/@ptolemy2002/cra-template-react-library) template in combination with [create-react-app](https://www.npmjs.com/package/create-react-app). It contains methods of building and publishing your library to npm.
41
+ For now, the library makes use of React 18 and does not use TypeScript.
42
+
43
+ ## Commands
44
+ The following commands exist in the project:
45
+
46
+ - `npm run uninstall` - Uninstalls all dependencies for the library
47
+ - `npm run reinstall` - Uninstalls and then Reinstalls all dependencies for the library
48
+ - `npm run example-uninstall` - Uninstalls all dependencies for the example app
49
+ - `npm run example-install` - Installs all dependencies for the example app
50
+ - `npm run example-reinstall` - Uninstalls and then Reinstalls all dependencies for the example app
51
+ - `npm run example-start` - Starts the example app after building the library
52
+ - `npm run build` - Builds the library
53
+ - `npm run release` - Publishes the library to npm without changing the version
54
+ - `npm run release-patch` - Publishes the library to npm with a patch version bump
55
+ - `npm run release-minor` - Publishes the library to npm with a minor version bump
56
+ - `npm run release-major` - Publishes the library to npm with a major version bump
package/index.js ADDED
@@ -0,0 +1,35 @@
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
+ // src/index.js
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ clamp: () => clamp,
23
+ wrapNumber: () => wrapNumber
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var import_js_utils = require("@ptolemy2002/js-utils");
27
+ function clamp(value, min, max) {
28
+ if (!(0, import_js_utils.isNullOrUndefined)(min) && value < min) return min;
29
+ if (!(0, import_js_utils.isNullOrUndefined)(max) && value > max) return max;
30
+ return value;
31
+ }
32
+ function wrapNumber(n, min, max) {
33
+ const range = max - min;
34
+ return n >= min ? min + (n - min) % range : max + (n - min) % range;
35
+ }
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@ptolemy2002/js-math-utils",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "files": [
6
+ "index.js"
7
+ ],
8
+ "scripts": {
9
+ "build": "esbuild src/index.js --bundle --format=cjs --outfile=index.js --external:@ptolemy2002/js-utils",
10
+ "postinstall": "npx typesync",
11
+ "uninstall": "bash ./scripts/uninstall.sh",
12
+ "reinstall": "bash ./scripts/reinstall.sh",
13
+ "example-uninstall": "bash ./scripts/example-uninstall.sh",
14
+ "example-install": "bash ./scripts/example-install.sh",
15
+ "example-reinstall": "bash ./scripts/example-reinstall.sh",
16
+ "example-start": "bash ./scripts/example-start.sh",
17
+ "release": "bash ./scripts/release.sh",
18
+ "release-patch": "bash ./scripts/release.sh patch",
19
+ "release-minor": "bash ./scripts/release.sh minor",
20
+ "release-major": "bash ./scripts/release.sh major"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Ptolemy2002/js-math-utils",
25
+ "directory": "lib"
26
+ },
27
+ "description": "Example of a React library",
28
+ "license": "ISC",
29
+ "peerDependencies": {
30
+ "@ptolemy2002/js-utils": "^1.0.1"
31
+ },
32
+ "devDependencies": {
33
+ "esbuild": "^0.23.0"
34
+ }
35
+ }