@softwear/latestcollectioncore 1.0.174 → 1.0.175

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.
@@ -66,19 +66,20 @@ function prepFilterSkusImages(filteredSkus, merge = true, fileNames) {
66
66
  const skusCopy = (0, deepCopy_1.default)(filteredSkus);
67
67
  const preppedSkus = [];
68
68
  const fileNames2skip = [];
69
- let idx = 0;
70
- skusCopy.forEach((sku) => {
71
- const fieldsToBeMerged = {};
69
+ skusCopy.forEach((sku, idx) => {
72
70
  if (sku.images && sku.images.length > 0) {
73
71
  // If a fileName is already matched, we skip it
74
72
  fileNames.forEach((fileName) => {
75
73
  var _a;
76
- if (((_a = sku.images) === null || _a === void 0 ? void 0 : _a.includes(fileName)) && !fileNames2skip.includes(fileName))
74
+ if (((_a = sku.images) === null || _a === void 0 ? void 0 : _a.includes(fileName)) && fileNames2skip.indexOf(fileName) == -1)
77
75
  fileNames2skip.push(fileName);
78
76
  });
79
77
  // If a sku has images, we skip it
78
+ sku['skip'] = true;
79
+ preppedSkus.push(sku);
80
80
  return;
81
81
  }
82
+ const fieldsToBeMerged = {};
82
83
  for (const fieldName in sku) {
83
84
  if (fieldName == '__created' || fieldName == '__modified' || fieldName == 'images' || fieldName == 'brandhash' || (merge == true && fieldName == 'colorFamily'))
84
85
  continue;
@@ -107,7 +108,6 @@ function prepFilterSkusImages(filteredSkus, merge = true, fileNames) {
107
108
  else {
108
109
  const newSku = {};
109
110
  newSku['originalSku'] = filteredSkus[idx];
110
- idx++;
111
111
  for (const fieldVal in fieldsToBeMerged) {
112
112
  const fieldNameArray = fieldsToBeMerged[fieldVal].sort();
113
113
  if (fieldNameArray.length > 1) {
@@ -121,7 +121,7 @@ function prepFilterSkusImages(filteredSkus, merge = true, fileNames) {
121
121
  }
122
122
  });
123
123
  const fileNames2Match = fileNames.filter((fileName) => {
124
- return fileNames2skip.includes(fileName) == false;
124
+ return fileNames2skip.indexOf(fileName) == -1;
125
125
  });
126
126
  return { preppedSkus: preppedSkus, fileNames2Match: fileNames2Match };
127
127
  }
@@ -150,7 +150,7 @@ function checkWithoutLast(fileName) {
150
150
  .toLowerCase()
151
151
  .split(/[_\-.\s()]+|%[0-9A-Fa-f]{2}/)
152
152
  .slice(0, -1);
153
- const lastToken = tokens.at(-1);
153
+ const lastToken = tokens[tokens.length - 1];
154
154
  let returnWithoutLast = false;
155
155
  if (lastToken) {
156
156
  if (lastToken.includes('front') || lastToken.includes('back') || lastToken.includes('side') || lastToken.includes('sole'))
@@ -201,7 +201,7 @@ function testQuickSearch(cleanedFileName, fileName, fileNameWithoutLast, quickSe
201
201
  indicesToReturn.push(idx);
202
202
  patternStringFound = quickSearchPattern;
203
203
  }
204
- else if (indicesToReturn.length == 0 && pair[0] == fileNameWithoutLast && !indicesWithoutLast.includes(idx)) {
204
+ else if (indicesToReturn.length == 0 && pair[0] == fileNameWithoutLast && indicesWithoutLast.indexOf(idx) == -1) {
205
205
  indicesWithoutLast.push(idx);
206
206
  patternStringFound = quickSearchPattern;
207
207
  }
@@ -224,6 +224,8 @@ function prepQuickSearch(preppedSkus) {
224
224
  patternStrings.push(pattern.join('-'));
225
225
  });
226
226
  preppedSkus.forEach((sku, idx) => {
227
+ if (sku['skip'])
228
+ return;
227
229
  GLOBAL_PATTERNS.forEach((pattern, patternIndex) => {
228
230
  const proposedFilename = pattern.reduce((out, field) => out + (field in sku ? sku[field] : ''), '');
229
231
  if (proposedFilename) {
@@ -240,12 +242,12 @@ function prepQuickSearch(preppedSkus) {
240
242
  }
241
243
  function addNewPatternToQuickSearch(preppedSkus, pattern, quickSearch) {
242
244
  const newQuickSearchArray = [];
243
- let idx = 0;
244
- preppedSkus.forEach((sku) => {
245
+ preppedSkus.forEach((sku, idx) => {
246
+ if (sku['skip'])
247
+ return;
245
248
  const proposedFilename = pattern.reduce((out, field) => out + (field in sku ? sku[field] : ''), '');
246
249
  if (proposedFilename)
247
250
  newQuickSearchArray.push([proposedFilename, idx]);
248
- idx++;
249
251
  });
250
252
  quickSearch[pattern.join('-')] = newQuickSearchArray;
251
253
  return quickSearch;
@@ -258,6 +260,8 @@ function fallbackSearch(cleanedFileName, fileNameWithoutLast, preppedSkus) {
258
260
  let currentBestSubstringPatterns = {};
259
261
  let maxPatternlength = 0;
260
262
  preppedSkus.forEach((sku, idx) => {
263
+ if (sku['skip'])
264
+ return;
261
265
  if (pattern_found.length > 0) {
262
266
  // In case a new pattern has been found in one sku, test that on the remaining skus. If they don't match the pattern, skip them.
263
267
  const proposedFilename = pattern_found.reduce((out, field) => out + (field in sku ? sku[field] : ''), '');
@@ -359,7 +363,7 @@ function fallbackSearch(cleanedFileName, fileNameWithoutLast, preppedSkus) {
359
363
  const sku = preppedSkus[idx];
360
364
  pattern.forEach((fieldName) => {
361
365
  const fieldVal = sku[fieldName];
362
- if (fieldVal && !uniqueFieldVals.includes(fieldVal))
366
+ if (fieldVal && uniqueFieldVals.indexOf(fieldVal) == -1)
363
367
  uniqueFieldVals.push(fieldVal);
364
368
  });
365
369
  });
@@ -407,6 +411,8 @@ function imageBinder(fileNames, filteredSkus, brand, specifiedPattern, test = fa
407
411
  const fileNameWithoutLast = checkWithoutLast(fileName);
408
412
  fileNameIndexMatch[fileName] = [];
409
413
  preppedSkus.forEach((sku, idx) => {
414
+ if (sku['skip'])
415
+ return;
410
416
  let skuStillMatches = true;
411
417
  specifiedPattern.every((fieldName) => {
412
418
  if (!(fieldName in sku))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.174",
3
+ "version": "1.0.175",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,18 +32,19 @@ function prepFilterSkusImages(filteredSkus: SkuI[], merge = true, fileNames: Arr
32
32
  const skusCopy = deepCopy(filteredSkus)
33
33
  const preppedSkus: Array<Record<string, any>> = []
34
34
  const fileNames2skip: Array<string> = []
35
- let idx = 0
36
- skusCopy.forEach((sku) => {
37
- const fieldsToBeMerged = {}
35
+ skusCopy.forEach((sku, idx) => {
38
36
  if (sku.images && sku.images.length > 0) {
39
37
  // If a fileName is already matched, we skip it
40
38
  fileNames.forEach((fileName) => {
41
- if (sku.images?.includes(fileName) && !fileNames2skip.includes(fileName)) fileNames2skip.push(fileName)
39
+ if (sku.images?.includes(fileName) && fileNames2skip.indexOf(fileName) == -1) fileNames2skip.push(fileName)
42
40
  })
43
41
  // If a sku has images, we skip it
42
+ sku['skip'] = true
43
+ preppedSkus.push(sku)
44
44
  return
45
45
  }
46
46
 
47
+ const fieldsToBeMerged = {}
47
48
  for (const fieldName in sku) {
48
49
  if (fieldName == '__created' || fieldName == '__modified' || fieldName == 'images' || fieldName == 'brandhash' || (merge == true && fieldName == 'colorFamily')) continue
49
50
  let fieldVal = sku[fieldName]
@@ -70,7 +71,6 @@ function prepFilterSkusImages(filteredSkus: SkuI[], merge = true, fileNames: Arr
70
71
  } else {
71
72
  const newSku = {}
72
73
  newSku['originalSku'] = filteredSkus[idx]
73
- idx++
74
74
  for (const fieldVal in fieldsToBeMerged) {
75
75
  const fieldNameArray = fieldsToBeMerged[fieldVal].sort()
76
76
  if (fieldNameArray.length > 1) {
@@ -83,7 +83,7 @@ function prepFilterSkusImages(filteredSkus: SkuI[], merge = true, fileNames: Arr
83
83
  }
84
84
  })
85
85
  const fileNames2Match = fileNames.filter((fileName) => {
86
- return fileNames2skip.includes(fileName) == false
86
+ return fileNames2skip.indexOf(fileName) == -1
87
87
  })
88
88
  return { preppedSkus: preppedSkus, fileNames2Match: fileNames2Match }
89
89
  }
@@ -116,7 +116,7 @@ function checkWithoutLast(fileName: string) {
116
116
  .toLowerCase()
117
117
  .split(/[_\-.\s()]+|%[0-9A-Fa-f]{2}/)
118
118
  .slice(0, -1)
119
- const lastToken = tokens.at(-1)
119
+ const lastToken = tokens[tokens.length - 1]
120
120
  let returnWithoutLast = false
121
121
  if (lastToken) {
122
122
  if (lastToken.includes('front') || lastToken.includes('back') || lastToken.includes('side') || lastToken.includes('sole')) returnWithoutLast = true
@@ -167,7 +167,7 @@ function testQuickSearch(
167
167
  if (pair[0] == cleanedFileName) {
168
168
  indicesToReturn.push(idx)
169
169
  patternStringFound = quickSearchPattern
170
- } else if (indicesToReturn.length == 0 && pair[0] == fileNameWithoutLast && !indicesWithoutLast.includes(idx)) {
170
+ } else if (indicesToReturn.length == 0 && pair[0] == fileNameWithoutLast && indicesWithoutLast.indexOf(idx) == -1) {
171
171
  indicesWithoutLast.push(idx)
172
172
  patternStringFound = quickSearchPattern
173
173
  }
@@ -188,6 +188,7 @@ function prepQuickSearch(preppedSkus: any): Record<string, Array<any>> {
188
188
  patternStrings.push(pattern.join('-'))
189
189
  })
190
190
  preppedSkus.forEach((sku, idx) => {
191
+ if (sku['skip']) return
191
192
  GLOBAL_PATTERNS.forEach((pattern, patternIndex) => {
192
193
  const proposedFilename = pattern.reduce((out, field) => out + (field in sku ? sku[field] : ''), '')
193
194
  if (proposedFilename) {
@@ -204,11 +205,10 @@ function prepQuickSearch(preppedSkus: any): Record<string, Array<any>> {
204
205
 
205
206
  function addNewPatternToQuickSearch(preppedSkus: any, pattern: Array<string>, quickSearch: Record<string, Array<Array<any>>>): Record<string, Array<any>> {
206
207
  const newQuickSearchArray: Array<Array<any>> = []
207
- let idx = 0
208
- preppedSkus.forEach((sku) => {
208
+ preppedSkus.forEach((sku, idx) => {
209
+ if (sku['skip']) return
209
210
  const proposedFilename = pattern.reduce((out, field) => out + (field in sku ? sku[field] : ''), '')
210
211
  if (proposedFilename) newQuickSearchArray.push([proposedFilename, idx])
211
- idx++
212
212
  })
213
213
  quickSearch[pattern.join('-')] = newQuickSearchArray
214
214
  return quickSearch
@@ -223,6 +223,7 @@ function fallbackSearch(cleanedFileName: string, fileNameWithoutLast: string, pr
223
223
  let currentBestSubstringPatterns: Record<string, Array<number>> = {}
224
224
  let maxPatternlength = 0
225
225
  preppedSkus.forEach((sku, idx) => {
226
+ if (sku['skip']) return
226
227
  if (pattern_found.length > 0) {
227
228
  // In case a new pattern has been found in one sku, test that on the remaining skus. If they don't match the pattern, skip them.
228
229
  const proposedFilename = pattern_found.reduce((out, field) => out + (field in sku ? sku[field] : ''), '')
@@ -282,15 +283,15 @@ function fallbackSearch(cleanedFileName: string, fileNameWithoutLast: string, pr
282
283
  substringPattern.splice(idx, 1)
283
284
  }
284
285
  })
285
- const proposedFilename = Object.values(substringObject).join('')
286
+ const proposedFilename = (<any>Object).values(substringObject).join('')
286
287
  if (proposedFilename == cleanedFileName || (fileNameWithoutLast && proposedFilename == fileNameWithoutLast)) {
287
288
  // We've discovered a new pattern
288
- pattern_found = Object.values(patternObject)
289
+ pattern_found = (<any>Object).values(patternObject)
289
290
  exactMatches.push(idx)
290
291
  return
291
292
  }
292
- patternString = Object.values(patternObject).join('-')
293
- const revisedPatternLength = Object.values(patternObject).length
293
+ patternString = (<any>Object).values(patternObject).join('-')
294
+ const revisedPatternLength = (<any>Object).values(patternObject).length
294
295
  if (revisedPatternLength == maxPatternlength) {
295
296
  // We've found a new pattern of the same length, so we keep this one too
296
297
  if (patternString in currentBestSubstringPatterns) {
@@ -317,7 +318,7 @@ function fallbackSearch(cleanedFileName: string, fileNameWithoutLast: string, pr
317
318
  const sku = preppedSkus[idx]
318
319
  pattern.forEach((fieldName) => {
319
320
  const fieldVal = sku[fieldName]
320
- if (fieldVal && !uniqueFieldVals.includes(fieldVal)) uniqueFieldVals.push(fieldVal)
321
+ if (fieldVal && uniqueFieldVals.indexOf(fieldVal) == -1) uniqueFieldVals.push(fieldVal)
321
322
  })
322
323
  })
323
324
  uniqueFieldVals.sort((a, b) => {
@@ -364,6 +365,7 @@ function imageBinder(fileNames: Array<string>, filteredSkus: SkuI[], brand: stri
364
365
  const fileNameWithoutLast = checkWithoutLast(fileName)
365
366
  fileNameIndexMatch[fileName] = []
366
367
  preppedSkus.forEach((sku, idx) => {
368
+ if (sku['skip']) return
367
369
  let skuStillMatches = true
368
370
  specifiedPattern.every((fieldName) => {
369
371
  if (!(fieldName in sku)) skuStillMatches = false
@@ -7,7 +7,7 @@ describe('imageBinder function', function () {
7
7
  // Tests on 1061 images, 1058 of which are fallback searches that return no results
8
8
  const result = await testBatch('miraclesuit')
9
9
  expect(Object.keys(result).length).toBe(8)
10
- expect(result.Mismatches).toBe(1058)
10
+ expect(result.Mismatches).toBe(1052)
11
11
  expect(result.QuickSearch).toBe(3)
12
12
  expect(result.Patterns['articleCode|articleCodeSupplier-articleDescription-colorCodeSupplier|colorSupplier']).toBe(3)
13
13
  // Time can vary, so we use a loose check (within 5 seconds)
@@ -19,8 +19,8 @@ describe('imageBinder function', function () {
19
19
  const result = await testBatch('lowa')
20
20
  expect(Object.keys(result).length).toBe(8)
21
21
  expect(result.Mismatches).toBe(0)
22
- expect(result.QuickSearch).toBe(1593)
23
- expect(result.Patterns['articleCode|articleCodeSupplier-colorCodeSupplier|colorSupplier']).toBe(1592)
22
+ expect(result.QuickSearch).toBe(1587)
23
+ expect(result.Patterns['articleCode|articleCodeSupplier-colorCodeSupplier|colorSupplier']).toBe(1586)
24
24
  // Time can vary, so we use a loose check (within 5 seconds)
25
25
  expect(result.Time).toBeGreaterThan(0)
26
26
  expect(result.Time).toBeLessThan(5)
@@ -30,9 +30,9 @@ describe('imageBinder function', function () {
30
30
  const result = await testBatch('vacanzeitaliane')
31
31
  expect(Object.keys(result).length).toBe(8)
32
32
  expect(result.Brand).toBe('vacanzeitaliane')
33
- expect(result.Mismatches).toBe(210)
34
- expect(result.QuickSearch).toBe(506)
35
- expect(result.Patterns['articleCode|articleCodeSupplier']).toBe(516)
33
+ expect(result.Mismatches).toBe(214)
34
+ expect(result.QuickSearch).toBe(496)
35
+ expect(result.Patterns['articleCode|articleCodeSupplier']).toBe(506)
36
36
  // Time can vary, so we use a loose check (within 5 seconds)
37
37
  expect(result.Time).toBeGreaterThan(0)
38
38
  expect(result.Time).toBeLessThan(5)
@@ -42,8 +42,8 @@ describe('imageBinder function', function () {
42
42
  expect(Object.keys(result).length).toBe(8)
43
43
  expect(result.Brand).toBe('dreamstar')
44
44
  expect(result.Mismatches).toBe(0)
45
- expect(result.QuickSearch).toBe(792)
46
- expect(result.Patterns['articleCode|articleCodeSupplier-colorCodeSupplier|colorSupplier']).toBe(634)
45
+ expect(result.QuickSearch).toBe(786)
46
+ expect(result.Patterns['articleCode|articleCodeSupplier-colorCodeSupplier|colorSupplier']).toBe(631)
47
47
  // Time can vary, so we use a loose check (within 5 seconds)
48
48
  expect(result.Time).toBeGreaterThan(0)
49
49
  expect(result.Time).toBeLessThan(5)