question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Convert number to string

See original GitHub issue

can you check if (typeof input === 'number') input = input.toString();?

e.g. getSlug(44) should output '44' but it outputs ''

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
simicommented, May 30, 2016

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 call toString() before passing to getSlug.

I’m 👎 on this feature since it will solve your problem, but it will add some complexity not used in 99% usage.

1reaction
pidcommented, Jul 12, 2016

But, this ticket opens another question, should getSlug return/throw an error if input is not a string or return false? To return an empty string feels not the best… what you are thinking about? Should we change this?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found