@softwear/latestcollectioncore 1.0.171 → 1.0.173

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,2 @@
1
+ import { BrandSettingI } from './types';
2
+ export default function (brand: string, brandsByHash: Record<string, BrandSettingI>, brands: BrandSettingI[], hashedBrand?: string): BrandSettingI | undefined;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const hashBrand_1 = __importDefault(require("./hashBrand"));
7
+ function isBrandEqual(hashedBrand, collection, aliases) {
8
+ return hashedBrand == collection || (aliases === null || aliases === void 0 ? void 0 : aliases.includes(hashedBrand));
9
+ }
10
+ function default_1(brand, brandsByHash, brands, hashedBrand = (0, hashBrand_1.default)(brand)) {
11
+ const mappedBrand = brandsByHash[hashedBrand];
12
+ if (mappedBrand)
13
+ return mappedBrand;
14
+ return brands.find((candidate) => isBrandEqual(hashedBrand, candidate.collection, candidate.aliases));
15
+ }
16
+ exports.default = default_1;
package/dist/hashBrand.js CHANGED
@@ -5,8 +5,8 @@ const DIACRITIC_REGEX = /[\u0300-\u036f]/g;
5
5
  // '~.<>!@#$%^&*():'"? /-\\'
6
6
  // Note: '-' is placed at the end of the class so it is treated literally,
7
7
  // and '\' is escaped.
8
- const REMOVE_CHARS_TEST_REGEX = /[~.<>!@#$%^&*()'"? \/\\-]/;
9
- const REMOVE_CHARS_REGEX = /[~.<>!@#$%^&*()'"? \/\\-]/g;
8
+ const REMOVE_CHARS_TEST_REGEX = /[~.<>!@#$%^&*():´`'"? \/\\-]/;
9
+ const REMOVE_CHARS_REGEX = /[~.<>!@#$%^&*():´`'"? \/\\-]/g;
10
10
  // Fast check: returns true if the string contains any non-ASCII character,
11
11
  // which we treat as a potential diacritic and normalize only in that case.
12
12
  function hasPotentialDiacritics(str) {
package/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export { default as edifact } from './edifact';
6
6
  export { default as ensureArray } from './ensureArray';
7
7
  export { default as ensureImpliedProperties } from './ensureImpliedProperties';
8
8
  export { default as findSkuByBarcode } from './findSkuByBarcode';
9
+ export { default as findMetaBrandSetting } from './findMetaBrandSetting';
9
10
  export { default as getBrandName } from './getBrandName';
10
11
  export { default as getPreferedPropertyMappings } from './getPreferedPropertyMappings';
11
12
  export { default as hashBrand } from './hashBrand';
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ 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.isAxiosError = exports.exponentialDelay = exports.axiosRetry = exports.createAxiosInstance = exports.lcAxios = exports.transaction = exports.sizeToMap = exports.round2 = exports.pivotTable = exports.isean13 = exports.imageBinder = exports.hasOnlyDigits = exports.hashBrand = exports.getPreferedPropertyMappings = exports.getBrandName = exports.findSkuByBarcode = exports.ensureImpliedProperties = exports.ensureArray = exports.edifact = exports.ean13 = exports.deepCopy = exports.buildPropertyMappingFn = exports.articleStatus = void 0;
20
+ exports.isAxiosError = exports.exponentialDelay = exports.axiosRetry = exports.createAxiosInstance = exports.lcAxios = exports.transaction = exports.sizeToMap = exports.round2 = exports.pivotTable = exports.isean13 = exports.imageBinder = exports.hasOnlyDigits = exports.hashBrand = exports.getPreferedPropertyMappings = exports.getBrandName = exports.findMetaBrandSetting = exports.findSkuByBarcode = exports.ensureImpliedProperties = exports.ensureArray = exports.edifact = exports.ean13 = exports.deepCopy = exports.buildPropertyMappingFn = exports.articleStatus = void 0;
21
21
  var articleStatus_1 = require("./articleStatus");
22
22
  Object.defineProperty(exports, "articleStatus", { enumerable: true, get: function () { return __importDefault(articleStatus_1).default; } });
23
23
  var buildPropertyMappingFn_1 = require("./buildPropertyMappingFn");
@@ -34,6 +34,8 @@ var ensureImpliedProperties_1 = require("./ensureImpliedProperties");
34
34
  Object.defineProperty(exports, "ensureImpliedProperties", { enumerable: true, get: function () { return __importDefault(ensureImpliedProperties_1).default; } });
35
35
  var findSkuByBarcode_1 = require("./findSkuByBarcode");
36
36
  Object.defineProperty(exports, "findSkuByBarcode", { enumerable: true, get: function () { return __importDefault(findSkuByBarcode_1).default; } });
37
+ var findMetaBrandSetting_1 = require("./findMetaBrandSetting");
38
+ Object.defineProperty(exports, "findMetaBrandSetting", { enumerable: true, get: function () { return __importDefault(findMetaBrandSetting_1).default; } });
37
39
  var getBrandName_1 = require("./getBrandName");
38
40
  Object.defineProperty(exports, "getBrandName", { enumerable: true, get: function () { return __importDefault(getBrandName_1).default; } });
39
41
  var getPreferedPropertyMappings_1 = require("./getPreferedPropertyMappings");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softwear/latestcollectioncore",
3
- "version": "1.0.171",
3
+ "version": "1.0.173",
4
4
  "description": "Core functions for LatestCollections applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,18 @@
1
+ import hashBrand from './hashBrand'
2
+ import { BrandSettingI } from './types'
3
+
4
+ function isBrandEqual(hashedBrand: string, collection?: string, aliases?: string[]) {
5
+ return hashedBrand == collection || aliases?.includes(hashedBrand)
6
+ }
7
+
8
+ export default function (
9
+ brand: string,
10
+ brandsByHash: Record<string, BrandSettingI>,
11
+ brands: BrandSettingI[],
12
+ hashedBrand = hashBrand(brand)
13
+ ): BrandSettingI | undefined {
14
+ const mappedBrand = brandsByHash[hashedBrand]
15
+ if (mappedBrand) return mappedBrand
16
+
17
+ return brands.find((candidate) => isBrandEqual(hashedBrand, candidate.collection, candidate.aliases))
18
+ }
package/src/hashBrand.ts CHANGED
@@ -3,8 +3,8 @@ const DIACRITIC_REGEX = /[\u0300-\u036f]/g
3
3
  // '~.<>!@#$%^&*():'"? /-\\'
4
4
  // Note: '-' is placed at the end of the class so it is treated literally,
5
5
  // and '\' is escaped.
6
- const REMOVE_CHARS_TEST_REGEX = /[~.<>!@#$%^&*()'"? \/\\-]/
7
- const REMOVE_CHARS_REGEX = /[~.<>!@#$%^&*()'"? \/\\-]/g
6
+ const REMOVE_CHARS_TEST_REGEX = /[~.<>!@#$%^&*():´`'"? \/\\-]/
7
+ const REMOVE_CHARS_REGEX = /[~.<>!@#$%^&*():´`'"? \/\\-]/g
8
8
 
9
9
  // Fast check: returns true if the string contains any non-ASCII character,
10
10
  // which we treat as a potential diacritic and normalize only in that case.
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ export { default as edifact } from './edifact'
6
6
  export { default as ensureArray } from './ensureArray'
7
7
  export { default as ensureImpliedProperties } from './ensureImpliedProperties'
8
8
  export { default as findSkuByBarcode } from './findSkuByBarcode'
9
+ export { default as findMetaBrandSetting } from './findMetaBrandSetting'
9
10
  export { default as getBrandName } from './getBrandName'
10
11
  export { default as getPreferedPropertyMappings } from './getPreferedPropertyMappings'
11
12
  export { default as hashBrand } from './hashBrand'
@@ -0,0 +1,21 @@
1
+ const { findMetaBrandSetting, hashBrand } = require('../dist/index')
2
+
3
+ describe('findMetaBrandSetting function', function () {
4
+ it('returns direct hash match from brandsByHash', function () {
5
+ const brand = { id: 'summum', name: 'Summum', collection: 'summum' }
6
+ const result = findMetaBrandSetting('Summum', { summum: brand }, [brand])
7
+ expect(result).toBe(brand)
8
+ })
9
+
10
+ it('returns alias fallback match when direct hash is missing', function () {
11
+ const brand = { id: 'summum', name: 'Summum', collection: 'summum', aliases: [hashBrand('summumwomen')] }
12
+ const result = findMetaBrandSetting('SummumWomen', {}, [brand])
13
+ expect(result).toBe(brand)
14
+ })
15
+
16
+ it('returns undefined when no match is found', function () {
17
+ const brand = { id: 'summum', name: 'Summum', collection: 'summum', aliases: [hashBrand('summumwomen')] }
18
+ const result = findMetaBrandSetting('DifferentBrand', {}, [brand])
19
+ expect(result).toBeUndefined()
20
+ })
21
+ })