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

utils-hb

v1.1.1

Published

utils collection for hb frontend projects

Downloads

6

Readme

utils-hb

utils collection for projects

Usage

Install

npm install utils-hb
# or
yarn add utils-hb

Import Module

// import all utils
import utils from "utils-hb";

utils.format.getSign(1); // return "+1"

// import single module
import { format } from "utils-hb";
format.getSign(1); // return "+1"

// import ES6 source module
import format from "utils-hb/format";

// import single method from ES6 source module
import { getSign } from "utils-hb/format";
getSign(1); // return "+1"

// import UMD module
import format from "utils-hb/dist/format";

- format

formatTimeDiff(dateTime)

  • @method formatTimeDiff
  • @param dateTime {String | Number | Date}
  • @return {String}
format.formatTimeDiff(Date.now() - 2000); // return "2秒前"
format.formatTimeDiff(Date.now() - 2000 * 60); // return "2分钟前"
format.formatTimeDiff(Date.now() - 2000 * 60 * 60); // return "2小时前"
format.formatTimeDiff(Date.now() - 2000 * 60 * 60 * 24); // return "2天前"

getSign(number)

  • @method getSign
  • @param number {String | Number}
  • @return {String | Number}
format.getSign(1); // return "+1"
format.getSign(0); // return 0
format.getSign(-1); // return -1

getSignColor(number)

  • @method getSignColor
  • @param number {String | Number}
  • @return {String}
format.getSignColor(1); // return "color-red"
format.getSign(0); // return "color-gray"
format.getSign(-1); // return "color-green"

highlightText(source, keywords = [])

  • @method highlightText
  • @param source {String | Number}
  • @param keywords {String | Array}
  • @return {String}
format.highlightText("Good Boy", "Boy"); // return 'Good <span class="highlight">Boy</span>'

numberUnitFormat(num, precision = 2)

  • @method numberUnitFormat
  • @param num {Number}
  • @param precision {Integer}
  • @return {String}
format.numberUnitFormat(100000); // return "10.00万";
format.numberUnitFormat(100000000); // return "1.00亿";

thousandsSeparatorFormat(number)

  • @method thousandsSeparatorFormat
  • @param number {Number}
  • @return {String}
format.thousandsSeparatorFormat(-1234567.89); // return "-1,234,567.89";

- queue

debounce(func, wait, immediate)

  • @method debounce
  • @param {Function} func
  • @param {Integer} wait debounce wait time in milliseconds
  • @param {Boolean} immediate
  • @returns {Function} new Function
queue.debounce(() => {}, 300);

- safe

xssFilter(source)

  • @method xssFilter
  • @param {String} source source content
  • @returns {String} html safe content
safe.xssFilter("<script></script>"); // return "&lt;script&gt;&lt;/script&gt;"

- transform

data2Set(data)

  • @method data2Set
  • @param {Any} data
  • @return {Set | Any} Set object or source data\
transform.data2Set(1); // Set(1) {1}
transform.data2Set([1,2,3]); // Set(3) {1,2,3}

getQueryString(queryString, searchString)

  • @method getQueryString
  • @param queryString {String}
  • @param searchString {String}
  • @return {String}
transform.getQueryString("a", "url?a=1&c=2"); // return "1"