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

nukit

v1.8.0

Published

Tiny collection of essential JavaScript utilities

Downloads

6

Readme

nukit

Tiny collection of essential JavaScript utilities.

Usage

Install:

npm i nukit

Import:

import { isNumber, oneOf, pick } from 'nukit';

if (oneOf([null, 'foo', 42], isNumber)) {
  console.log('There is a number!');
}

const value = pick(['apple', 'banana', 'carrot']);

Why?

  • TypeScript: nice types support
  • Small & Simple: 37 essential functions in about 5 KBs of code
  • Modern: doesn't rewrites ESNext features that already exists

Contents

Filters

  • isUndefined — returns true if value is undefined
  • isNull — returns true if value is null
  • isBoolean — returns true if value is a boolean
  • isNumber — returns true if value is a number
  • isString — returns true if value is a string
  • isPrimitive — returns true if value is a primitive, i.e. undefined, null, boolean, number or string
  • isArray — returns true if value is array of any items
  • isObject — returns true if value is an object but not null nor array
  • isEmpty — returns true if value is empty, i.e. undefined, null, empty string, empty array or empty object (i.e. object without own properties)
  • allOf — returns true if all values in array meets filter condition
  • oneOf — returns true if at least one of values in array meets filter condition
  • equally — returns true if all of predicates are true
  • neither — returns true if at least one of predicates is true
    • or — alias
  • toUnique — creates a predicate function for standard Array.prototype.filter to filter unique values

Mappers

  • toBoolean — maps value into a boolean if possible
  • toNumber — maps value into a number if possible
  • toString — maps value into a string
  • filterObject — filters object entries by predicate like standard array's filter
  • mapObject — maps object entries by callback function like standard array's map
  • repeat — repeats some action for a specified number of times
  • byKeys — creates a comparator function for standard array's sort method to sort elements by keys provided in a custom order

Random

  • bool — returns random boolean value
  • int — returns random integer number value
  • float — returns random float number value
  • char — returns random character value
  • str — returns random string value
  • pick — returns random value from an array of one or more items
  • shuffle — returns shuffled copy of array
  • weighted — returns weighted random value from an array of values and weights

Seedable Random

Just like random utilities above, but with seeding support.

  • seedBool — creates seeded version of bool function
  • seedInt — creates seeded version of char function
  • seedFloat — creates seeded version of float function
  • seedChar — creates seeded version of char function
  • seedStr — creates seeded version of str function
  • seedPick — creates seeded version of pick function
  • seedShuffle — creates seeded version of shuffle function
  • seedWeighted — creates seeded version of weighted function

Date

  • ts — returns a Unix numeric timestamp for current or specified date
  • isValidDate — returns true if value is valid Date or suits for Date creation
  • diffDate — returns total amount of time between two dates (years, months, days, hours etc)

Error

  • when/drop — returns a function to drop an error when predicate is true

RegExp

  • r — creates a RegExp from a template string, gu flags are enabled
  • re — creates a RegExp from a string in a short way

Development

# run tests
npm run test

# get tests coverage report
npm run coverage

# build a package
npm run build

# publish a release
npm run release