@leonardorick/utils
v0.0.29
Published
Utils JS functions from Leonardo Rick
Downloads
21
Readme
utils
Javascript functions that are useful to be re-used
usage
`pnpm i @leonardorick/utils`
on plain javascript
import utils from './node_modules/@leonardorick/utils/index.js';
on a modern JS application working with bundlers
import utils from '@leoanrdorick/utils';
publish
pnpm version patch
pnpm run build
git commit -m "<message>"
git push
npm publish --access=public
add new functions
If you are going to add a new "module" (file) make sure to keep the same structure present on the project. The following three folders should have (almost) the same structure:
src/
Where the.js
file is located and the function is actually implemented. This function should be imported insidesrc/index.js
, which is the only file that is not repeated on the other folders. This file abastracts the complexity of the actualindex.js
outside thesrc
folder that import stuff from './dist' and we don't want to keep updating it everytime.Make sure to add some JSDocs one each function explaining it usage
tests/
Any function should have at least one test for it implementation. Preferably the module will have more than one test per function implement to contemplate multiple scenariostypes/
The signature of the exported classes/functions should be present ontypes/
as a.d.ts
file. This file should also be imported on thetypes/index.d.ts
so all types of the exported package members can be properly infered by IDE's
Try to make the functions inside each module ordered alphabetically as much as possible!
Code patterns
Optional parameters: Usually optional parameters are the last param of the function and are inside a object with default values.
funciton something(a, {
opt1 = true,
opt2 = null,
opt3 = 5,
} = {})
internal imports: If some module imports another one internally it needs to import it with the extension. This allows the builded version to work as expected
import { hypotenuse, round } from './math.js'; // right
//...
import { hypotenuse, round } from './math'; // wrong
Examples
You can go for any example index.html and open the file to check some useful examples of the usage of the package