denwa-web-shared 1.0.48 → 1.0.50

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.
@@ -429,16 +429,23 @@ const uuidToStringId = (uuid2, length = 18) => {
429
429
  return cleanUuid.slice(-length);
430
430
  };
431
431
  const uuidToNumericId = (uuid2, maxDigits = 18) => {
432
- const hex = uuid2.replace(/-/g, "");
433
- const safeHex = hex.slice(-14);
434
- const num = parseInt(safeHex, 16);
435
- let numStr = num.toString();
436
- if (numStr.length < maxDigits) {
437
- numStr = numStr.padStart(maxDigits, "0");
438
- } else if (numStr.length > maxDigits) {
439
- numStr = numStr.slice(-maxDigits);
432
+ const cleanUuid = uuid2.replace(/-/g, "");
433
+ let hash = 0;
434
+ for (let i = 0; i < cleanUuid.length; i++) {
435
+ const char = cleanUuid.charCodeAt(i);
436
+ hash = (hash << 5) - hash + char;
437
+ hash = hash & hash;
438
+ }
439
+ let result = Math.abs(hash).toString();
440
+ if (result.length < maxDigits) {
441
+ const segments = cleanUuid.match(/.{1,4}/g) || [];
442
+ for (const segment of segments) {
443
+ const segmentNum = parseInt(segment, 16);
444
+ result += Math.abs(segmentNum).toString();
445
+ if (result.length >= maxDigits) break;
446
+ }
440
447
  }
441
- return numStr;
448
+ return result.slice(0, maxDigits);
442
449
  };
443
450
  const escapeXml = (str) => {
444
451
  if (!str) return "";
@@ -467,7 +474,7 @@ const generateYandexFeedXML = ({
467
474
  <name>${escapeXml(item.name)}</name>
468
475
  <vendor>${escapeXml(item.vendor)}</vendor>
469
476
  <description>${escapeXml(item.description)}</description>
470
- <vendorCode>${escapeXml(item.vendorCode)}</vendorCode>
477
+ ${item.vendorCode && `<vendorCode>${escapeXml(item.vendorCode)}</vendorCode>`}
471
478
  <pickup>${item.pickup}</pickup>
472
479
  ${(_a = item.params) == null ? void 0 : _a.map((item2) => {
473
480
  return `<param name="${item2.name}">${escapeXml(item2.value)}</param>`;
@@ -477,7 +484,8 @@ const generateYandexFeedXML = ({
477
484
  }).join("");
478
485
  const categoriesXml = categoriesData.map((item) => {
479
486
  const id = typeof item.id === "number" ? item.id : uuidToNumericId(item.id);
480
- return `<category id="${id}">${escapeXml(item.name)}</category>`;
487
+ const parentId = item.parentId ? ` parentId="${typeof item.parentId === "number" ? item.parentId : uuidToNumericId(item.parentId)}"` : "";
488
+ return `<category id="${id}"${parentId}>${escapeXml(item.name)}</category>`;
481
489
  }).join("");
482
490
  return `<?xml version="1.0" encoding="UTF-8"?>
483
491
  <!DOCTYPE yml_catalog SYSTEM "shops.dtd">
@@ -427,16 +427,23 @@ const uuidToStringId = (uuid2, length = 18) => {
427
427
  return cleanUuid.slice(-length);
428
428
  };
429
429
  const uuidToNumericId = (uuid2, maxDigits = 18) => {
430
- const hex = uuid2.replace(/-/g, "");
431
- const safeHex = hex.slice(-14);
432
- const num = parseInt(safeHex, 16);
433
- let numStr = num.toString();
434
- if (numStr.length < maxDigits) {
435
- numStr = numStr.padStart(maxDigits, "0");
436
- } else if (numStr.length > maxDigits) {
437
- numStr = numStr.slice(-maxDigits);
430
+ const cleanUuid = uuid2.replace(/-/g, "");
431
+ let hash = 0;
432
+ for (let i = 0; i < cleanUuid.length; i++) {
433
+ const char = cleanUuid.charCodeAt(i);
434
+ hash = (hash << 5) - hash + char;
435
+ hash = hash & hash;
436
+ }
437
+ let result = Math.abs(hash).toString();
438
+ if (result.length < maxDigits) {
439
+ const segments = cleanUuid.match(/.{1,4}/g) || [];
440
+ for (const segment of segments) {
441
+ const segmentNum = parseInt(segment, 16);
442
+ result += Math.abs(segmentNum).toString();
443
+ if (result.length >= maxDigits) break;
444
+ }
438
445
  }
439
- return numStr;
446
+ return result.slice(0, maxDigits);
440
447
  };
441
448
  const escapeXml = (str) => {
442
449
  if (!str) return "";
@@ -465,7 +472,7 @@ const generateYandexFeedXML = ({
465
472
  <name>${escapeXml(item.name)}</name>
466
473
  <vendor>${escapeXml(item.vendor)}</vendor>
467
474
  <description>${escapeXml(item.description)}</description>
468
- <vendorCode>${escapeXml(item.vendorCode)}</vendorCode>
475
+ ${item.vendorCode && `<vendorCode>${escapeXml(item.vendorCode)}</vendorCode>`}
469
476
  <pickup>${item.pickup}</pickup>
470
477
  ${(_a = item.params) == null ? void 0 : _a.map((item2) => {
471
478
  return `<param name="${item2.name}">${escapeXml(item2.value)}</param>`;
@@ -475,7 +482,8 @@ const generateYandexFeedXML = ({
475
482
  }).join("");
476
483
  const categoriesXml = categoriesData.map((item) => {
477
484
  const id = typeof item.id === "number" ? item.id : uuidToNumericId(item.id);
478
- return `<category id="${id}">${escapeXml(item.name)}</category>`;
485
+ const parentId = item.parentId ? ` parentId="${typeof item.parentId === "number" ? item.parentId : uuidToNumericId(item.parentId)}"` : "";
486
+ return `<category id="${id}"${parentId}>${escapeXml(item.name)}</category>`;
479
487
  }).join("");
480
488
  return `<?xml version="1.0" encoding="UTF-8"?>
481
489
  <!DOCTYPE yml_catalog SYSTEM "shops.dtd">
@@ -231,13 +231,14 @@ export declare const generateYandexFeedXML: ({ shopName, shopCompany, delivery,
231
231
  categoriesData: {
232
232
  id: string | number;
233
233
  name: string;
234
+ parentId?: string | number;
234
235
  }[];
235
236
  offersData: {
236
237
  id: string | number;
237
238
  categoryId: string | number;
238
239
  name: string;
239
240
  vendor: string;
240
- vendorCode: string;
241
+ vendorCode?: string | null;
241
242
  description: string;
242
243
  href: string;
243
244
  images: IPreparedServerImageWithAlt[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "denwa-web-shared",
3
3
  "private": false,
4
- "version": "1.0.48",
4
+ "version": "1.0.50",
5
5
  "type": "module",
6
6
  "author": "Denwa",
7
7
  "main": "dist/denwa-web-shared.cjs.js",