@softwear/latestcollectioncore 1.0.8 → 1.0.9

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 @@
1
+ export default function (object: any): any;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function default_1(object) {
4
+ if (!object)
5
+ return object;
6
+ return JSON.parse(JSON.stringify(object));
7
+ }
8
+ exports.default = default_1;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as applyPropertyMapping } from "./applyPropertyMapping";
2
2
  export { default as ean13 } from "./ean13";
3
+ export { default as deepCopy } from "./deepCopy";
3
4
  export { default as hashBrand } from "./hashBrand";
4
5
  export * from "./types";
5
6
  export * from "./consts";
package/dist/index.js CHANGED
@@ -17,11 +17,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.hashBrand = exports.ean13 = exports.applyPropertyMapping = void 0;
20
+ exports.hashBrand = exports.deepCopy = exports.ean13 = exports.applyPropertyMapping = void 0;
21
21
  var applyPropertyMapping_1 = require("./applyPropertyMapping");
22
22
  Object.defineProperty(exports, "applyPropertyMapping", { enumerable: true, get: function () { return __importDefault(applyPropertyMapping_1).default; } });
23
23
  var ean13_1 = require("./ean13");
24
24
  Object.defineProperty(exports, "ean13", { enumerable: true, get: function () { return __importDefault(ean13_1).default; } });
25
+ var deepCopy_1 = require("./deepCopy");
26
+ Object.defineProperty(exports, "deepCopy", { enumerable: true, get: function () { return __importDefault(deepCopy_1).default; } });
25
27
  var hashBrand_1 = require("./hashBrand");
26
28
  Object.defineProperty(exports, "hashBrand", { enumerable: true, get: function () { return __importDefault(hashBrand_1).default; } });
27
29
  __exportStar(require("./types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,4 @@
1
+ export default function (object: any): any {
2
+ if (!object) return object
3
+ return JSON.parse(JSON.stringify(object))
4
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as applyPropertyMapping } from "./applyPropertyMapping"
2
2
  export { default as ean13 } from "./ean13"
3
+ export { default as deepCopy } from "./deepCopy"
3
4
  export { default as hashBrand } from "./hashBrand"
4
5
  export * from "./types"
5
6
  export * from "./consts"
@@ -0,0 +1,206 @@
1
+ const { deepCopy, applyPropertyMapping } = require("../dist/index")
2
+ const { expect } = require("chai")
3
+
4
+ const skus = [
5
+ {
6
+ id: "1234567890128",
7
+ brand: "levis",
8
+ collection: "22summer",
9
+ collectionSupplier: "SUMMER 2022",
10
+ colorCodeSupplier: "100",
11
+ colorFamily: "White",
12
+ size: "S",
13
+ },
14
+ {
15
+ id: "1234567890129",
16
+ brand: "levis",
17
+ collection: "22summer",
18
+ collectionSupplier: "SUMMER 2022",
19
+ colorCodeSupplier: "100",
20
+ colorFamily: "White",
21
+ size: "M",
22
+ },
23
+ {
24
+ id: "1234567890130",
25
+ brand: "levis",
26
+ collection: "22summer",
27
+ collectionSupplier: "SUMMER 2022",
28
+ colorCodeSupplier: "100",
29
+ colorFamily: "White",
30
+ size: "L",
31
+ },
32
+ {
33
+ id: "1234567890131",
34
+ brand: "levis",
35
+ collection: "22summer",
36
+ collectionSupplier: "SUMMER 2022",
37
+ colorCodeSupplier: "200",
38
+ colorFamily: "Blue",
39
+ size: "S",
40
+ },
41
+ {
42
+ id: "1234567890132",
43
+ brand: "levis",
44
+ collection: "22summer",
45
+ collectionSupplier: "SUMMER 2022",
46
+ colorCodeSupplier: "200",
47
+ colorFamily: "Blue",
48
+ size: "M",
49
+ },
50
+ {
51
+ id: "1234567890133",
52
+ brand: "levis",
53
+ collection: "22summer",
54
+ collectionSupplier: "SUMMER 2022",
55
+ colorCodeSupplier: "200",
56
+ colorFamily: "Blue",
57
+ size: "L",
58
+ },
59
+ {
60
+ id: "1234567890134",
61
+ brand: "gstar",
62
+ collection: "22summer",
63
+ collectionSupplier: "SUMMER 2022",
64
+ colorCodeSupplier: "200",
65
+ colorFamily: "Blue",
66
+ size: "S",
67
+ },
68
+ {
69
+ id: "1234567890135",
70
+ brand: "gstar",
71
+ collection: "22summer",
72
+ collectionSupplier: "SUMMER 2022",
73
+ colorCodeSupplier: "200",
74
+ colorFamily: "Blue",
75
+ size: "M",
76
+ },
77
+ {
78
+ id: "1234567890136",
79
+ brand: "gstar",
80
+ collection: "22summer",
81
+ collectionSupplier: "SUMMER 2022",
82
+ colorCodeSupplier: "200",
83
+ colorFamily: "Blue",
84
+ size: "L",
85
+ },
86
+ ]
87
+
88
+ const colorMapping = [
89
+ {
90
+ id: "levis",
91
+ propertyMapping: [
92
+ { category: "ColorCode", from: "200", to: "Blauw" },
93
+ { category: "ColorCode", from: "100", to: "Wit" },
94
+ ],
95
+ },
96
+ ]
97
+
98
+ const partialMapping = [
99
+ {
100
+ id: "levis",
101
+ propertyMapping: [
102
+ { category: "ColorCode", from: "200", to: "Blauw" },
103
+ { category: "ColorCode", from: "100", to: "Wit" },
104
+ { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
105
+ ],
106
+ },
107
+ ]
108
+
109
+ const fullMapping = [
110
+ {
111
+ id: "levis",
112
+ propertyMapping: [
113
+ { category: "ColorCode", from: "200", to: "Blauw" },
114
+ { category: "ColorCode", from: "100", to: "Wit" },
115
+ { category: "Collection", from: "SUMMER 2022", to: "22zomer" },
116
+ ],
117
+ },
118
+ {
119
+ id: "gstar",
120
+ propertyMapping: [{ category: "Collection", from: "SUMMER 2022", to: "22zomer" }],
121
+ },
122
+ ]
123
+
124
+ const originalSkus = deepCopy(skus)
125
+
126
+ describe("applyPropertyMapping", () => {
127
+ before(() => {
128
+ expect(applyPropertyMapping, "applyPropertyMapping").to.be.a("function")
129
+ })
130
+ it("returns empty array on an empty array", function () {
131
+ expect(applyPropertyMapping([], []).length).to.equal(0)
132
+ })
133
+
134
+ it("returns array untouched on an empty mapping", function () {
135
+ expect(applyPropertyMapping(skus, [])).to.deep.equal(originalSkus)
136
+ })
137
+
138
+ it("returns mapped colors on a color mapping", function () {
139
+ const mappedSkus = applyPropertyMapping(skus, colorMapping)
140
+ expect(mappedSkus[0].colorFamily).to.equal("Wit")
141
+ expect(mappedSkus[1].colorFamily).to.equal("Wit")
142
+ expect(mappedSkus[2].colorFamily).to.equal("Wit")
143
+ expect(mappedSkus[3].colorFamily).to.equal("Blauw")
144
+ expect(mappedSkus[4].colorFamily).to.equal("Blauw")
145
+ expect(mappedSkus[5].colorFamily).to.equal("Blauw")
146
+ expect(mappedSkus[6].colorFamily).to.equal("Blue")
147
+ expect(mappedSkus[7].colorFamily).to.equal("Blue")
148
+ expect(mappedSkus[8].colorFamily).to.equal("Blue")
149
+
150
+ expect(mappedSkus[0].collection).to.equal("22summer")
151
+ expect(mappedSkus[1].collection).to.equal("22summer")
152
+ expect(mappedSkus[2].collection).to.equal("22summer")
153
+ expect(mappedSkus[3].collection).to.equal("22summer")
154
+ expect(mappedSkus[4].collection).to.equal("22summer")
155
+ expect(mappedSkus[5].collection).to.equal("22summer")
156
+ expect(mappedSkus[6].collection).to.equal("22summer")
157
+ expect(mappedSkus[7].collection).to.equal("22summer")
158
+ expect(mappedSkus[8].collection).to.equal("22summer")
159
+ })
160
+
161
+ it("returns partially mapped skus on a partial mapping", function () {
162
+ const mappedSkus = applyPropertyMapping(skus, partialMapping)
163
+ expect(mappedSkus[0].colorFamily).to.equal("Wit")
164
+ expect(mappedSkus[1].colorFamily).to.equal("Wit")
165
+ expect(mappedSkus[2].colorFamily).to.equal("Wit")
166
+ expect(mappedSkus[3].colorFamily).to.equal("Blauw")
167
+ expect(mappedSkus[4].colorFamily).to.equal("Blauw")
168
+ expect(mappedSkus[5].colorFamily).to.equal("Blauw")
169
+ expect(mappedSkus[6].colorFamily).to.equal("Blue")
170
+ expect(mappedSkus[7].colorFamily).to.equal("Blue")
171
+ expect(mappedSkus[8].colorFamily).to.equal("Blue")
172
+
173
+ expect(mappedSkus[0].collection).to.equal("22zomer")
174
+ expect(mappedSkus[1].collection).to.equal("22zomer")
175
+ expect(mappedSkus[2].collection).to.equal("22zomer")
176
+ expect(mappedSkus[3].collection).to.equal("22zomer")
177
+ expect(mappedSkus[4].collection).to.equal("22zomer")
178
+ expect(mappedSkus[5].collection).to.equal("22zomer")
179
+ expect(mappedSkus[6].collection).to.equal("22summer")
180
+ expect(mappedSkus[7].collection).to.equal("22summer")
181
+ expect(mappedSkus[8].collection).to.equal("22summer")
182
+ })
183
+
184
+ it("returns fully mapped skus on a full mapping", function () {
185
+ const mappedSkus = applyPropertyMapping(skus, fullMapping)
186
+ expect(mappedSkus[0].colorFamily).to.equal("Wit")
187
+ expect(mappedSkus[1].colorFamily).to.equal("Wit")
188
+ expect(mappedSkus[2].colorFamily).to.equal("Wit")
189
+ expect(mappedSkus[3].colorFamily).to.equal("Blauw")
190
+ expect(mappedSkus[4].colorFamily).to.equal("Blauw")
191
+ expect(mappedSkus[5].colorFamily).to.equal("Blauw")
192
+ expect(mappedSkus[6].colorFamily).to.equal("Blue")
193
+ expect(mappedSkus[7].colorFamily).to.equal("Blue")
194
+ expect(mappedSkus[8].colorFamily).to.equal("Blue")
195
+
196
+ expect(mappedSkus[0].collection).to.equal("22zomer")
197
+ expect(mappedSkus[1].collection).to.equal("22zomer")
198
+ expect(mappedSkus[2].collection).to.equal("22zomer")
199
+ expect(mappedSkus[3].collection).to.equal("22zomer")
200
+ expect(mappedSkus[4].collection).to.equal("22zomer")
201
+ expect(mappedSkus[5].collection).to.equal("22zomer")
202
+ expect(mappedSkus[6].collection).to.equal("22zomer")
203
+ expect(mappedSkus[7].collection).to.equal("22zomer")
204
+ expect(mappedSkus[8].collection).to.equal("22zomer")
205
+ })
206
+ })
@@ -0,0 +1,17 @@
1
+ const { deepCopy } = require("../dist/index")
2
+ const { expect } = require("chai")
3
+
4
+ const input = { foo: { foo: "bar" }, fooArray: [3.14, "foo"] }
5
+ describe("deepCopy function", function () {
6
+ it("should return an exact copy of its nullish input", function () {
7
+ expect(deepCopy()).to.deep.eq(undefined)
8
+ expect(deepCopy(null)).to.deep.eq(null)
9
+ })
10
+ it("should return an object that deepEquals its input", function () {
11
+ expect(deepCopy("1234")).to.deep.eq("1234")
12
+ expect(deepCopy(input)).to.deep.eq(input)
13
+ })
14
+ it("should return a new object", function () {
15
+ expect(deepCopy(input)).to.not.eq(input)
16
+ })
17
+ })
@@ -1,5 +1,5 @@
1
1
  const { ean13 } = require("../dist/index")
2
- const { assert } = require("chai")
2
+ const { expect } = require("chai")
3
3
 
4
4
  const should = require("chai").should()
5
5
 
@@ -10,6 +10,6 @@ describe("ean13 function", function () {
10
10
  })
11
11
  })
12
12
  it("should calculate a valid check digit", function () {
13
- assert.equal(ean13("123456789012"), "1234567890128")
13
+ expect(ean13("123456789012")).to.equal(1234567890128)
14
14
  })
15
15
  })
@@ -1,17 +1,17 @@
1
1
  const { hashBrand } = require("../dist/index")
2
- const { assert } = require("chai")
2
+ const { expect } = require("chai")
3
3
 
4
4
  describe("hashBrand function", function () {
5
5
  it("should return an empty string on non-string inputs", function () {
6
- assert.equal(hashBrand(3), "")
6
+ expect(hashBrand(3)).to.equal("")
7
7
  })
8
8
  it("should return an empty string on an empty input", function () {
9
- assert.equal(hashBrand(""), "")
9
+ expect(hashBrand("")).to.equal("")
10
10
  })
11
11
  it("should return the input in lowercase without spaces", function () {
12
- assert.equal(hashBrand("Marie Jo"), "mariejo")
12
+ expect(hashBrand("Marie Jo")).to.equal("mariejo")
13
13
  })
14
14
  it("should return the input stripped from non characters", function () {
15
- assert.equal(hashBrand("Cl ~<>!@#$%^&*():'\"? ean"), "clean")
15
+ expect(hashBrand("Cl ~<>!@#$%^&*():'\"? ean")).to.equal("clean")
16
16
  })
17
17
  })