@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @vpmedia/simplify
2
2
 
3
- [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.7.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
3
+ [![npm version](https://badge.fury.io/js/@vpmedia%2Fsimplify.svg?v=1.8.0)](https://badge.fury.io/js/@vpmedia%2Fsimplify)
4
4
  [![Node.js CI](https://github.com/vpmedia/simplify/actions/workflows/ci.yml/badge.svg)](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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vpmedia/simplify",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "@vpmedia/simplify",
5
5
  "author": "Andras Csizmadia <andras@vpmedia.hu> (www.vpmedia.hu)",
6
6
  "license": "MIT",
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/deg2rot.js';
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,5 @@
1
+ import { deg2rad } from './deg2rad.js';
2
+
3
+ test('TBD', () => {
4
+ expect(deg2rad(90)).toBe(1.5707963267948966);
5
+ });
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Fixes floating point number (0.20000000000000004 -> 0.2).
3
+ * @param {number} value - Number to fix.
4
+ * @returns {number} The fixed number.
5
+ */
6
+ export function fixFloatPrecision(value) {
7
+ return Number.parseFloat(value.toPrecision(12));
8
+ }
@@ -0,0 +1,5 @@
1
+ import { fixFloatPrecision } from './fixFloatPrecision.js';
2
+
3
+ test('TBD', () => {
4
+ expect(fixFloatPrecision(0.20000000000000004)).toBe(0.2);
5
+ });
@@ -0,0 +1,8 @@
1
+ import { purgeObject } from './purgeObject.js';
2
+
3
+ test('TBD', () => {
4
+ const a = { k: 'v' };
5
+ expect(a.k).toBe('v');
6
+ purgeObject(a);
7
+ expect(a.k).toBe(null);
8
+ });
@@ -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/deg2rot.js";
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,7 @@
1
+ /**
2
+ * Clones an object.
3
+ * @param {object} source - A reference to the source object.
4
+ * @returns {object} The cloned object.
5
+ */
6
+ export function cloneObject(source: object): object;
7
+ //# sourceMappingURL=cloneObject.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,2 @@
1
+ export function deg2rad(deg: number): number;
2
+ //# sourceMappingURL=deg2rad.d.ts.map
@@ -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,7 @@
1
+ /**
2
+ * Fixes floating point number (0.20000000000000004 -> 0.2).
3
+ * @param {number} value - Number to fix.
4
+ * @returns {number} The fixed number.
5
+ */
6
+ export function fixFloatPrecision(value: number): number;
7
+ //# sourceMappingURL=fixFloatPrecision.d.ts.map
@@ -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