4.0.0 • Published 2 months ago

jackknife v4.0.0

Weekly downloads
13
License
MIT
Repository
github
Last release
2 months ago

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.

4.0.0

2 months ago

3.0.0

2 years ago

2.8.1

2 years ago

2.8.0

4 years ago

2.7.2

4 years ago

2.7.1

4 years ago

2.7.0

4 years ago

2.6.2

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.4.2

4 years ago

2.4.1

4 years ago

2.4.0

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.2

4 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago