smath 1.12.0 → 1.12.1
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/dist/bin.js +6 -1
- package/dist/index.js +16 -0
- package/package.json +1 -1
- package/types/index.d.ts +12 -0
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var _a, _b, _c, _d;
|
|
3
|
+
var _a, _b, _c, _d, _e;
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
var _1 = require(".");
|
|
6
6
|
var func = ((_a = process.argv[2]) !== null && _a !== void 0 ? _a : '').toLowerCase(), nums = process.argv.slice(3).map(function (arg, i) {
|
|
@@ -43,6 +43,7 @@ if (func.includes('help')) {
|
|
|
43
43
|
console.log(' rdist <n> [mean] [stdev] : Generate `n` normally-distributed random floats');
|
|
44
44
|
console.log(' rat <n> [eps] : Decompose `n` into a ratio');
|
|
45
45
|
console.log(' mixed <n> [eps] : Decompose `n` into a mixed number');
|
|
46
|
+
console.log(' toHex <n> [length] : Convert decimal `n` into hexadecimal');
|
|
46
47
|
process.exit(1);
|
|
47
48
|
}
|
|
48
49
|
switch (func) {
|
|
@@ -146,6 +147,10 @@ switch (func) {
|
|
|
146
147
|
console.log(_1.SMath.mixed(nums[0], (_d = nums[1]) !== null && _d !== void 0 ? _d : 1e-6));
|
|
147
148
|
break;
|
|
148
149
|
}
|
|
150
|
+
case ('tohex'): {
|
|
151
|
+
console.log(_1.SMath.toHex(nums[0], (_e = nums[1]) !== null && _e !== void 0 ? _e : 0));
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
149
154
|
case (''): {
|
|
150
155
|
console.error('Missing argument. Use with "help" for a list of commands.');
|
|
151
156
|
process.exit(1);
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,7 @@ exports.SMath = void 0;
|
|
|
17
17
|
* Small math function library
|
|
18
18
|
*
|
|
19
19
|
* 
|
|
20
|
+
* 
|
|
20
21
|
*/
|
|
21
22
|
/**
|
|
22
23
|
* Contains a small math function library including
|
|
@@ -591,4 +592,19 @@ var SMath;
|
|
|
591
592
|
return __assign({ whole: n | 0 }, rat(n < -1 ? (n | 0) - n : n - (n | 0), epsilon));
|
|
592
593
|
}
|
|
593
594
|
SMath.mixed = mixed;
|
|
595
|
+
/**
|
|
596
|
+
* Convert any number to its hexadecimal equivalent.
|
|
597
|
+
* @param n A decimal number to convert
|
|
598
|
+
* @param length The minimum number of digits to show
|
|
599
|
+
* @returns The number `n` converted to hexadecimal
|
|
600
|
+
* @example
|
|
601
|
+
* ```js
|
|
602
|
+
* const hex = SMath.toHex(10, 2); // '0A'
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
function toHex(n, length) {
|
|
606
|
+
if (length === void 0) { length = 0; }
|
|
607
|
+
return (n < 0 ? '-' : '') + (n < 0 ? -n : n).toString(16).padStart(length, '0').toUpperCase();
|
|
608
|
+
}
|
|
609
|
+
SMath.toHex = toHex;
|
|
594
610
|
})(SMath || (exports.SMath = SMath = {}));
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Small math function library
|
|
4
4
|
*
|
|
5
5
|
* 
|
|
6
|
+
* 
|
|
6
7
|
*/
|
|
7
8
|
/**
|
|
8
9
|
* Contains a small math function library including
|
|
@@ -356,4 +357,15 @@ export declare namespace SMath {
|
|
|
356
357
|
num: number;
|
|
357
358
|
den: number;
|
|
358
359
|
};
|
|
360
|
+
/**
|
|
361
|
+
* Convert any number to its hexadecimal equivalent.
|
|
362
|
+
* @param n A decimal number to convert
|
|
363
|
+
* @param length The minimum number of digits to show
|
|
364
|
+
* @returns The number `n` converted to hexadecimal
|
|
365
|
+
* @example
|
|
366
|
+
* ```js
|
|
367
|
+
* const hex = SMath.toHex(10, 2); // '0A'
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
function toHex(n: number, length?: number): string;
|
|
359
371
|
}
|