@zajno/common
v2.3.7
Published
Zajno's re-usable utilities for JS/TS projects
Downloads
1,748
Readme
Zajno's Toolbox
This is a library with a useful utils/helpers to share across our projects.
Doesn't pretend to be useful in outer world because probably everything is invented, tested and released to NPM already.
The motivation to have this – just to control and organize some shared code that we ever wanted to write by ourselves.
Logger interface & console implementation – create instance of logger, inject your own implementation or globally enable/disable logger instances by callling
setMode
Cache, EnumHelper, Event, Lazy, Pool, Throttle, Disposer
...and other more or less noteworthy stuff.
The source code is written in TypeScript, and intended to be used in TS project, so no built JS sources included.
Usage
It can be used a git submodule if you're brave enough, but it's possible to use it as npm package (kinda) as well. In your project:
- Install from NPM:
npm i @zajno/common
tslib
is the only peer dependency.
- In your code, use each module separately:
import logger, { ILogger } from '@zajno/common/logger';
Note on imports in v1
Previously one had to import from like @zajno/common/lib/logger
since compiling had been doing at postinstall
time so Typescript with its config was a peer dependency. Currently it's not the case and this packages is provided with build artifacts (js + d.ts + source maps); so no need to include /lib
part in imports anymore.
Although install time has been decreased, the main downside is that sources are built being targeted on CommonJS & ES2019+ (for now!). This might be not always suitable and/or optimal for all build setups.
Local development
If you plan to update the sources while using it in your project, we'd recommend using yalc
. It does some magic to allow both using it in your project and updating it.
The flow will look like the following. [1] – operations made on this project, [2] – operations made on dependant project.
- install
yalc
globally [1]
fork (if you're outside Zajno) and clone this project, donpm i
[1]
runyalc publish --private
[2]
runyalc add @zajno/common && npm i
[1]
make changes in local copy, run tests etc.[1]
run some magic:npm run push:local
– this should deliver your updated copy to local project(s) [2][2]
notice the changes in your project, repeat 5-7 until you're done[2]
to cleanup, runyalc remove @zajno/common
or justyalc remove --all
[1]
push your changes after making sure it's OK, we'd say thank you for a PR![2]
re-add the package into your project or specify tag/commit (e.g.npm upgrade @zajno/common
)