Advertisement
Guest User

Untitled

a guest
Jan 24th, 2022
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. ## What is This?
  2. Allow users to input numbers/strings with commasRemove commas for string or numbers and check if the number/string contains commas
  3.  
  4. -Add commas
  5. -Remove commas
  6. -Check if string/num contains commas
  7.  
  8. ## Installation
  9.  
  10. `npm i no-comma`
  11.  
  12. Usage
  13. ```
  14. const noComma = require('no-comma')
  15.  
  16. const isComma = noComma.isComma
  17. const removeComma = noComma.removeComma
  18. const addComma = noComma.addComma
  19.  
  20.  
  21. const number = '5,000,000'
  22. const noNumber = '5000000'
  23.  
  24.  
  25. isComma(noNumber) // returns false
  26. isComma(number) // returns true
  27.  
  28. removeComma(number) // returns 5000000
  29. addComma(noNumber) // returns 5,000,000
  30. ```
  31.  
  32. Examples
  33. ```
  34. const noComma = require('no-comma')
  35.  
  36. const isComma = noComma.isComma
  37. const removeComma = noComma.removeComma
  38. const addComma = noComma.addComma
  39.  
  40.  
  41. // req.body.salary = 4,000,000
  42.  
  43. const salaryNoComma = removeComma(req.body.salary) // returns 4000000
  44.  
  45. //Adding the returned number with regular number
  46. const salaryAdding = (salaryNoComma + 12) // returns 4000012
  47.  
  48. console.log(addComma(salaryAdding)) // returns 4,000,012
  49. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement