Common utils and helpers used on node, Js and Ts projects
npm install @acelords/js-utilsnull, undefined and 0 differently null is rendered as "null" in this template {functionThatReturnsNull(null)} and as such would be such a hasle writing multiple #if for checking null (or even {functionThatReturnsNull(null) ?? ""}). It would be nice to just have {functionThatReturnsNullAsString(undefined)} for improved DX don't you agree?Most functions are meant to be uses only in the Presentation layer. Use them sparingly in the Business logic layer.
#### Sample results from the docs on hover
!Screenshot 1
#### Tests for quick reference
!Screenshot 2
npm``bash
npm i @acelords/js-utils
pnpm i @acelords/js-utils
`
Clicked {formatNumber(978345, true)} times.
Clicked 978,345 times.
Clicked {formatNumber(null|undefined|"", true)} times.
Clicked times.
Clicked {formatNumber(null|undefined|"" ?? 0, true)} times.
Clicked 0 times.
Clicked {formatNumber(null|undefined|"" ?? "0", true)} times.
Clicked 0 times.
Clicked {formatNumber(null|undefined|"" ?? "1000", true)} times.
Clicked 1,000 times.
Clicked {formatNumber("abc", true)} times.
Clicked times.
- Format currency saved in cents (as you should) in human-readable way (
Int|BigInt|Float also supported):
Costs ${formatCurrency(132949)} only.
Costs $1,329.49 only.
Costs ${formatCurrency(null|undefined|"")} only.
Costs $ only.
Costs ${formatCurrency(null|undefined|"" ?? "0")} only.
Costs $0.00 only.
Costs ${formatCurrency(null|undefined|"" ?? 0)} only.
Costs $0.00 only.
Costs ${formatCurrency(null|undefined|"" ?? 1099)} only.
Costs $10.99 only.
Costs ${formatCurrency("abc")} only.
Costs only.
- Count apples sold by the doctor:
You have sold {formatNumber(3454, true)} {pluralize('apples', applesCount)} today.
You have sold 3,454 apples today.
You have sold 1 apple today.
You have sold 0 apples today.
Dev Notes
$3
`bash
npm t
`$3
Before publishing, remember to INCREMENT Versioning (in package.json) and also BUILD it`bash
npm run build && npm publish --access public
``