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

@dengfengwang/utils

v0.0.25

Published

Some commonly used utils.

Downloads

51

Readme

Some convenience utils.

Installation

npm install --save @dengfengwang/utils

or

yarn add @dengfengwang/utils

Usage

You can import(or require) @dengfengwang/utils by getting it from npm

import { $number } from '@dengfengwang/utils';

const { toFixed } = $number;

console.log(toFixed(1.123, 2))

Table of contents

API

$array

.reverse

Reverses an array in place.

Params

  • arr {Array}: The array to reverse.
  • start {Number}: Starting index.
  • end {Number}: Ending index.

Example

import { $array } from '@dengfengwang/utils';
const { reverse } = $array;

const arr = [1, 2, 3];
reverse(arr, 0, arr.length - 1);
console.log(arr);
//=> [3,2,1]

$boolean

.random

Get a random boolean (true/false).

Params

  • returns {Boolean}: A boolean (true or false).

Example

import { $boolean } from '@dengfengwang/utils';
const { random } = $boolean;

console.log(random());
//=> true/false

$date

.isWeekday

Check if the provided day is a weekday.

Params

  • date {Date}: Provided Date.
  • returns {Boolean}: Either a weekday or not(a weekend day).

Example

import { $date } from '@dengfengwang/utils';
const { isWeekday } = $date;

console.log(isWeekday(new Date('2021-05-17T00:00:00')));
//=> true

$math

.average

Get average value of arguments.

Params

  • ...args {Arguments}: Some number arguments.
  • returns {Number}: Average value of the arguments.

Example

import { $math } from '@dengfengwang/utils';
const { average } = $math;

console.log(average(1,2,3));
//=> 2

$number

.isEven

Check if a number is even or odd.

Params

  • num {Number}: Arbitrary integer.
  • returns {Boolean}: Even or not(odd).

Example

import { $number } from '@dengfengwang/utils';
const { isEven } = $number;

console.log(isEven(2));
//=> true
console.log(isEven(3));
//=> false

.toFixed

Truncate a number to a fixed decimal point.

Params

  • num {Number}: The needed formatted number.
  • digits {Number}: The number of digits to appear after the decimal point.
  • returns {Boolean}: The given number using fixed-point notation.

Example

import { $number } from '@dengfengwang/utils';
const { toFixed } = $number;

console.log(toFixed(2.123, 2));
//=> 2.12

$string

.reverse

Reverse the characters in a string.

Params

  • str {String}: The string to reverse.
  • returns {String} The reversed string.

Example

import { $string } from '@dengfengwang/utils';
const { reverse } = $string;

console.log(reverse("abc"));
//=> 'cba'

License

Software License

Copyright (c) 2021-present, Weiwei Wang