mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
errors: refactor to use a method that formats a list string
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com> PR-URL: https://github.com/nodejs/node/pull/45793 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
98fc94a444
commit
8046e0ef53
3 files changed
+41
-38
No files matched your search
@@ -0,0 +1,20 @@
|
||||
// Flags: --expose-internals
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const { strictEqual } = require('node:assert');
|
||||
const { formatList } = require('internal/errors');
|
||||
|
||||
if (!common.hasIntl) common.skip('missing Intl');
|
||||
|
||||
{
|
||||
const and = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
|
||||
const or = new Intl.ListFormat('en', { style: 'long', type: 'disjunction' });
|
||||
|
||||
const input = ['apple', 'banana', 'orange'];
|
||||
for (let i = 0; i < input.length; i++) {
|
||||
const slicedInput = input.slice(0, i);
|
||||
strictEqual(formatList(slicedInput), and.format(slicedInput));
|
||||
strictEqual(formatList(slicedInput, 'or'), or.format(slicedInput));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user