Skip to content

Commit 765f46b

Browse files
authored
makeCommaSeparatedString: add lastSeparator and postfixargs (#1830)
- makeCommaSeparatedString - Add lastSeparator and postfix args - export
1 parent 8634056 commit 765f46b

6 files changed

Lines changed: 30 additions & 6 deletions

File tree

packages/components/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@labkey/components",
3-
"version": "6.54.3",
3+
"version": "6.55.0",
44
"description": "Components, models, actions, and utility functions for LabKey applications and pages",
55
"sideEffects": false,
66
"files": [

packages/components/releaseNotes/components.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# @labkey/components
22
Components, models, actions, and utility functions for LabKey applications and pages
33

4+
### version 6.55.0
5+
*Released*: 10 July 2025
6+
- makeCommaSeparatedString: Add lastSeparator and postfix args, export
7+
48
### version 6.54.3
59
*Released*: 10 July 2025
610
- Issue 52657: LKSM: We shouldn't allow creating sample names that differ only in case

packages/components/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import {
6767
isNonNegativeFloat,
6868
isNonNegativeInteger,
6969
isSetEqual,
70+
makeCommaSeparatedString,
7071
parseCsvString,
7172
parseScientificInt,
7273
quoteValueWithDelimiters,
@@ -1557,6 +1558,7 @@ export {
15571558
LockIcon,
15581559
LOOK_AND_FEEL_METRIC,
15591560
LookupSelectInput,
1561+
makeCommaSeparatedString,
15601562
makeQueryInfo,
15611563
makeTestActions,
15621564
makeTestISelectRowsResult,

packages/components/src/internal/util/utils.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,24 @@ describe('makeCommaSeparatedString', () => {
14161416
expect(makeCommaSeparatedString([123, 456])).toBe('123 and 456');
14171417
expect(makeCommaSeparatedString([123, 'blood', true])).toBe('123, blood and true');
14181418
});
1419+
1420+
test('lastSeparator', () => {
1421+
expect(makeCommaSeparatedString(['blood'], ', or ')).toBe('blood');
1422+
expect(makeCommaSeparatedString(['blood', 'saliva', 'dna'], ', or ')).toEqual('blood, saliva, or dna');
1423+
expect(makeCommaSeparatedString([1, 2, 3], ', and ')).toEqual('1, 2, and 3');
1424+
});
1425+
1426+
test('postfix', () => {
1427+
expect(makeCommaSeparatedString(['blood'], undefined, '.')).toBe('blood.');
1428+
expect(makeCommaSeparatedString(['blood', 'saliva', 'dna'], undefined, '.')).toEqual('blood, saliva and dna.');
1429+
expect(makeCommaSeparatedString([1, 2, 3], undefined, '.')).toEqual('1, 2 and 3.');
1430+
});
1431+
1432+
test('lastSeparator & postfix', () => {
1433+
expect(makeCommaSeparatedString(['blood'], ', or ', '.')).toBe('blood.');
1434+
expect(makeCommaSeparatedString(['blood', 'saliva', 'dna'], ', or ', '.')).toEqual('blood, saliva, or dna.');
1435+
expect(makeCommaSeparatedString([1, 2, 3], ', and ', '.')).toEqual('1, 2, and 3.');
1436+
});
14191437
});
14201438

14211439
describe('getValuesSummary', () => {

packages/components/src/internal/util/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,13 @@ export function getValueFromRow(row: Record<string, any>, col: string): string |
694694
return val;
695695
}
696696

697-
export function makeCommaSeparatedString<T>(values: T[]): string {
697+
export function makeCommaSeparatedString<T>(values: T[], lastSeparator = ' and ', postfix = ''): string {
698698
if (!values || values.length === 0) return '';
699-
if (values.length === 1) return values[0] + '';
699+
if (values.length === 1) return values[0] + postfix;
700700

701701
const firsts = values.slice(0, values.length - 1);
702702
const last = values[values.length - 1];
703-
return firsts.join(', ') + ' and ' + last;
703+
return firsts.join(', ') + lastSeparator + last + postfix;
704704
}
705705

706706
/**

0 commit comments

Comments
 (0)