yummies 4.7.0 → 4.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.
@@ -1,8 +1,15 @@
1
- export interface CounterFn<TProcessedValue = number> {
2
- (): TProcessedValue;
1
+ export interface Counter<TValue = number> {
2
+ (): TValue;
3
3
  counter: number;
4
- value: TProcessedValue;
4
+ value: TValue;
5
+ increment(): TValue;
6
+ decrement(): TValue;
5
7
  reset(): void;
6
8
  }
7
- export declare const createCounter: <TProcessedValue = number>(processValue?: (value: number) => TProcessedValue, initial?: number) => CounterFn<TProcessedValue>;
9
+ /**
10
+ * @deprecated use {`Counter`}. Will be removed in next major release
11
+ */
12
+ export interface CounterFn<TValue = number> extends Counter<TValue> {
13
+ }
14
+ export declare const createCounter: <TValue = number>(processValue?: (value: number) => TValue, initial?: number) => Counter<TValue>;
8
15
  //# sourceMappingURL=counter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../../src/complex/counter.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS,CAAC,eAAe,GAAG,MAAM;IACjD,IAAI,eAAe,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,eAAe,CAAC;IACvB,KAAK,IAAI,IAAI,CAAC;CACf;AAED,eAAO,MAAM,aAAa,GAAI,eAAe,GAAG,MAAM,EACpD,eAAe,CAAC,KAAK,EAAE,MAAM,KAAK,eAAe,EACjD,UAAS,MAAU,KAClB,SAAS,CAAC,eAAe,CAgB3B,CAAC"}
1
+ {"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../../src/complex/counter.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO,CAAC,MAAM,GAAG,MAAM;IACtC,IAAI,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,IAAI,MAAM,CAAC;IACpB,SAAS,IAAI,MAAM,CAAC;IACpB,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,MAAM,GAAG,MAAM,CAAE,SAAQ,OAAO,CAAC,MAAM,CAAC;CAAG;AAEtE,eAAO,MAAM,aAAa,GAAI,MAAM,GAAG,MAAM,EAC3C,eAAe,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,EACxC,UAAS,MAAU,KAClB,OAAO,CAAC,MAAM,CAsBhB,CAAC"}
@@ -1,14 +1,18 @@
1
+ /* eslint-disable @typescript-eslint/no-use-before-define */
1
2
  export const createCounter = (processValue, initial = 0) => {
2
- const incrementFn = (() => {
3
- const nextCounter = incrementFn.counter++;
4
- incrementFn.value =
5
- processValue?.(nextCounter) ?? nextCounter;
6
- return incrementFn.value;
7
- });
8
- incrementFn.reset = () => {
9
- incrementFn.counter = initial;
10
- incrementFn.value = processValue?.(initial) ?? initial;
3
+ const update = (counter) => {
4
+ fn.value = processValue?.(counter) ?? counter;
5
+ return fn.value;
11
6
  };
12
- incrementFn.reset();
13
- return incrementFn;
7
+ const increment = () => update(++fn.counter);
8
+ const decrement = () => update(--fn.counter);
9
+ const fn = increment;
10
+ fn.increment = increment;
11
+ fn.decrement = decrement;
12
+ fn.reset = () => {
13
+ fn.counter = initial;
14
+ fn.value = processValue?.(initial) ?? initial;
15
+ };
16
+ fn.reset();
17
+ return fn;
14
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yummies",
3
- "version": "4.7.0",
3
+ "version": "4.8.0",
4
4
  "keywords": [],
5
5
  "author": "js2me",
6
6
  "license": "MIT",
@@ -51,6 +51,11 @@
51
51
  "default": "./common.js",
52
52
  "types": "./common.d.ts"
53
53
  },
54
+ "./complex/counter.test": {
55
+ "import": "./complex/counter.test.js",
56
+ "default": "./complex/counter.test.js",
57
+ "types": "./complex/counter.test.d.ts"
58
+ },
54
59
  "./complex/counter": {
55
60
  "import": "./complex/counter.js",
56
61
  "default": "./complex/counter.js",