@lichens-innovation/ts-common
v1.15.4
Published
Reusable generic typescript utilities, types, constants, helpers
Readme
ts-common
Reusable generic typescript utilities, types, constants, helpers
Note: The default export is pure TypeScript and environment-agnostic—it has no dependency on Node.js, browser, or React Native APIs, so the same code runs in any of these runtimes. Subpath imports such as
@lichens-innovation/ts-common/webtarget a specific environment and rely on its APIs.
Table of content
- ts-common
Prerequisites
- Node.js (LTS or higher)
- Yarn
Scripts
| Command | Description |
|------------------------------|-----------------------------------------------------------------------------|
| yarn prepare | Configures Husky (Git hooks). Runs automatically after yarn install. |
| yarn build | Compiles the project with tsup (outputs to dist/). |
| yarn clean:node | Removes node_modules and yarn.lock. |
| yarn clean:dist | Removes the dist directory. |
| yarn typecheck | Type-checks TypeScript without emitting files (tsc --noEmit). |
| yarn lint | Runs ESLint on the project. |
| yarn lint:fix | Runs ESLint and applies automatic fixes. |
| yarn test | Runs tests with Vitest and coverage report. |
| yarn test:watch | Runs tests in watch mode with Vitest. |
| yarn test:coverage | Runs tests with coverage report using Vitest. |
Optional modules
This library provides optional subpath modules with external dependencies. Install only the dependencies you need. For more information regarding the packaging, see the following technical explanation.
Excel (@lichens-innovation/ts-common/excel)
npm install exceljs mimeCSV (@lichens-innovation/ts-common/csv)
npm install papaparse mimePDF (@lichens-innovation/ts-common/pdf)
npm install jspdf jspdf-autotableWeb (@lichens-innovation/ts-common/web)
No external dependency required.
MIME (@lichens-innovation/ts-common/mime)
npm install mimeLogger (@lichens-innovation/ts-common/logger)
Logger based on pino with formatted console output (timestamp, colored levels). Works in browser and Node.js.
- Browser: logs are formatted and sent to
consolewith colored level labels. - Node.js: logs are formatted with pino-pretty (colorized, readable output). Install
pino-prettywhen using the logger in Node.
Install the dependencies:
npm install pinoFor Node.js (required for pretty output):
npm install pino-prettyExports: logger, setLoggerMinimumLevel, type Level.
Usage example:
import { logger, setLoggerMinimumLevel, type Level } from "@lichens-innovation/ts-common/logger";
// Minimum level (optional): "trace" | "debug" | "info" | "warn" | "error" | "fatal"
setLoggerMinimumLevel("debug");
logger.info("Simple message");
logger.debug("Debug", { userId: "123", action: "login" });
logger.error("Error", { code: 500 });RJSF (@lichens-innovation/ts-common/rjsf)
Utilities and hooks for React JSON Schema Form (RJSF) with i18n (i18next / react-i18next), localized validation (ajv-i18n), and form layout. For React apps using RJSF with translation and validation.
Install the dependencies:
npm install @rjsf/core @rjsf/utils @rjsf/validator-ajv8 ajv-i18n i18next react-i18nextContributions
Contributions to the project are made by simply improving the current codebase and then creating a Pull Request. If the version field in package.json is incremented, the build will be automatically triggered when the PR is merged into the main branch, and the new version will be published to our enterprise Git repository.
Unit tests
Test coverage must be maintained at 80% or higher. It is therefore important to always attempt to cover new code that is added with appropriate tests.
Library semantic versioning
When there is a breaking change, Semantic Versioning must be used to indicate that a major behavior has changed. Semantic Versioning follows the MAJOR.MINOR.PATCH format:
MAJORversion when you make incompatible API changesMINORversion when you add functionality in a backward compatible mannerPATCHversion when you make backward compatible bug fixes
Project coding guidelines
Adhering to established coding guidelines is essential for developing efficient, maintainable, and scalable software. These guidelines promote consistency across codebases, making it easier for teams to collaborate and for new developers to understand existing code. By following standardized patterns, such as those outlined in the Coding guidelines, developers can reduce errors and enhance code readability.
TODOs
This section list remaining tasks (not yet completed)
- RJSF-001: find a way to dynamically resolve the rjsf-i18n.utils "%1 Key" pattern
License
This project is licensed under the MIT License - see the LICENSE file for details.
