Remove support for numbers
See original GitHub issueNumbers are currently allowed, but they yield unexpected results
> const classNames = require('classnames')
> classNames(0) // Falsy values are always filtered
''
> classNames(42) // Stringified integers aren’t valid class names
'42'
> classNames(3.14) // Stringified floats aren’t valid class names
'3.14'
> classNames(Infinity) // This is the only number which yields a valid class name
'Infinity'
> classNames(NaN) // Falsy values are always filtered
''
This may not be much of an issue, but the readme explicitly states this package is for joining class names. Numeric values aren’t valid class names, but they’re explicitly supported in the implementation.
According to the type definitions, numbers are supported.
Since breaking changes are on the way, I think it makes sense to remove support for numbers.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Add or remove rows and columns in Numbers on Mac
Click the table. In the Format sidebar, click the Table tab, then do any of the following: Add or delete headers and footers:...
Read more >Remove Fake Tech Support number from taskbar - TechNet
Right-click taskbar, mouse over toolbars and uncheck toolbar with telephone number. ... That does not remove it. I only turns it off so...
Read more >Best practices for adding or removing phone numbers on a ...
One or more numbers are duplicated in the REMOVE NUMBERS section; One or more numbers are duplicated in the ADD NUMBERS section; One...
Read more >How do I remove Team Number from my account?
Visit Sideline Settings · Tap Team Number · Remove team members from the account: iOS: Swipe left on the member name > tap...
Read more >How to remove a number from Shared Speed Dial | Ooma Office
How to remove a number from Shared Speed Dial · Log in to office.ooma.com as an administrator and navigate to the Settings page....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I agree it’s not recommended but it is valid and currently supported so its removal is a breaking change as @dcousens notes. My comment was noting that the claim “a number such as ‘42’ or ‘3.14’ is not a valid class name” is false. My working assumption is not “we should support all edge cases and must continue to do so” but “classnames currently support these edge cases and its maintainers need to consider if it worth making breaking changes to remove support”.
I agree that for the sake of simple APIs
number
should not be a valid type and thatclassnames(2)
should be unsupported and a type error and that users should writeclassnames('2')
instead as part of a v3 where breaking changes are allowed.I would also be tempted to remove
boolean
from the valid values too - and thus only allowing strings / undefined / null as a breaking changeThe CSS Spec says you can’t start a class name with a number. HOWEVER you can start it with a backslash-escaped identifier. So
.2 {}
is invalid, but.\32 {}
- the character sequence for ‘2’ is valid.You need a bit of trickery to define the class in css but the html
class="2"
is totally valid and references a valid css selector. See this codepen for some demos.Passing numbers into classNames feels strange, and personally I’d never do it but if supporting them isn’t any more complex than a toString() call then it feels like it’d be worth keeping support.