Is there a functional reason to prefer a Javascript class with only static methods or a file with functions?

Viewed 40

Let's say I've created a class with only static methods like below.

export class JWT {
  static getPayload(token: string): { [key: string]: any } {
    ...
  }

  static isExpired(token: string): boolean {
   ...
  }
}

I've seen libraries with classes like the above. But given all the class methods are static, there's no shared state amongst the functions. Why not instead create a file named jwt.ts with the same functions but no class?

export function getPayload(token: string): { [key: string]: any } {
    ...
  }

export function isExpired(token: string): boolean {
   ...
  }

I could call

import { JWT } from 'file1';
import { getPayload } from 'file2';
Option 1: JWT.getPayload()
Option 2: getPayload()

Is there a functional difference or is this primarily a stylistic difference?

0 Answers
Related