Namespaces would be my preference. However, if you are using modules (ES6, AMD, CommonJS, etc.), there is a third, and preferred option, would be to simply export the functions by themselves.
const PI: number = 3.14;
export function calculateCircumference(diameter: number): number {
return diameter * PI;
}
export function calculateRectangle(width: number, length: number): number {
return width * length;
}
With modules the file itself forms a name boundary or "namespace" if you will. (In fact, the keyword namespace is an alias for module in TypeScript.) Writing your code in this manner has some added benefits later on if you use something like tree shaking to eliminate unused code in a package.
You can then import your functions in other files like this:
// If you want to use the prefix
import * as MyMath from './my-math';
// Or without the prefix
import {
calculateCircumference,
calculateRectangle
} from './my-math';
Namespaces are useful if you need to split code across files and want to merge properties under a single parent object. But they are unnecessary is you are using modules already.