npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@acelords/js-utils

v1.1.6

Published

Common utils and helpers used on node, Js and Ts projects

Downloads

82

Readme

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