Utility as a function

See Utils and Services about our standard concept.

But why not use import/export to include functions?

This would be of course the standard EcmaScript way. It's also completely fine to do so in your own projects. Just be consistent, unless there's a better reason not to be.

Note! However, this is usually not a consistent way to do it in Heusala Group projects.

In this case you would just create a file fooUtils.ts like:

export function strip (value: string) : string {
  return value.replace(/ +/, "");
}

...and use it simply:

import fooUtils from './fooUtils.ts';

console.log( fooUtils.strip('a b c') );

There are actually some benefits like the fact a correctly implemented ES import system can include only parts which you imported and let others uncompiled. However, with a correctly configured minimizing build system it should happen for unused parts of classes also.

The most likely problem with this style is that it relies on files to group functions together. The static class style can be compiled as a single file and debugged without loosing the context of grouped functions.