@managesome/eposmatic-toolkit 0.2.771 → 0.2.772
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.
|
@@ -136,7 +136,13 @@ export declare function getReceiptEngineFooterDetails(order: Partial<IOrder>, se
|
|
|
136
136
|
export declare const plusSymbolModifierTitles: string[];
|
|
137
137
|
export declare const minusSymbolModifierTitles: string[];
|
|
138
138
|
export declare function getItemModifierTitle(name: string): string;
|
|
139
|
-
|
|
139
|
+
/**
|
|
140
|
+
* The modifier title with the option name removed, so the line does not print
|
|
141
|
+
* the overlap twice. A + / - marker (added by `getItemModifierTitle`) is always
|
|
142
|
+
* kept, and a title the option name already covers is dropped entirely.
|
|
143
|
+
* Matching is case-insensitive and treats whitespace runs as equivalent.
|
|
144
|
+
*/
|
|
145
|
+
export declare function getStrippedModifierTitle(modifierTitle: string, optionName: string): string;
|
|
140
146
|
/**
|
|
141
147
|
* Mutates the options array by adding modifier options to it.
|
|
142
148
|
*
|
|
@@ -7,7 +7,7 @@ exports.getPartialItems = exports.minusSymbolModifierTitles = exports.plusSymbol
|
|
|
7
7
|
exports.getDiscountLabel = getDiscountLabel;
|
|
8
8
|
exports.getReceiptEngineFooterDetails = getReceiptEngineFooterDetails;
|
|
9
9
|
exports.getItemModifierTitle = getItemModifierTitle;
|
|
10
|
-
exports.
|
|
10
|
+
exports.getStrippedModifierTitle = getStrippedModifierTitle;
|
|
11
11
|
exports.getReceiptItemModifiers = getReceiptItemModifiers;
|
|
12
12
|
exports.getOrderItemReceiptBody = getOrderItemReceiptBody;
|
|
13
13
|
exports.getReceiptBody = getReceiptBody;
|
|
@@ -302,11 +302,28 @@ function getItemModifierTitle(name) {
|
|
|
302
302
|
}
|
|
303
303
|
return modifierName;
|
|
304
304
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
305
|
+
/**
|
|
306
|
+
* The modifier title with the option name removed, so the line does not print
|
|
307
|
+
* the overlap twice. A + / - marker (added by `getItemModifierTitle`) is always
|
|
308
|
+
* kept, and a title the option name already covers is dropped entirely.
|
|
309
|
+
* Matching is case-insensitive and treats whitespace runs as equivalent.
|
|
310
|
+
*/
|
|
311
|
+
function getStrippedModifierTitle(modifierTitle, optionName) {
|
|
312
|
+
const marker = modifierTitle.match(/^[+-]/)?.[0] ?? '';
|
|
313
|
+
const title = modifierTitle.replace(/^[+-]\s*/, '');
|
|
314
|
+
const normalizedTitle = title.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
315
|
+
const normalizedOption = optionName.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
316
|
+
// The option name already says everything the title says - keep only the marker.
|
|
317
|
+
if (normalizedTitle !== '' && normalizedOption.includes(normalizedTitle)) {
|
|
318
|
+
return marker;
|
|
319
|
+
}
|
|
320
|
+
const pattern = optionName
|
|
321
|
+
.trim()
|
|
322
|
+
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
323
|
+
.split(/\s+/)
|
|
324
|
+
.join('\\s+');
|
|
325
|
+
const strippedTitle = title.replace(new RegExp(pattern, 'gi'), '').trim();
|
|
326
|
+
return `${marker}${strippedTitle !== '' ? ` ${strippedTitle}` : ''}`.trim();
|
|
310
327
|
}
|
|
311
328
|
/**
|
|
312
329
|
* Mutates the options array by adding modifier options to it.
|
|
@@ -351,25 +368,19 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
|
|
|
351
368
|
modifierOptions.push(option);
|
|
352
369
|
}
|
|
353
370
|
}
|
|
354
|
-
else {
|
|
355
|
-
modifierOptions = modifierOptions.map((option) => ({
|
|
356
|
-
...option,
|
|
357
|
-
// With hide_modifier_name on, the modifier name is not printed, so
|
|
358
|
-
// the option name must not be merged with it - keep it as-is.
|
|
359
|
-
name: hide_modifier_name
|
|
360
|
-
? (0, common_1.titleCase)(option.name)
|
|
361
|
-
: (0, common_1.titleCase)(getItemModifierOptionTitle(modifierName, option.name)),
|
|
362
|
-
}));
|
|
363
|
-
}
|
|
364
371
|
for (let j = 0; j < modifierOptions.length; j++) {
|
|
365
372
|
const option = modifierOptions[j];
|
|
366
373
|
const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
374
|
+
// The option name is what survives; the modifier title only prints its
|
|
375
|
+
// non-overlapping remainder, so identical names collapse into the option
|
|
376
|
+
// name alone.
|
|
377
|
+
const strippedModifierName = hide_modifier_name ? '' : getStrippedModifierTitle(modifierName, option.name);
|
|
378
|
+
const optionDescription = strippedModifierName !== ''
|
|
379
|
+
? `${space}${optionQuantity}${strippedModifierName} `
|
|
380
|
+
: `${space}${optionQuantity}`;
|
|
370
381
|
options.push({
|
|
371
382
|
left: (0, emoji_strip_1.default)(optionDescription),
|
|
372
|
-
option_name: (0, emoji_strip_1.default)(option.name),
|
|
383
|
+
option_name: (0, emoji_strip_1.default)((0, common_1.titleCase)(option.name)),
|
|
373
384
|
});
|
|
374
385
|
if (option.modifiers != null && option.modifiers.length > 0) {
|
|
375
386
|
getReceiptItemModifiers(option.modifiers, options, display_modifiers_on_separate_lines, space, hide_modifier_name);
|
|
@@ -383,18 +394,16 @@ function getReceiptItemModifiers(itemModifiers, options = [], display_modifiers_
|
|
|
383
394
|
const modifierName = getItemModifierTitle(modifier.name);
|
|
384
395
|
for (let j = 0; j < modifier.options.length; j++) {
|
|
385
396
|
const option = modifier.options[j];
|
|
386
|
-
// With hide_modifier_name on, the modifier name is not printed, so
|
|
387
|
-
// the option name must not be merged with it - keep it as-is.
|
|
388
|
-
const optionName = hide_modifier_name
|
|
389
|
-
? (0, common_1.sentenceCase)(option.name)
|
|
390
|
-
: (0, common_1.sentenceCase)(getItemModifierOptionTitle(modifierName, option.name));
|
|
391
397
|
const optionQuantity = option.quantity > 1 ? `${option.quantity}x ` : '';
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
398
|
+
// Mirrors the flat mode: the option name is what survives, and the
|
|
399
|
+
// modifier title only prints its non-overlapping remainder.
|
|
400
|
+
const strippedModifierName = hide_modifier_name ? '' : getStrippedModifierTitle(modifierName, option.name);
|
|
401
|
+
const optionDescription = strippedModifierName !== ''
|
|
402
|
+
? `${space}${optionQuantity}${strippedModifierName} `
|
|
403
|
+
: `${space}${optionQuantity}`;
|
|
395
404
|
options.push({
|
|
396
405
|
left: (0, emoji_strip_1.default)(optionDescription),
|
|
397
|
-
option_name: (0, emoji_strip_1.default)(
|
|
406
|
+
option_name: (0, emoji_strip_1.default)((0, common_1.sentenceCase)(option.name)),
|
|
398
407
|
});
|
|
399
408
|
if (option.modifiers) {
|
|
400
409
|
getReceiptItemModifiers(option.modifiers, options, display_modifiers_on_separate_lines, space, hide_modifier_name);
|
|
@@ -254,7 +254,7 @@ describe('getPartialItems - composite items on partial KOTs (ref_type)', () => {
|
|
|
254
254
|
});
|
|
255
255
|
// =========================><=========================
|
|
256
256
|
describe('getReceiptItemModifiers - hide_modifier_name', () => {
|
|
257
|
-
it('
|
|
257
|
+
it('collapses identical modifier and option names into the option name', () => {
|
|
258
258
|
const options = [];
|
|
259
259
|
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
260
260
|
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
@@ -262,8 +262,8 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
|
|
|
262
262
|
]),
|
|
263
263
|
], options, false, '', false);
|
|
264
264
|
expect(options).toHaveLength(1);
|
|
265
|
-
expect(options[0].left).toBe('
|
|
266
|
-
expect(options[0].option_name).toBe('');
|
|
265
|
+
expect(options[0].left).toBe(' ');
|
|
266
|
+
expect(options[0].option_name).toBe('Tikka pizza');
|
|
267
267
|
});
|
|
268
268
|
it('prints the full option name when hide_modifier_name is on (no merge)', () => {
|
|
269
269
|
const options = [];
|
|
@@ -330,4 +330,66 @@ describe('getReceiptItemModifiers - hide_modifier_name', () => {
|
|
|
330
330
|
expect(options[0].left).toBe(' ');
|
|
331
331
|
expect(options[0].option_name).toBe('Tikka Pizza Large');
|
|
332
332
|
});
|
|
333
|
+
it('collapses identical names into the option name in separate-lines mode too', () => {
|
|
334
|
+
const options = [];
|
|
335
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
336
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
337
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
|
|
338
|
+
]),
|
|
339
|
+
], options, true, '', false);
|
|
340
|
+
expect(options).toHaveLength(1);
|
|
341
|
+
expect(options[0].left).toBe(' ');
|
|
342
|
+
expect(options[0].option_name).toBe('Tikka Pizza');
|
|
343
|
+
});
|
|
344
|
+
it('keeps the modifier title when the option name does not overlap it', () => {
|
|
345
|
+
const options = [];
|
|
346
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([makeModifier('mod-size', 'modref-size', 'SIZE', [makeOption('opt-large', 'size-large', 'Large')])], options, false, '', false);
|
|
347
|
+
expect(options).toHaveLength(1);
|
|
348
|
+
expect(options[0].left).toBe(' SIZE ');
|
|
349
|
+
expect(options[0].option_name).toBe('Large');
|
|
350
|
+
});
|
|
351
|
+
it('keeps the + marker when a keyword-styled title collapses', () => {
|
|
352
|
+
const options = [];
|
|
353
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
354
|
+
makeModifier('mod-wings', 'modref-wings', 'Extra Hot Wings', [
|
|
355
|
+
makeOption('opt-wings', 'wings-extra', 'Extra Hot Wings'),
|
|
356
|
+
]),
|
|
357
|
+
], options, false, '', false);
|
|
358
|
+
expect(options).toHaveLength(1);
|
|
359
|
+
expect(options[0].left).toBe(' + ');
|
|
360
|
+
expect(options[0].option_name).toBe('Extra hot wings');
|
|
361
|
+
});
|
|
362
|
+
it('keeps the - marker for removal-style titles', () => {
|
|
363
|
+
const options = [];
|
|
364
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
365
|
+
makeModifier('mod-onion', 'modref-onion', 'Without Onion', [
|
|
366
|
+
makeOption('opt-onion', 'onion-remove', 'Without Onion'),
|
|
367
|
+
]),
|
|
368
|
+
], options, false, '', false);
|
|
369
|
+
expect(options).toHaveLength(1);
|
|
370
|
+
expect(options[0].left).toBe(' - ');
|
|
371
|
+
expect(options[0].option_name).toBe('Without onion');
|
|
372
|
+
});
|
|
373
|
+
it('drops the title when the option name fully covers it', () => {
|
|
374
|
+
const options = [];
|
|
375
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
376
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
377
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza Large'),
|
|
378
|
+
]),
|
|
379
|
+
], options, false, '', false);
|
|
380
|
+
expect(options).toHaveLength(1);
|
|
381
|
+
expect(options[0].left).toBe(' ');
|
|
382
|
+
expect(options[0].option_name).toBe('Tikka pizza large');
|
|
383
|
+
});
|
|
384
|
+
it('collapses names that only differ in whitespace', () => {
|
|
385
|
+
const options = [];
|
|
386
|
+
(0, receipt_engine_1.getReceiptItemModifiers)([
|
|
387
|
+
makeModifier('mod-pizza', 'modref-pizza', 'Tikka Pizza', [
|
|
388
|
+
makeOption('opt-tikka', 'pizza-tikka', 'Tikka Pizza'),
|
|
389
|
+
]),
|
|
390
|
+
], options, false, '', false);
|
|
391
|
+
expect(options).toHaveLength(1);
|
|
392
|
+
expect(options[0].left).toBe(' ');
|
|
393
|
+
expect(options[0].option_name).toBe('Tikka pizza');
|
|
394
|
+
});
|
|
333
395
|
});
|