diff-for-humans.ts 605 B

1234567891011121314151617181920212223
  1. import { Pipe, PipeTransform } from "@angular/core";
  2. import TimeAgo from "javascript-time-ago";
  3. import en from "javascript-time-ago/locale/en";
  4. TimeAgo.locale(en);
  5. const timeAgo = new TimeAgo("en-US");
  6. /**
  7. * Generated class for the DiffForHumansPipe pipe.
  8. *
  9. * See https://angular.io/api/core/Pipe for more info on Angular Pipes.
  10. */
  11. @Pipe({
  12. name: "diffForHumans"
  13. })
  14. export class DiffForHumansPipe implements PipeTransform {
  15. /**
  16. * Takes a timestamp and makes the diff readable for humans.
  17. */
  18. transform(value: string, ...args) {
  19. return timeAgo.format(new Date(value), "twitter");
  20. }
  21. }