-
Notifications
You must be signed in to change notification settings - Fork 0
Code structure
The source code for the library is found in the ./src/ directory. It is split into subdirectories based on the type of the code.
In each directory, there should be an index.ts file. This file shouldn't contain any logic, it should only handle exports and renaming from the directory. This means that no other directory should import anything beyond the directory's index.ts file. More information about importing can be found in the Module structure page.
Constants are located in the ./src/constants/ directory. Constants are values of any type that remain constant throughout the runtime of the program. They are split into files based on the type of the constant. For example, all constants of type number are located in the ./src/constants/numbers.ts file.
As constant objects need to import their constructors, it is important to think of circular imports. If the object needs a constant of the same type, this constant should be created in the same file as the constructor and be reexported inside the constants file. If the constant isn't needed in the constructor, it should be defined in the constants file.
The library adheres to the JavaScript standard of throwing errors. All code related to errors is located in the ./src/errors/ directory. More information about errors can be found in the Errors page.
The ./src/geometryObjects/ directory contains the classes for all our objects. The classes are split into files based on the type of the object. More information about Geometry objects can be found in the Geometry objects page.
The ./src/helpers/ directory contains helper functions. These are standalone functions that can be used in multiple places. Any wrappers around external code should be placed here. More information about helpers can be found in the Helpers page.
The ./src/interfaces/ directory contains all interfaces. Interfaces are used to define the structure of objects. More information about interfaces can be found in the Interfaces page.
The ./src/procedures/ directory contains procedures. Procedures are pure functions with some predefined argument structures. They are usually used to describe a mathematical procedure. More information about procedures can be found in the Procedures page.
In the root of the ./src/ directory, there are files that don't fit into a category but are directly exported from the library.
The ./src/factories.ts file contains factory functions. The library doesn't use many standalone factory functions (they are usually a part of a class). The few that are used are located here. All of them are directly exported from the library.
The ./src/validators.ts file contains validator functions (type predicates and assertion functions). These functions can be used to narrow down the type of an object. They are all fully typed, and when used with TypeScript, the compiler can infer the type of the object after the validation. All of them are directly exported from the library.