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

jackknife

v4.0.0

Published

The useful compact tool.

Downloads

131

Readme

jackknife

npm npm bundle size license Issues


Description

jackknife is a multi-tool that provides a set of utility functions to face the wild projects.
All the blades are typescript compatible.


Installation

npm i jackknife

In order to use any API you have to import them:

// Typescript
import { clone, getPassword, sort } from 'jackknife';

// or Node
const { clone, getPassword, sort } = require('jackknife');

Browser support

Latest versions of Chrome, Firefox, Opera, Safari and Edge.


Test, Bugs and Feature requests

If you want to execute unit test run:

npm test

For bugs and feature requests, please create an issue.


API


chunks

chunks<T>(array: T[], chunkSize: number): T[][]

Split an array in a defined number of chunks.


shuffle

shuffle<T>(array: T[]): T[]

Shuffle an array.


sort

Sort an array of objects by an object property defined by the getField function.


unique

unique<T>(array: T[]): T[]

Remove the duplicated values from an array.


random

random(min: number, max: number, decimals = 0): number

Generate a random number (integer or float) in the defined range (inclusive).


round

round(value: number, decimals = 2): number

Round a number with the defined precision of decimals.


identifier

identifier(): number

Generate a numeric identifier useful as an ID value.


range

range(min: number, max: number): number[]

Generate an array of numbers in a defined range.


degToRad

degToRad(degrees: number): number

Convert degrees to radians.


radToDeg

radToDeg(radians: number): number

Convert radians to degrees.


datetime

datetime(date: Date | string | number, withTime = true): string

Get a human-readable format of a date value.


bytes

bytes(value: number, decimals = 2): string

Get a human-readable format of a bytes value.


code

code(length = 10, chars = 'all'): string

Generate a random string.
chars is the set of characters to use. It can be a predefined set between 'alphanumeric', 'letters', 'lower-letters', 'upper-letters', 'numbers', 'symbols', 'all' or a custom set.


color

color(): string

Generate a random color in hexadecimal notation.


pad

pad(value: number | string, length: number, symbol: string): string

Add a start padding to a value.


nested

nested<T>(root: Record<any, unknown>, path: string): T | undefined

Get the nested value of a object property by a string path.


querystring

querystring(): Record<string, string>

Get the query string of the current url.


LabelValue

interface LabelValue<T> { label: string; value: T; }

An useful interface to cast the objects with the common label-value pair structure.


getCookie

getCookie(name: string): string | undefined

Get the value of a cookie.


setCookie

setCookie(name: string, value: string, options: CookieOptions = {}): void

Set the value of a cookie.

CookieOptions are:

For the details of CookieOptions see MDN reference.


deleteCookie

deleteCookie(name: string): void

Delete a cookie.