@vita-mojo/basket-quantifier 0.0.2-VMOS-12775-eae9307-638-rc.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 ADDED
@@ -0,0 +1,11 @@
1
+ # basket-quantifier
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build basket-quantifier` to build the library.
8
+
9
+ ## Running unit tests
10
+
11
+ Run `nx test basket-quantifier` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "name": "@vita-mojo/basket-quantifier",
3
+ "version": "0.0.2-VMOS-12775-eae9307-638-rc.0",
4
+ "type": "commonjs",
5
+ "peerDependencies": {
6
+ "@vita-mojo/types": "1.0.23-VMOS-12775-eae9307-638-rc.0",
7
+ "tslib": "2.4.1"
8
+ },
9
+ "main": "./src/index.js",
10
+ "types": "./src/index.d.ts"
11
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/basket-quantifier';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/basket-quantifier"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/basket-quantifier/src/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC"}
@@ -0,0 +1,4 @@
1
+ export declare const basketQuantifier: {
2
+ quantify: (bundles: import("../../../../dist/packages/types/src/order/bundle").Bundle[]) => void;
3
+ dequantify: (bundles: import("../../../../dist/packages/types/src/order/bundle").Bundle[]) => import("../../../../dist/packages/types/src/order/bundle").Bundle[];
4
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.basketQuantifier = void 0;
4
+ const quantify_1 = require("./quantify");
5
+ const dequantify_1 = require("./dequantify");
6
+ exports.basketQuantifier = {
7
+ quantify: quantify_1.quantify,
8
+ dequantify: dequantify_1.dequantify,
9
+ };
10
+ //# sourceMappingURL=basket-quantifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basket-quantifier.js","sourceRoot":"","sources":["../../../../../packages/basket-quantifier/src/lib/basket-quantifier.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AACtC,6CAA0C;AAE7B,QAAA,gBAAgB,GAAG;IAC9B,QAAQ,EAAR,mBAAQ;IACR,UAAU,EAAV,uBAAU;CACX,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { Order } from '@vita-mojo/types';
2
+ export declare const dequantify: (bundles: Order.Bundle.Bundle[]) => Order.Bundle.Bundle[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dequantify = void 0;
4
+ const dequantify = (bundles) => {
5
+ return bundles.reduce((acc, bundle) => {
6
+ if (!bundle.basketEntries) {
7
+ acc.push(bundle);
8
+ return acc;
9
+ }
10
+ // basketEntries keys are ulid's, sort them to preserve correct bundles order
11
+ Object.keys(bundle.basketEntries).sort().forEach(entryId => {
12
+ const entry = bundle.basketEntries[entryId];
13
+ const basketId = `${bundle.basketUUID}#${entryId}`;
14
+ const dequantifiedBundle = Object.assign(Object.assign(Object.assign({}, bundle), entry), { basketId, quantity: 1, basketEntries: undefined });
15
+ acc.push(dequantifiedBundle);
16
+ });
17
+ return acc;
18
+ }, []);
19
+ };
20
+ exports.dequantify = dequantify;
21
+ //# sourceMappingURL=dequantify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dequantify.js","sourceRoot":"","sources":["../../../../../packages/basket-quantifier/src/lib/dequantify.ts"],"names":[],"mappings":";;;AAEO,MAAM,UAAU,GAAG,CAAC,OAA8B,EAAE,EAAE;IAC3D,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE;QACpC,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;YACzB,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjB,OAAO,GAAG,CAAC;SACZ;QACD,6EAA6E;QAC7E,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YACzD,MAAM,KAAK,GAAG,MAAM,CAAC,aAAc,CAAC,OAAO,CAAC,CAAC;YAC7C,MAAM,QAAQ,GAAG,GAAG,MAAM,CAAC,UAAU,IAAI,OAAO,EAAE,CAAC;YACnD,MAAM,kBAAkB,iDACnB,MAAM,GACN,KAAK,KACR,QAAQ,EACR,QAAQ,EAAE,CAAC,EACX,aAAa,EAAE,SAAS,GACzB,CAAC;YACF,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;QACH,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAA2B,CAAC,CAAC;AAClC,CAAC,CAAC;AArBW,QAAA,UAAU,cAqBrB"}
@@ -0,0 +1,2 @@
1
+ import { Order } from '@vita-mojo/types';
2
+ export declare const quantify: (bundles: Order.Bundle.Bundle[]) => void;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quantify = void 0;
4
+ const quantify = (bundles) => { };
5
+ exports.quantify = quantify;
6
+ //# sourceMappingURL=quantify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quantify.js","sourceRoot":"","sources":["../../../../../packages/basket-quantifier/src/lib/quantify.ts"],"names":[],"mappings":";;;AAEO,MAAM,QAAQ,GAAG,CAAC,OAA8B,EAAE,EAAE,GAAE,CAAC,CAAC;AAAlD,QAAA,QAAQ,YAA0C"}