@ptolemy2002/js-math-utils 1.0.2 → 2.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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  This library contains mathematical utilities for JavaScript development.
3
3
 
4
4
  The functions are not exported as default, so you can import them in one of the following ways:
5
- ```
5
+ ```javascript
6
6
  // ES6
7
7
  import { functionName } from '@ptolemy2002/js-math-utils';
8
8
  // CommonJS
@@ -37,12 +37,10 @@ Wraps a number between a minimum and maximum value, non-inclusive on the maximum
37
37
  Number - The wrapped value.
38
38
 
39
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.
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). However, it does not actually depend on React - it has been modified to work only with my own utility library. It contains methods of building and publishing your library to npm.
42
41
 
43
42
  ## Peer Dependencies
44
- These should be installed in order to use the library, as npm does not automatically add peer dependencies to your project.
45
- - @ptolemy2002/js-utils: ^1.0.1
43
+ This project does not have any peer dependencies (they are all bundled with the library), so it should work out of the box.
46
44
 
47
45
  ## Commands
48
46
  The following commands exist in the project:
@@ -0,0 +1,7 @@
1
+ type ClampOptions = {
2
+ min?: number;
3
+ max?: number;
4
+ };
5
+ export declare function clamp(value: number, { min, max }?: ClampOptions): number;
6
+ export declare function wrapNumber(n: number, min: number, max: number): number;
7
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clamp = clamp;
4
+ exports.wrapNumber = wrapNumber;
5
+ function clamp(value, { min = null, max = null } = {}) {
6
+ if (min !== null && value < min)
7
+ return min;
8
+ if (max !== null && value > max)
9
+ return max;
10
+ return value;
11
+ }
12
+ function wrapNumber(n, min, max) {
13
+ const range = max - min;
14
+ return ((n - range) % range === 0 ?
15
+ min
16
+ : n >= min ?
17
+ min + (n - min) % range
18
+ :
19
+ max + (n - min) % range);
20
+ }
package/package.json CHANGED
@@ -1,12 +1,19 @@
1
1
  {
2
2
  "name": "@ptolemy2002/js-math-utils",
3
- "version": "1.0.2",
4
- "main": "index.js",
3
+ "version": "2.0.0",
4
+ "private": false,
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
5
7
  "files": [
6
- "index.js"
8
+ "/dist"
7
9
  ],
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/Ptolemy2002/js-math-utils",
13
+ "directory": "lib"
14
+ },
8
15
  "scripts": {
9
- "build": "esbuild src/index.js --bundle --format=cjs --outfile=index.js --external:@ptolemy2002/js-utils",
16
+ "build": "tsc --project ./tsconfig.json",
10
17
  "postinstall": "npx typesync",
11
18
  "uninstall": "bash ./scripts/uninstall.sh",
12
19
  "reinstall": "bash ./scripts/reinstall.sh",
@@ -19,17 +26,5 @@
19
26
  "release-minor": "bash ./scripts/release.sh minor",
20
27
  "release-major": "bash ./scripts/release.sh major"
21
28
  },
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/Ptolemy2002/js-math-utils",
25
- "directory": "lib"
26
- },
27
- "description": "JavaScript math utilities",
28
- "license": "ISC",
29
- "peerDependencies": {
30
- "@ptolemy2002/js-utils": "^1.0.1"
31
- },
32
- "devDependencies": {
33
- "esbuild": "^0.23.0"
34
- }
29
+ "devDependencies": {}
35
30
  }
package/index.js DELETED
@@ -1,35 +0,0 @@
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
- }