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

my-easy-fp

v0.22.0

Published

Simple functional programming utility & Misc programming tool

Downloads

222,125

Readme

Simple functional programming utility & programming helper tools

Download Status Github Star Github Issues NPM version License

Simple utility functions that can use browser, node.

Function list

boolean

| name | description | | ------- | ------------------------------ | | isFalse | If argument false, return true | | isTrue | If argument true, return true | | invert | return inverted boolean value |

array

| name | description | | -------- | --------------------------------------------------------------------------------- | | populate | populate array zero base, if you pass second argument true that populate one base | | chunk | array split given size | | last | pick last element from array | | first | pick first element from array | | toArray | make array given argument | | settify | make it set and convert it back to array |

empty

| name | description | | ----------------- | ----------------------------------------------------------------------------------------------------- | | isUndefined | if argument undefiend, return true | | isNotUndefined | if argument not undefined, return true | | isNull | if argument null, return true | | isNotNull | if argument not null, return true | | isNotEmpty | if argument not null and undefined, return true | | isEmpty | if argument null or undefined, return true | | isComplexEmpty | if argument not undefined and null, do additional test isNaN, empty string, empty array, empty object | | isNotComplexEmpty | return inverted value isComplexEmpty |

misc

| name | description | | ----------------- | ----------------------------------------------------- | | typedkey | same work Object.keys, but typed key in Recoed | | getRandomRange | return random value in min and max | | getRandomRangeInt | return random integer value in min and max | | isError | if argument is Error return Error or return undefined |

sleep

| name | description | | ----- | ----------------------- | | sleep | sleep given millisecond |

Custom Utility Types

| name | description | | ------------------ | -------------------------------------- | | TResolvePromise | get type resolved promise | | TResolveArray | get type resolve array | | TNullablePick | convert specific field to nullable | | TNonNullableObject | object type each field to non nullable | | TNonNullablePick | convert specific field to non nullable |

False & True checker

Why need this utility?

import { isFalse } from 'my-easy-fp';

const iamboolean = false;

// this line easily miss in refactoring or changing
if (!iamboolean) {
  console.log('I am execute false-case');
}

// more than better!
if (isFalse(iamboolean)) {
  console.log('I am execute false-case');
}

Empty checker

Why need this utility?

const iamempty?: string | null = undefined;

// this line some boring task
if (iamempty === undefined || iamempty === null || iamempty !== '') {
  console.log('i am empty');
}

// more than better!
if (isComplexEmpty(iamempty)) {
  console.log('i am empty');
}

You need only undefined and null check, use double equal operator.

const iamempty?: string | null = undefined;

// Recently ESLint allow double equal for null check
// see https://eslint.org/docs/latest/rules/eqeqeq#allow-null
if (iamempty == null) {
  console.log('i am empty');
}

Sleep

Why need this utility?

const ms = 1000;

// this line some boring task
await new Promise((resolve) => setTimeout(() => resolve(), ms));

// more than better!
await sleep(ms);

Array

populate, chunk utility here.

// seq is [0,1,2,3,4,5,6,7,8,9]
const seq = populate(10);

// seq is [1,2,3,4,5,6,7,8,9,10]
const seq = populate(10, true);

// chunked is [[1,2],[3,4],[5,6],[7]]
const chunked = chunk([1, 2, 3, 4, 5, 6, 7], 2);

// settify is [ 1, 2, 3, 4 ]
const settified = settify([1, 1, 2, 3, 2, 3, 4]);

// zeroIndex is 1
const zeroIndex = atOrThrow([1, 2, 3], 0);

Type Helper

resolve promise, array. But you can use type-fest or ts-essentials. Recommand use type-fest and tsessentials.

// you can get string | Buffer type
type TResolvedPromiseType = TResolvePromise<ReturnType<typeof fs.promises.readFile>>;

// you can get number type
type TResolvedArrayType = TResolveArray<number[]>;

interface IStudent {
  name: string;
  major: string;
  grade: number;
}

// you can get { name?: string; major?: string; grade: number; }
// converted Omit<IStudent, 'name' | 'major'> & Pick<Partial<IStudent>, 'name' | 'major'>
type TCliArgumentStudent = TNullablePick<IStudent, 'name' | 'major'>;