@neovici/cosmoz-utils 5.10.2 → 5.12.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.
@@ -0,0 +1,3 @@
1
+ export function memoize(fn: any): (arg: any) => any;
2
+ export function memooize(fn: any): (arg1: any, arg2: any) => any;
3
+ export function memoooize(fn: any): (arg1: any, arg2: any, arg3: any) => any;
@@ -0,0 +1,37 @@
1
+ export const memoize = fn => {
2
+ let lastArg, lastResult;
3
+ return function (arg) {
4
+ if (lastArg === arg) {
5
+ return lastResult;
6
+ }
7
+ const result = fn(arg);
8
+ lastResult = result;
9
+ lastArg = arg;
10
+ return result;
11
+ };
12
+ }, memooize = fn => {
13
+ let lastArg1, lastArg2, lastResult;
14
+ return function (arg1, arg2) {
15
+ if (lastArg1 === arg1 && lastArg2 === arg2) {
16
+ return lastResult;
17
+ }
18
+ const result = fn(arg1, arg2);
19
+ lastResult = result;
20
+ lastArg1 = arg1;
21
+ lastArg2 = arg2;
22
+ return result;
23
+ };
24
+ }, memoooize = fn => {
25
+ let lastArg1, lastArg2, lastArg3, lastResult;
26
+ return function (arg1, arg2, arg3) {
27
+ if (lastArg1 === arg1 && lastArg2 === arg2 && lastArg3 === arg3) {
28
+ return lastResult;
29
+ }
30
+ const result = fn(arg1, arg2, arg3);
31
+ lastResult = result;
32
+ lastArg1 = arg1;
33
+ lastArg2 = arg2;
34
+ lastArg3 = arg3;
35
+ return result;
36
+ };
37
+ };
@@ -0,0 +1,2 @@
1
+ export declare const parse: (value?: string | number) => number | undefined;
2
+ export declare const round: (num: number, precision?: number) => number | undefined;
package/dist/number.js ADDED
@@ -0,0 +1,14 @@
1
+ export const parse = (value) => {
2
+ if (!value || value === Infinity)
3
+ return;
4
+ if (typeof value === 'number')
5
+ return value;
6
+ const num = parseFloat(value
7
+ .replace(/[\s]/gu, '')
8
+ .replace(/[,.]/gu, '.')
9
+ .replace(/[.](?=.*[.])/gu, ''));
10
+ if (isNaN(num))
11
+ return;
12
+ return num;
13
+ };
14
+ export const round = (num, precision = 2) => parse(num.toFixed(precision));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "5.10.2",
3
+ "version": "5.12.0",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",
@@ -55,6 +55,7 @@
55
55
  "./array": "./dist/array.js",
56
56
  "./date": "./dist/date.js",
57
57
  "./function": "./dist/function.js",
58
+ "./number": "./dist/number.js",
58
59
  "./location": "./dist/location.js",
59
60
  "./money": "./dist/money.js",
60
61
  "./promise": "./dist/promise.js",