@vpmedia/simplify 1.7.0 → 1.8.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 +1 -1
- package/eslint.config.js +1 -0
- package/package.json +1 -1
- package/src/index.js +3 -1
- package/src/util/deg2rad.test.js +5 -0
- package/src/util/fixFloatPrecision.js +8 -0
- package/src/util/fixFloatPrecision.test.js +5 -0
- package/src/util/purgeObject.test.js +8 -0
- package/src/util/safeFloat.js +31 -0
- package/src/util/safeFloat.test.js +13 -0
- package/types/index.d.ts +3 -1
- package/types/util/cloneObject.d.ts +7 -0
- package/types/util/cloneObject.d.ts.map +1 -0
- package/types/util/deg2rad.d.ts +2 -0
- package/types/util/deg2rad.d.ts.map +1 -0
- package/types/util/fixFloatPrecision.d.ts +7 -0
- package/types/util/fixFloatPrecision.d.ts.map +1 -0
- package/types/util/safeFloat.d.ts +22 -0
- package/types/util/safeFloat.d.ts.map +1 -0
- /package/src/util/{deg2rot.js → deg2rad.js} +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @vpmedia/simplify
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/js/@vpmedia%2Fsimplify)
|
|
4
4
|
[](https://github.com/vpmedia/simplify/actions/workflows/ci.yml)
|
|
5
5
|
|
|
6
6
|
@vpmedia/simplify TBD
|
package/eslint.config.js
CHANGED
|
@@ -58,6 +58,7 @@ export default [
|
|
|
58
58
|
'unicorn/no-null': 'off',
|
|
59
59
|
'unicorn/prevent-abbreviations': 'off',
|
|
60
60
|
'unicorn/prefer-global-this': 'off',
|
|
61
|
+
'unicorn/numeric-separators-style': 'off',
|
|
61
62
|
'no-unused-vars': 'off',
|
|
62
63
|
'prefer-arrow-callback': 'error',
|
|
63
64
|
'prefer-template': 'error',
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -3,13 +3,15 @@ export * from './const/http_status.js';
|
|
|
3
3
|
export { Logger } from './logging/Logger.js';
|
|
4
4
|
export { addLeadingZero } from './util/addLeadingZero.js';
|
|
5
5
|
export { capitalize } from './util/capitalize.js';
|
|
6
|
-
export { deg2rad } from './util/
|
|
6
|
+
export { deg2rad } from './util/deg2rad.js';
|
|
7
7
|
export { delayPromise } from './util/delayPromise.js';
|
|
8
8
|
export { FetchError, HTTP_0_ANY, fetchRetry } from './util/fetchRetry.js';
|
|
9
|
+
export { fixFloatPrecision } from './util/fixFloatPrecision.js';
|
|
9
10
|
export { getObjValueByPath } from './util/getObjValueByPath.js';
|
|
10
11
|
export { getRandomInt } from './util/getRandomInt.js';
|
|
11
12
|
export { getURLParam } from './util/getURLParam.js';
|
|
12
13
|
export { purgeObject } from './util/purgeObject.js';
|
|
14
|
+
export { addFloat, fixFloat, subFloat } from './util/safeFloat.js';
|
|
13
15
|
export { sanitizeURLParam } from './util/sanitizeURLParam.js';
|
|
14
16
|
export { saveAsFile } from './util/saveAsFile.js';
|
|
15
17
|
export { setObjValueByPath } from './util/setObjValueByPath.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience method for floating point precision handling.
|
|
3
|
+
* @param {number} value - The number to process.
|
|
4
|
+
* @param {number} p - The precision. Defaults to 2.
|
|
5
|
+
* @returns {number} The processed value.
|
|
6
|
+
*/
|
|
7
|
+
export function fixFloat(value, p = 2) {
|
|
8
|
+
return Number.parseFloat(value.toFixed(p));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Adds two value with floating point precision.
|
|
13
|
+
* @param {number} a - The number a.
|
|
14
|
+
* @param {number} b - The number b.
|
|
15
|
+
* @returns {number} The processed value.
|
|
16
|
+
*/
|
|
17
|
+
export function addFloat(a, b) {
|
|
18
|
+
const p = 100;
|
|
19
|
+
return fixFloat((a * p + b * p) / p);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Substracts two value with floating point precision.
|
|
24
|
+
* @param {number} a - The number a.
|
|
25
|
+
* @param {number} b - The number b.
|
|
26
|
+
* @returns {number} The processed value.
|
|
27
|
+
*/
|
|
28
|
+
export function subFloat(a, b) {
|
|
29
|
+
const p = 100;
|
|
30
|
+
return fixFloat((a * p - b * p) / p);
|
|
31
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { addFloat, fixFloat, subFloat } from './safeFloat.js';
|
|
2
|
+
|
|
3
|
+
test('fixFloat()', () => {
|
|
4
|
+
expect(fixFloat(0.20000000000000004)).toBe(0.2);
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
test('addFloat()', () => {
|
|
8
|
+
expect(addFloat(0.20000000000000004, 0.1000001)).toBe(0.3);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('subFloat()', () => {
|
|
12
|
+
expect(subFloat(0.20000000000000004, 0.1000001)).toBe(0.1);
|
|
13
|
+
});
|
package/types/index.d.ts
CHANGED
|
@@ -2,8 +2,9 @@ export * from "./const/http_status.js";
|
|
|
2
2
|
export { Logger } from "./logging/Logger.js";
|
|
3
3
|
export { addLeadingZero } from "./util/addLeadingZero.js";
|
|
4
4
|
export { capitalize } from "./util/capitalize.js";
|
|
5
|
-
export { deg2rad } from "./util/
|
|
5
|
+
export { deg2rad } from "./util/deg2rad.js";
|
|
6
6
|
export { delayPromise } from "./util/delayPromise.js";
|
|
7
|
+
export { fixFloatPrecision } from "./util/fixFloatPrecision.js";
|
|
7
8
|
export { getObjValueByPath } from "./util/getObjValueByPath.js";
|
|
8
9
|
export { getRandomInt } from "./util/getRandomInt.js";
|
|
9
10
|
export { getURLParam } from "./util/getURLParam.js";
|
|
@@ -13,4 +14,5 @@ export { saveAsFile } from "./util/saveAsFile.js";
|
|
|
13
14
|
export { setObjValueByPath } from "./util/setObjValueByPath.js";
|
|
14
15
|
export { underscoreToCamelCase } from "./util/underscoreToCamelCase.js";
|
|
15
16
|
export { FetchError, HTTP_0_ANY, fetchRetry } from "./util/fetchRetry.js";
|
|
17
|
+
export { addFloat, fixFloat, subFloat } from "./util/safeFloat.js";
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloneObject.d.ts","sourceRoot":"","sources":["../../src/util/cloneObject.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oCAHW,MAAM,GACJ,MAAM,CAKlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deg2rad.d.ts","sourceRoot":"","sources":["../../src/util/deg2rad.js"],"names":[],"mappings":"AAKO,6BAHI,MAAM,GACJ,MAAM,CAIlB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixFloatPrecision.d.ts","sourceRoot":"","sources":["../../src/util/fixFloatPrecision.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,yCAHW,MAAM,GACJ,MAAM,CAIlB"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience method for floating point precision handling.
|
|
3
|
+
* @param {number} value - The number to process.
|
|
4
|
+
* @param {number} p - The precision. Defaults to 2.
|
|
5
|
+
* @returns {number} The processed value.
|
|
6
|
+
*/
|
|
7
|
+
export function fixFloat(value: number, p?: number): number;
|
|
8
|
+
/**
|
|
9
|
+
* Adds two value with floating point precision.
|
|
10
|
+
* @param {number} a - The number a.
|
|
11
|
+
* @param {number} b - The number b.
|
|
12
|
+
* @returns {number} The processed value.
|
|
13
|
+
*/
|
|
14
|
+
export function addFloat(a: number, b: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Substracts two value with floating point precision.
|
|
17
|
+
* @param {number} a - The number a.
|
|
18
|
+
* @param {number} b - The number b.
|
|
19
|
+
* @returns {number} The processed value.
|
|
20
|
+
*/
|
|
21
|
+
export function subFloat(a: number, b: number): number;
|
|
22
|
+
//# sourceMappingURL=safeFloat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeFloat.d.ts","sourceRoot":"","sources":["../../src/util/safeFloat.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,gCAJW,MAAM,MACN,MAAM,GACJ,MAAM,CAIlB;AAED;;;;;GAKG;AACH,4BAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAKlB;AAED;;;;;GAKG;AACH,4BAJW,MAAM,KACN,MAAM,GACJ,MAAM,CAKlB"}
|
|
File without changes
|