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

why-not-utils

v0.1.0

Published

A utility library designed to reduce redundant code and improve development efficiency by providing a set of reusable methods. Beyond array manipulation, this package includes utilities for math operations, date handling, string manipulation, and more. St

Downloads

5

Readme

Why Not

Why Not is a utility library designed to streamline development by providing a collection of reusable methods. It helps reduce redundant code and enhance code readability. This library offers utilities not only for array manipulation but also for operations involving math, dates, strings, and more.

Features

  • Array Utilities: Methods for unique values, filtering, mapping, grouping, and more.
  • Math Utilities: Functions to simplify common mathematical operations.
  • Date Utilities: Helpful functions for date manipulation and formatting.
  • String Utilities: Methods for string manipulation and formatting (Coming Soon).

Installation

You can install Why Not via npm (not available yet):

npm install why-not

Usage

Here are some examples of how to use Why Not:

Array Utilities

import { toUnique, filterBy, mapBy, groupBy, compact } from 'why-not';

const numbers = [1, 2, 2, 3, 1];
const uniqueNumbers = toUnique(numbers); // [1, 2, 3]

const filtered = filterBy(numbers, (n) => n > 1); // [2, 2, 3]
const doubled = mapBy(numbers, (n) => n * 2); // [2, 4, 4, 6, 2]

const objects = [{ id: 1 }, { id: 2 }, { id: 2 }, { id: 3 }, { id: 1 }];
const grouped = groupBy(objects, 'id'); // { '1': [{ id: 1 }, { id: 1 }], '2': [{ id: 2 }, { id: 2 }], '3': [{ id: 3 }] }

const compacted = compact([1, 0, 2, false, 3, null, undefined, '']); // [1, 2, 3]

Math Utilities

import {
  gcd,
  lcm,
  isPrime,
  factorial,
  fibonacci,
  mean,
  median,
  mode,
  standardDeviation,
  range,
  roundTo,
  MathMutator,
} from 'why-not';

const a = 12;
const b = 15;

console.log(gcd(a, b)); // 3
console.log(lcm(a, b)); // 60
console.log(isPrime(17)); // true
console.log(factorial(5)); // 120
console.log(fibonacci(7)); // 13

const array = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4];

console.log(mean(array)); // 3
console.log(median(array)); // 3
console.log(mode(array)); // [4]
console.log(standardDeviation(array)); // 1.0954
console.log(range(array)); // 3
console.log(roundTo(1.23456789, 4)); // 1.2346

const mathMutator = new MathMutator(array);
console.log(mathMutator.mean()); // 3
console.log(mathMutator.median()); // 3
console.log(mathMutator.mode()); // [4]
console.log(mathMutator.standardDeviation()); // 1.0954
console.log(mathMutator.range()); // 3
console.log(mathMutator.roundTo(1.23456789, 4)); // 1.2346

Date Utilities

import { DateFormatter } from 'why-not';
const formattedDate = DateFormatter(dateStr, { format: 'dd/MM/yyyy' });
console.log(formattedDate); // 30/07/2023

Refer to the docs for more information.

API

For detailed API documentation, refer to the docs.

Contributing

Contributions are welcome! Please read the CONTRIBUTING.md for guidelines on how to contribute to this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

This project is maintained by Naveen.