1.1.6 • Published 3 months ago

@acelords/js-utils v1.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

AceLords Node Utils

Common utils for your node, Javascript, and Typescript projects.

Why this library?

This libray focuses more on presentation aspects, not to be used in business logic. Different frameworks/libraries render null, undefined and 0 differently

NB e.g. in svelte, 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

Installation

Install via npm

npm i @acelords/js-utils

pnpm i @acelords/js-utils

Docs

Available functions. View the entire list here

  • formatDate()
  • formatDateTime()
  • getTimeFromDate()
  • randomNumber()
  • randomString()
  • isNumeric()
  • fromNow()
  • substring()
  • numberFormat()
  • formatNumber()
  • formatCurrency()
  • slugify()
  • stripTags()
  • stripHtml()
  • plural()
  • singular()
  • pluralize()
  • insertIntoArray()
  • getMonthNameFromSqlMonthIndex()
  • isPhoneNumber()
  • isEmail()
  • isEmpty()
  • ucwords()
  • capitalize()
  • camelCase()
  • camelCaseToSentenceCase()
  • snakeCaseToSentenceCase()
  • kebabCaseToSentenceCase()
  • kebabCaseToPascalCase()
  • kebabCase()
  • scrollToTop()
  • countWords()
  • countWordsFromHtml()
  • birthdayFromNow()
  • isPhoneNumber()
  • getRandomElementsFromArray()

Sample Usages

  • Format a number value in human-readable way: <p>Clicked {formatNumber(978345, true)} times.</p> <p>Clicked 978,345 times.</p> <p>Clicked {formatNumber(null|undefined|"", true)} times.</p> <p>Clicked times.</p> <p>Clicked {formatNumber(null|undefined|"" ?? 0, true)} times.</p> <p>Clicked 0 times.</p> <p>Clicked {formatNumber(null|undefined|"" ?? "0", true)} times.</p> <p>Clicked 0 times.</p> <p>Clicked {formatNumber(null|undefined|"" ?? "1000", true)} times.</p> <p>Clicked 1,000 times.</p> <p>Clicked {formatNumber("abc", true)} times.</p> <p>Clicked times.</p>

  • Format currency saved in cents (as you should) in human-readable way (Int|BigInt|Float also supported): <p>Costs ${formatCurrency(132949)} only.</p> <p>Costs $1,329.49 only.</p> <p>Costs ${formatCurrency(null|undefined|"")} only.</p> <p>Costs $ only.</p> <p>Costs ${formatCurrency(null|undefined|"" ?? "0")} only.</p> <p>Costs $0.00 only.</p> <p>Costs ${formatCurrency(null|undefined|"" ?? 0)} only.</p> <p>Costs $0.00 only.</p> <p>Costs ${formatCurrency(null|undefined|"" ?? 1099)} only.</p> <p>Costs $10.99 only.</p> <p>Costs ${formatCurrency("abc")} only.</p> <p>Costs only.</p>

  • Count apples sold by the doctor: <p>You have sold {formatNumber(3454, true)} {pluralize('apples', applesCount)} today.</p> <p>You have sold 3,454 apples today.</p> <p>You have sold 1 apple today.</p> <p>You have sold 0 apples today.</p>

Dev Notes

Testing

npm t

Publish to NPM

Before publishing, remember to INCREMENT Versioning and also BUILD it

npm run build && npm publish --access public 
1.1.6

3 months ago

1.1.5

3 months ago

1.1.4

3 months ago

1.1.3

3 months ago

1.1.1

3 months ago

1.1.0

3 months ago

1.1.2

3 months ago

1.0.9

8 months ago

1.0.8

9 months ago

1.0.7

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago