@ezez/utils 2.0.0 → 2.1.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.
Files changed (103) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/README.md +1 -0
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +1 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/round.d.ts +3 -0
  8. package/dist/round.d.ts.map +1 -0
  9. package/dist/round.js +9 -0
  10. package/dist/round.js.map +1 -0
  11. package/docs/assets/search.js +1 -1
  12. package/docs/functions/cap.html +6 -5
  13. package/docs/functions/capitalize.html +6 -5
  14. package/docs/functions/coalesce.html +6 -5
  15. package/docs/functions/compareArrays.html +6 -5
  16. package/docs/functions/compareProps.html +6 -5
  17. package/docs/functions/deserialize.html +6 -5
  18. package/docs/functions/ensureArray.html +6 -5
  19. package/docs/functions/ensureDate.html +6 -5
  20. package/docs/functions/ensureError.html +6 -5
  21. package/docs/functions/ensurePrefix.html +6 -5
  22. package/docs/functions/ensureSuffix.html +6 -5
  23. package/docs/functions/ensureTimestamp.html +6 -5
  24. package/docs/functions/escapeRegExp.html +6 -5
  25. package/docs/functions/formatDate.html +6 -5
  26. package/docs/functions/get.html +6 -5
  27. package/docs/functions/getMultiple.html +6 -5
  28. package/docs/functions/insertSeparator.html +6 -5
  29. package/docs/functions/isEmpty.html +6 -5
  30. package/docs/functions/isNumericString.html +6 -5
  31. package/docs/functions/isPlainObject.html +6 -5
  32. package/docs/functions/last.html +6 -5
  33. package/docs/functions/later-1.html +6 -5
  34. package/docs/functions/mapAsync.html +6 -5
  35. package/docs/functions/mapValues.html +6 -5
  36. package/docs/functions/match.html +6 -5
  37. package/docs/functions/merge.html +14 -13
  38. package/docs/functions/mostFrequent.html +6 -5
  39. package/docs/functions/noop.html +6 -5
  40. package/docs/functions/occurrences.html +6 -5
  41. package/docs/functions/omit.html +6 -5
  42. package/docs/functions/pick.html +6 -5
  43. package/docs/functions/pull.html +6 -5
  44. package/docs/functions/remove.html +6 -5
  45. package/docs/functions/removeCommonProperties.html +6 -5
  46. package/docs/functions/replace.html +6 -5
  47. package/docs/functions/replaceDeep.html +6 -5
  48. package/docs/functions/rethrow.html +6 -5
  49. package/docs/functions/round.html +144 -0
  50. package/docs/functions/safe.html +7 -6
  51. package/docs/functions/scale.html +6 -5
  52. package/docs/functions/seq.html +6 -5
  53. package/docs/functions/seqEarlyBreak.html +6 -5
  54. package/docs/functions/serialize.html +6 -5
  55. package/docs/functions/set.html +6 -5
  56. package/docs/functions/setImmutable.html +6 -5
  57. package/docs/functions/sortBy.html +6 -5
  58. package/docs/functions/sortProps.html +6 -5
  59. package/docs/functions/stripPrefix.html +6 -5
  60. package/docs/functions/stripSuffix.html +6 -5
  61. package/docs/functions/throttle.html +6 -5
  62. package/docs/functions/truthy.html +6 -5
  63. package/docs/functions/unique.html +6 -5
  64. package/docs/functions/wait.html +6 -5
  65. package/docs/functions/waitFor.html +6 -5
  66. package/docs/functions/waitSync.html +6 -5
  67. package/docs/index.html +6 -4
  68. package/docs/interfaces/ComparePropsOptions.html +6 -6
  69. package/docs/interfaces/GetMultipleSource.html +6 -5
  70. package/docs/interfaces/GetSource.html +6 -5
  71. package/docs/interfaces/IsNumericStringOptions.html +9 -9
  72. package/docs/interfaces/OccurencesOptions.html +6 -6
  73. package/docs/interfaces/SetImmutableSource.html +6 -5
  74. package/docs/interfaces/SetSource.html +6 -5
  75. package/docs/interfaces/ThrottleOptions.html +7 -7
  76. package/docs/interfaces/ThrottledFunctionExtras.html +7 -7
  77. package/docs/modules.html +6 -4
  78. package/docs/pages/CHANGELOG.html +49 -37
  79. package/docs/pages/Introduction.html +5 -4
  80. package/docs/types/CustomDeserializers.html +6 -5
  81. package/docs/types/CustomSerializers.html +6 -5
  82. package/docs/types/Later.html +6 -5
  83. package/docs/types/MapValuesFn.html +6 -5
  84. package/docs/types/MatchCallback.html +6 -5
  85. package/docs/types/SeqEarlyBreaker.html +6 -5
  86. package/docs/types/SeqFn.html +6 -5
  87. package/docs/types/SeqFunctions.html +6 -5
  88. package/docs/types/SetImmutablePath.html +6 -5
  89. package/docs/types/ThrottledFunction.html +6 -5
  90. package/docs/variables/mapValuesUNSET.html +6 -5
  91. package/docs/variables/mergeUNSET.html +6 -5
  92. package/esm/index.d.ts +1 -0
  93. package/esm/index.d.ts.map +1 -1
  94. package/esm/index.js +1 -0
  95. package/esm/index.js.map +1 -1
  96. package/esm/round.d.ts +3 -0
  97. package/esm/round.d.ts.map +1 -0
  98. package/esm/round.js +6 -0
  99. package/esm/round.js.map +1 -0
  100. package/package.json +1 -1
  101. package/src/index.ts +1 -0
  102. package/src/round.spec.ts +27 -0
  103. package/src/round.ts +21 -0
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AA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,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/esm/index.js CHANGED
@@ -35,6 +35,7 @@ export * from "./removeCommonProperties.js";
35
35
  export * from "./replace.js";
36
36
  export * from "./replaceDeep.js";
37
37
  export * from "./rethrow.js";
38
+ export * from "./round.js";
38
39
  export * from "./safe.js";
39
40
  export * from "./scale.js";
40
41
  export * from "./seq.js";
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,mBAAmB,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,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
package/esm/round.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ declare const round: (value: number, precision?: number) => number;
2
+ export { round, };
3
+ //# sourceMappingURL=round.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round.d.ts","sourceRoot":"","sources":["../src/round.ts"],"names":[],"mappings":"AAYA,QAAA,MAAM,KAAK,UAAW,MAAM,cAAc,MAAM,WAI/C,CAAC;AAEF,OAAO,EACH,KAAK,GACR,CAAC"}
package/esm/round.js ADDED
@@ -0,0 +1,6 @@
1
+ const round = (value, precision) => {
2
+ const multiplier = Math.pow(10, precision || 0);
3
+ return Math.round(value * multiplier) / multiplier;
4
+ };
5
+ export { round, };
6
+ //# sourceMappingURL=round.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"round.js","sourceRoot":"","sources":["../src/round.ts"],"names":[],"mappings":"AAYA,MAAM,KAAK,GAAG,CAAC,KAAa,EAAE,SAAkB,EAAE,EAAE;IAEhD,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,SAAS,IAAI,CAAC,CAAC,CAAC;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,UAAU,CAAC;AACvD,CAAC,CAAC;AAEF,OAAO,EACH,KAAK,GACR,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ezez/utils",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "repository": "https://github.com/dzek69/bottom-line.git",
5
5
  "author": "Jacek Nowacki @dzek69 <git-public@dzek.eu>",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -36,6 +36,7 @@ export * from "./removeCommonProperties.js";
36
36
  export * from "./replace.js";
37
37
  export * from "./replaceDeep.js";
38
38
  export * from "./rethrow.js";
39
+ export * from "./round.js";
39
40
  export * from "./safe.js";
40
41
  export * from "./scale.js";
41
42
  export * from "./seq.js";
@@ -0,0 +1,27 @@
1
+ import { round } from "./round";
2
+
3
+ describe("round", () => {
4
+ it("rounds the values without precision", async () => {
5
+ round(1.23).must.equal(1);
6
+ round(1.55).must.equal(2);
7
+ round(1.5).must.equal(2);
8
+ round(1.49999).must.equal(1);
9
+ });
10
+
11
+ it("rounds the values with precision", async () => {
12
+ round(1.23, 1).must.equal(1.2);
13
+ round(1.55, 1).must.equal(1.6);
14
+ round(1.5, 1).must.equal(1.5);
15
+ round(1.49999, 1).must.equal(1.5);
16
+
17
+ round(1.5, 2).must.equal(1.5);
18
+ });
19
+
20
+ it("rounds the tricky values", async () => {
21
+ round(0.1 + 0.2, 1).must.equal(0.3);
22
+ });
23
+
24
+ it("rounds with higher precision", async () => {
25
+ round(1.2, 6).must.equal(1.2);
26
+ });
27
+ });
package/src/round.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Rounds a number to a given precision
3
+ *
4
+ * @example
5
+ * round(1.23) // 1
6
+ * round(1.55) // 2
7
+ * round(1.333, 2) // 1.33
8
+ * round(1.2345, 3) // 1.234
9
+ *
10
+ * @param value - value to round
11
+ * @param precision - precision to round to
12
+ */
13
+ const round = (value: number, precision?: number) => {
14
+ // eslint-disable-next-line @typescript-eslint/no-magic-numbers
15
+ const multiplier = Math.pow(10, precision || 0);
16
+ return Math.round(value * multiplier) / multiplier;
17
+ };
18
+
19
+ export {
20
+ round,
21
+ };