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

jittoku

v0.1.14

Published

tiny typed utility library

Downloads

21

Readme

jittoku

Tiny TypeScript utility

Install

npm install jittoku

Usage

values(object)

returns an array of object values

const obj = { a: 1, b: 2, c: 3 };
const result = values(obj); // ['1', '2', '3']

keys(object)

returns an array of object keys

const obj = { a: 1, b: 2, c: 3 };
const result = keys(obj); // ['a', 'b', 'c']

isObject(value)

checks if the given value is an object

const result1 = isObject({}); // true
const result2 = isObject([]); // true
const result3 = isObject(null); // false

isNullish(value)

checks if the given value is null or undefined

const result1 = isNullish(null); // true
const result2 = isNullish(undefined); // true
const result3 = isNullish(0); // false

oLength(object)

returns the number of keys in an object

const obj = { a: 1, b: 2, c: 3 };
const result = oLength(obj); // 3

oForEach(object, function)

executes a function for each entry in an object

const obj = { a: 1, b: 2, c: 3 };
oForEach(obj, ([key, value], index) => {
  console.log(`Key: ${key}, Value: ${value}`);
});

oForEachK(object, function)

executes a function for each key in an object

const obj = { a: 1, b: 2, c: 3 };
oForEachK(obj, (key, index) => {
  console.log(`Key: ${key}`);
});

oForEachV(object, function)

executes a function for each value in an object

const obj = { a: 1, b: 2, c: 3 };
oForEachV(obj, (value, index) => {
  console.log(`Value: ${value}`);
});

oMap(object, function)

applies a function to each entry in an object and returns an array of the results

const obj = { a: 1, b: 2, c: 3 };
const result = oMap(obj, ([key, value], index) => key + value); // ['a1', 'b2', 'c3']

oReduce(object, function, initialValue)

executes a cumulative function for each entry in an object and returns the result

const obj = { a: 1, b: 2, c: 3 };
const result = oReduce(obj, (acc, [key, value], index) => acc + value, 0); // 6

oMapO(object, function)

applies a function to each entry in an object and returns a new object

const obj = { a: 1, b: 2, c: 3 };
const result = oMapO(obj, ([key, value], index) => [key + 'x', value * 2]); // { ax: 2, bx: 4, cx: 6 }

aToO(array, function)

applies a function to each element in an array and returns an object

const array = ['a', 'b', 'c'];
const result = aToO(array, (item, index) => [item, index + 1]); // { a: 1, b: 2, c: 3 }

partition(array, function)

splits the elements of an array based on a condition

const array = [1, 2, 3, 4, 5];
const result = partition(array, (cur, index) => cur % 2 === 0); // [[2, 4], [1, 3, 5]]

shake(object)

removes null or undefined values from an object

const obj = { a: 1, b: null, c: undefined, d: 4 };
const result = shake(obj); // { a: 1, d: 4 }

range(number)

returns an array of integers within a specified range

const result = range(5); // [0, 1, 2, 3, 4]

times(iterations, function)

executes a function a specified number of times

times(3, index => {
  console.log(`Iteration ${index + 1}`);
});

unique(array)

returns a new array with duplicate elements removed

const array = [1, 2, 2, 3, 3, 4, 5];
const result = unique(array); // [1, 2, 3, 4, 5]

arrayed(value)

converts a value to an array, or returns the value if it's already an array

const result1 = arrayed(1); // [1]
const result2 = arrayed([1, 2, 3]); // [1, 2, 3]

firstEntry(object)

returns the first entry of an object

const obj = { a: 1, b: 2, c: 3 };
const result = firstEntry(obj); // ['a', 1]

pick(object, function)

selects entries from an object based on a specified condition

const obj = { a: 1, b: 'two', c: true };
const picker = (key: unknown, value: unknown) : value is number => typeof value === 'number'
const result = pick(obj, picker); // { a: 1 }

random(min: number, max: number)

returns a random floating-point number within a specified range

const result = random(10, 20); // random floating-point number between 10 and 20

clamp(x: number, min: number, max: number)

returns min if x is less than min, max if x is greater than max, and x itself if it is within the range.

const result1 = clamp(-5, 0, 10); // 0
const result2 = clamp(5, 0, 10);  // 5
const result3 = clamp(15, 0, 10); // 10