@ptolemy2002/js-math-utils 1.0.3 → 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
@@ -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.3",
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",
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,16 +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
- "devDependencies": {
31
- "@ptolemy2002/js-utils": "^1.0.1",
32
- "esbuild": "^0.23.0"
33
- }
29
+ "devDependencies": {}
34
30
  }
package/index.js DELETED
@@ -1,145 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __commonJS = (cb, mod) => function __require() {
8
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
- };
10
- var __export = (target, all) => {
11
- for (var name in all)
12
- __defProp(target, name, { get: all[name], enumerable: true });
13
- };
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
-
32
- // node_modules/@ptolemy2002/js-utils/index.js
33
- var require_js_utils = __commonJS({
34
- "node_modules/@ptolemy2002/js-utils/index.js"(exports, module2) {
35
- var __defProp2 = Object.defineProperty;
36
- var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
37
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
38
- var __hasOwnProp2 = Object.prototype.hasOwnProperty;
39
- var __export2 = (target, all) => {
40
- for (var name in all)
41
- __defProp2(target, name, { get: all[name], enumerable: true });
42
- };
43
- var __copyProps2 = (to, from, except, desc) => {
44
- if (from && typeof from === "object" || typeof from === "function") {
45
- for (let key of __getOwnPropNames2(from))
46
- if (!__hasOwnProp2.call(to, key) && key !== except)
47
- __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
48
- }
49
- return to;
50
- };
51
- var __toCommonJS2 = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
52
- var src_exports2 = {};
53
- __export2(src_exports2, {
54
- Callable: () => Callable,
55
- ext_hasNestedProperty: () => ext_hasNestedProperty,
56
- isNullOrUndefined: () => isNullOrUndefined2,
57
- listInPlainEnglish: () => listInPlainEnglish,
58
- loadExtension: () => loadExtension,
59
- unloadExtension: () => unloadExtension
60
- });
61
- module2.exports = __toCommonJS2(src_exports2);
62
- function ext_hasNestedProperty(prop = "") {
63
- if (typeof prop === "string") prop = prop.split(".");
64
- if (!Array.isArray(prop)) return this.hasOwnProperty(prop);
65
- let obj = this;
66
- for (let i = 0; i < prop.length; i++) {
67
- const p = prop[i];
68
- if (!obj?.hasOwnProperty(p)) return false;
69
- obj = obj[p];
70
- }
71
- return true;
72
- }
73
- function loadExtension(name, func, base = Object) {
74
- if (base.prototype.hasOwnProperty(name)) return;
75
- Object.defineProperty(base.prototype, name, {
76
- value: func,
77
- enumerable: false,
78
- writable: true,
79
- configurable: true
80
- });
81
- }
82
- function unloadExtension(name, base = Object) {
83
- delete base.prototype[name];
84
- }
85
- function listInPlainEnglish(list, { max = void 0, conjunction = "and" } = {}) {
86
- if (max === void 0) max = list.length;
87
- if (list.length === 0) {
88
- return "";
89
- }
90
- if (list.length === 1) {
91
- return list[0];
92
- }
93
- if (list.length === 2) {
94
- return `${list[0]} ${conjunction} ${list[1]}`;
95
- }
96
- list = list.map((v, i) => {
97
- if (i === list.length - 1) return v;
98
- if (v.endsWith(`"`)) {
99
- return v.slice(0, -1) + `," `;
100
- } else if (v.endsWith(`'`)) {
101
- return v.slice(0, -1) + `,' `;
102
- } else {
103
- return v + ", ";
104
- }
105
- });
106
- if (list.length > max) {
107
- return `${list.slice(0, max).join("")}${conjunction} ${list.length - max} more`;
108
- } else {
109
- return `${list.slice(0, -1).join("")}${conjunction} ${list[list.length - 1]}`;
110
- }
111
- }
112
- function isNullOrUndefined2(v) {
113
- return v === null || v === void 0;
114
- }
115
- var Callable = class extends Function {
116
- constructor() {
117
- super("...args", "return this.__self__.__call__(...args)");
118
- let self = this.bind(this);
119
- this.__self__ = self;
120
- return self;
121
- }
122
- // This should be overridden by the subclass
123
- __call__() {
124
- }
125
- };
126
- }
127
- });
128
-
129
- // src/index.js
130
- var src_exports = {};
131
- __export(src_exports, {
132
- clamp: () => clamp,
133
- wrapNumber: () => wrapNumber
134
- });
135
- module.exports = __toCommonJS(src_exports);
136
- var import_js_utils = __toESM(require_js_utils());
137
- function clamp(value, min, max) {
138
- if (!(0, import_js_utils.isNullOrUndefined)(min) && value < min) return min;
139
- if (!(0, import_js_utils.isNullOrUndefined)(max) && value > max) return max;
140
- return value;
141
- }
142
- function wrapNumber(n, min, max) {
143
- const range = max - min;
144
- return (n - range) % range === 0 ? min : n >= min ? min + (n - min) % range : max + (n - min) % range;
145
- }