Format.js 822 B

123456789101112131415161718192021222324252627282930313233343536
  1. export default class Format{
  2. static currency(num){
  3. return "$" + num.toFixed(2);
  4. }
  5. static transactionDate(date){
  6. let year = date.getFullYear();
  7. let month = date.getMonth() + 1;
  8. let day = date.getDate();
  9. return `${year}-${month}-${day}`;
  10. }
  11. static dateFromTransaction(d, dayOfWeek = false){
  12. const date = new Date(d);
  13. let options = {
  14. year: "numeric",
  15. month: "long",
  16. day: "numeric",
  17. weekday: dayOfWeek ? "long" : undefined
  18. };
  19. return date.toLocaleDateString("en-US", options);
  20. }
  21. static dollarsToCents(num){
  22. if(typeof num === "string") num = Number(num);
  23. return Math.round(num * 100);
  24. }
  25. static centsToDollars(num){
  26. return num / 100;
  27. }
  28. }