Skip to content

Commit

Permalink
fix: adjust labels
Browse files Browse the repository at this point in the history
Display boolean values in labels when using `long` verbosity.
  • Loading branch information
theetrain committed Jul 23, 2024
1 parent 87ab626 commit a13fc4e
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 7 deletions.
1 change: 0 additions & 1 deletion e2e/svelte-4/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions lib/cartesian.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,17 @@ export function createLabel (
innerProps,
{ verbosity } = { verbosity: 'short' }
) {
const shortValues = ['string', 'number', 'boolean']
const label = []
const shortVerbosity = verbosity === 'short' || verbosity === true
const joinCharacter = shortVerbosity ? ', ' : '\n'

for (const [key, value] of Object.entries(innerProps)) {
const isShortValue = shortValues.includes(typeof value)

if (
shortVerbosity
&& typeof value !== 'string'
&& typeof value !== 'number'
&& typeof value !== 'boolean'
&& !isShortValue
) {
// Skip symbols and objects for 'short' labels
continue
Expand All @@ -65,8 +66,7 @@ export function createLabel (
// Long verbosity treatment
if (
verbosity === 'long'
&& typeof value !== 'string'
&& typeof value !== 'number'
&& !isShortValue
) {
refinedValue = typeof value
} else if (verbosity === 'long-with-objects' && typeof value === 'object') {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
],
"scripts": {
"check": "svelte-check",
"test": "vitest"
"test": "vitest",
"start-4": "cd e2e/svelte-4 && npm i && npm run dev"
},
"author": "Enrico Sacchetti <[email protected]>",
"license": "MIT",
Expand Down
3 changes: 3 additions & 0 deletions tests/cartesian.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ describe('createLabel', () => {
obj: { hello: 'world' }
}, { verbosity: 'long' }))
.toBe('variant: primary\nsize: md\nobj: object')

expect(createLabel({ variant: 'primary', disabled: true }, { verbosity: 'long' }))
.toBe('variant: primary\ndisabled: true')
})

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

0 comments on commit a13fc4e

Please sign in to comment.