Skip to content

Commit a13fc4e

Browse files
committed
fix: adjust labels
Display boolean values in labels when using `long` verbosity.
1 parent 87ab626 commit a13fc4e

10 files changed

+10
-7
lines changed

e2e/svelte-4/package-lock.json

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading
Loading
Loading
Loading
Loading

lib/cartesian.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,17 @@ export function createLabel (
4545
innerProps,
4646
{ verbosity } = { verbosity: 'short' }
4747
) {
48+
const shortValues = ['string', 'number', 'boolean']
4849
const label = []
4950
const shortVerbosity = verbosity === 'short' || verbosity === true
5051
const joinCharacter = shortVerbosity ? ', ' : '\n'
5152

5253
for (const [key, value] of Object.entries(innerProps)) {
54+
const isShortValue = shortValues.includes(typeof value)
55+
5356
if (
5457
shortVerbosity
55-
&& typeof value !== 'string'
56-
&& typeof value !== 'number'
57-
&& typeof value !== 'boolean'
58+
&& !isShortValue
5859
) {
5960
// Skip symbols and objects for 'short' labels
6061
continue
@@ -65,8 +66,7 @@ export function createLabel (
6566
// Long verbosity treatment
6667
if (
6768
verbosity === 'long'
68-
&& typeof value !== 'string'
69-
&& typeof value !== 'number'
69+
&& !isShortValue
7070
) {
7171
refinedValue = typeof value
7272
} else if (verbosity === 'long-with-objects' && typeof value === 'object') {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
],
1313
"scripts": {
1414
"check": "svelte-check",
15-
"test": "vitest"
15+
"test": "vitest",
16+
"start-4": "cd e2e/svelte-4 && npm i && npm run dev"
1617
},
1718
"author": "Enrico Sacchetti <[email protected]>",
1819
"license": "MIT",

tests/cartesian.test.js

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ describe('createLabel', () => {
6767
obj: { hello: 'world' }
6868
}, { verbosity: 'long' }))
6969
.toBe('variant: primary\nsize: md\nobj: object')
70+
71+
expect(createLabel({ variant: 'primary', disabled: true }, { verbosity: 'long' }))
72+
.toBe('variant: primary\ndisabled: true')
7073
})
7174

7275
it('handles functions and symbols (short)', () => {

0 commit comments

Comments
 (0)