@ptolemy2002/js-math-utils 1.0.1 → 1.0.3
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 +4 -2
- package/index.js +112 -2
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -37,8 +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
|
-
|
|
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.
|
|
41
|
+
|
|
42
|
+
## Peer Dependencies
|
|
43
|
+
This project does not have any peer dependencies (they are all bundled with the library), so it should work out of the box.
|
|
42
44
|
|
|
43
45
|
## Commands
|
|
44
46
|
The following commands exist in the project:
|
package/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
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
|
+
};
|
|
5
10
|
var __export = (target, all) => {
|
|
6
11
|
for (var name in all)
|
|
7
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -14,8 +19,113 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
19
|
}
|
|
15
20
|
return to;
|
|
16
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
|
+
));
|
|
17
30
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
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
|
+
|
|
19
129
|
// src/index.js
|
|
20
130
|
var src_exports = {};
|
|
21
131
|
__export(src_exports, {
|
|
@@ -23,7 +133,7 @@ __export(src_exports, {
|
|
|
23
133
|
wrapNumber: () => wrapNumber
|
|
24
134
|
});
|
|
25
135
|
module.exports = __toCommonJS(src_exports);
|
|
26
|
-
var import_js_utils =
|
|
136
|
+
var import_js_utils = __toESM(require_js_utils());
|
|
27
137
|
function clamp(value, min, max) {
|
|
28
138
|
if (!(0, import_js_utils.isNullOrUndefined)(min) && value < min) return min;
|
|
29
139
|
if (!(0, import_js_utils.isNullOrUndefined)(max) && value > max) return max;
|
|
@@ -31,5 +141,5 @@ function clamp(value, min, max) {
|
|
|
31
141
|
}
|
|
32
142
|
function wrapNumber(n, min, max) {
|
|
33
143
|
const range = max - min;
|
|
34
|
-
return n >= min ? min + (n - min) % range : max + (n - min) % range;
|
|
144
|
+
return (n - range) % range === 0 ? min : n >= min ? min + (n - min) % range : max + (n - min) % range;
|
|
35
145
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ptolemy2002/js-math-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"index.js"
|
|
7
7
|
],
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "esbuild src/index.js --bundle --format=cjs --outfile=index.js
|
|
9
|
+
"build": "esbuild src/index.js --bundle --format=cjs --outfile=index.js",
|
|
10
10
|
"postinstall": "npx typesync",
|
|
11
11
|
"uninstall": "bash ./scripts/uninstall.sh",
|
|
12
12
|
"reinstall": "bash ./scripts/reinstall.sh",
|
|
@@ -26,10 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"description": "JavaScript math utilities",
|
|
28
28
|
"license": "ISC",
|
|
29
|
-
"peerDependencies": {
|
|
30
|
-
"@ptolemy2002/js-utils": "^1.0.1"
|
|
31
|
-
},
|
|
29
|
+
"peerDependencies": {},
|
|
32
30
|
"devDependencies": {
|
|
31
|
+
"@ptolemy2002/js-utils": "^1.0.1",
|
|
33
32
|
"esbuild": "^0.23.0"
|
|
34
33
|
}
|
|
35
34
|
}
|