INTRODUCTION
Epigraph Standard Library or epigraph-std-lib is a collection of standards that we follow across our solutions. The idea is to have a single source of truth across solutions while ensuring that the dependencies are always up to date with the industry standards.
EPIGRAPH
A global object that must only be initialized once per session and provides some common functionalities across solutions in that session.
EPIGRAPH LIBRARY EXPORTS
Name | Description |
---|---|
EpigraphBaseSolutionHtmlElement | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement |
EpigraphBaseSolutionLitElement | A base class intended to enforce some common functionalities across our solutions, built by extending the LitElement |
EpigraphLogger | A logger class that provides a convenient way for logging info, warning or errors in any given session |
EpigraphQrCoreGenerator | A Utility class that allows the generation of a QR code from a give string input |
EpigraphUnitsConverter | |
EpigraphUrlProcessor |
HOW TO:
Add a new EpigraphLibrary:
- Create a new directory under lib/EpigraphLibs/
<MyEpigraphLibrary>
- Create the module file/s. Ensure that the names of these files are in camelCase.
- Write a test for this Library under tests/<MyEpigraphLibrary.test.ts>
- Add the module that you wish to export as an entry in vite.config.ts > defineConfig > build > entry, similar to other entries in there. This will bundle the new module on build.
- Go to package.json:
- Add the new module entry under exports similar to other entries in that field.
- Add the new module entry under typesVersions similar to other entries in that field.
Use the library
This library exports the module into submodules to allow for better tree shaking when bundling the final product. Here is how you can import the submodules individually.
// Epigraph Object
import { Epigraph } from "@epigraph/epigraph-std-lib/dist/Epigraph/epigraph";
// Epigraph libs
import { EpigraphAnalytics } from "@epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics";
Exported Submodules: | Name | Description | |---|---| | @epigraph/epigraph-std-lib/dist/Epigraph/epigraph | A base class intended to enforce some common functionalities across our solutions, built by extending the HTMLElement | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphAnalytics | An Analytics modules that exports handy ways to log analytics across our solutions | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphLogger | A Logger modules that exports handy ways to log across our solutions | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphNexusApi | A Nexus API modules that exports handy ways to interact with the Nexus API across our solutions | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphQrCodeGenerator | A QR Code generator modules that exports handy ways to generate QR Codes across our solutions | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphResultFactory | A Result Factory modules that exports handy ways to generate Result objects across our solutions | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUnitsConverter | A Utility class that allows conversion between different standard unit, including but not limited to Distance, Color, etc. | | @epigraph/epigraph-std-lib/dist/EpigraphLibs/epigraphUrlProcessor | A Utility class that provides various methods to generate, process, manipulate URLs |
Write a test:
We use vitest to write tests in this repository using happy-dom to support some but not all browser functionalities. In order to write a new test:
- Create a new file for a specific test under tests/ as
<MyEpigraphLibrary>
.test.ts - Write a test following the instructions and samples here
- Make sure to import the library from "../dist/epigraph-std-lib" to avoid any issues that might come up after bundling.
- Open a terminal and execute "npm run test". This will build all the libraries under dist/ and then run tests using those.
REFERENCES
A huge thanks to everyone who inspired the setup for this repository: