The idea was to take all those small thing I'm always rewriting on every project and move them to a single package so I can, not only stop copying & pasting them all over the place, but also maintain them all together.
There are two rules I followed when I had to decide what to put and what to keep somewhere else:
- The utility needs to fit on a single file.
- It shouldn't include any specific business logic from any other project.
The package is divided on 3 folders:
node: Utilities that are only compatible with Node.
shared: Utilities that can work on both browser and Node.
browser: Utilities that can only be used while on a browser.
Two notes about the Node utilities:
- I'm a big fan of Jimple, so all the files not only export the utility but also a service provider or a "servicer provider generator" to register the utility on a Jimple app.
- Some of them may depend on the others.
This is a service to manage applications configurations. It takes care of loading, activating, switching and merging configuration files.
A really small service to centralize the place where you read environment variables and check if you are running on development or production.
Listens for uncaught exceptions and unhandled promises rejections, and logs them out with full detail.
The name leaves nothing to the imagination. As you may have guessed, this is service for logging messages into the console.
A tiny function that reads the contents of the app
package.json. This is really useful on an Jimple application where you can register it, because the returned value gets cached and it's available as a service.
An easy way to manage locations and build paths relative to those locations on a Node app.
require but the path is relative to the project root directory.
A really basic client to work with an API endpoints requests.
Deep merge (and copy) of objects(
Arrays using native spread syntax.
Create a deferred promise using the native
A small implementation of a pubsub service for handling events on an app.
A way to extend promise chains by injecting custom properties.
A set of utility functions to generate resources that can be used on Jimple or abstractions created from it (like Jimpex).
A small collection of utility methods to work with objects.
An abstract class allows you to build services that relay on browser storage (session/local) and simplifies the way you work it.
All files are written using commonjs, as I targeted the oldest Node LTS and it doesn't support modules (without a flag) yet, but you can use it with ESM.
When the package gets published, an ESM version is generated on the path
/esm. If you are using the latest version of Node, or a module bundler (like projext :D), instead of requiring from the package's root path, you should do it from the
/esm sub path:
// commonjs const ObjectUtils = require('wootils/shared/objectUtils'); // ESM import ObjectUtils from 'wootils/esm/shared/objectUtils';
Since the next LTS to become "the oldest" is 12, which still uses the flag, I still have no plans on going with ESM by default.
||Generates the project documentation.|
||Lints the staged files.|
||Lints the entire project code.|
||Runs the project unit tests.|
||Lists all the pending to-do's.|
husky to automatically install the repository hooks so...
- The code will be formatted and linted before any commit.
- The dependencies will be updated after every merge.
- The tests will run before pushing.
The configuration is on the
commitlint property of the
semantic-release and a GitHub action to automatically release on NPM everything that gets merged to main.
The configuration for
semantic-release is on
./releaserc and the workflow for the release is on
I use Jest to test the project.
The configuration file is on
./.jestrc.js, the tests are on
./tests and the script that runs it is on
Code linting and formatting
For linting, I use ESlint with my own custom configuration; there are two configuration files,
./.eslintrc for the source and the tooling, and
./tests/.eslintrc, and there's also a
./.eslintignore to exclude some files.
The script that runs them is
./utils/scripts/lint; the script
lint-all only runs ESLint, and runs it for the entire project.
I use JSDoc to generate an HTML documentation site for the project.
The configuration file is on
./.jsdoc.js and the script that runs it is on
@todo comments to write all the pending improvements and fixes, and Leasot to generate a report. The script that runs it is on
This project uses bash scripts for development, so if you want to develop on Windows, you need to do it with WSL.