Convert number to string
See original GitHub issuecan you check if (typeof input === 'number') input = input.toString();
?
e.g. getSlug(44)
should output '44'
but it outputs ''
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
JavaScript Number toString() Method - W3Schools
Convert a number to a string, using base 2 (binary):. let num = 15; let text = num. ... Definition and Usage. The...
Read more >Java Convert int to String - javatpoint
The Integer.toString() method converts int to String. The toString() is the static method of Integer class. The signature of toString() method is given...
Read more >JavaScript Number to String – How to Use toString to Convert ...
The toString() method is a built-in method of the JavaScript Number object that allows you to convert any number type value into its...
Read more >Converting Number to String in C++ - GeeksforGeeks
In this method, a string stream declares a stream object which first inserts a number, as a stream into an object and then...
Read more >Converting Between Numbers and Strings
Converting Numbers to Strings · int i; // Concatenate "i" with an empty string; conversion is handled for you. · // The valueOf...
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 FreeTop 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
Top GitHub Comments
Yeah, this is 2 extra lines of code. Then someone will came here and ask to add another two lines for another data type. In the end, there will be big condition handling all those types.
What I suggest is to keep it in this way as it is now and move that responsibility outside of this library. In API docs is written that
getSlug
expects string. You need to handle that in your code.If you need to pass number in there, you can introduce your own wrapper on top of the
getSlug
for example or calltoString()
before passing togetSlug
.I’m 👎 on this feature since it will solve your problem, but it will add some complexity not used in 99% usage.
But, this ticket opens another question, should getSlug return/throw an error if
input
is not a string or returnfalse
? To return an empty string feels not the best… what you are thinking about? Should we change this?