0.1.5 • Published 3 years ago

utillite v0.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

JavaScript utility library

Only the most necessary and nothing superfluous

Installation

Using npm:

$ npm i utillite

Usage

import utils from "utillite"

isEmpty

This method returns true when the value is null

utils.isEmpty(""); // true
utils.isEmpty({}); // true
utils.isEmpty([]); // true
utils.isEmpty([1, 2]); // false

deepClone

This method returns the deep cloned value

const arr = [1, 2, 3];
const cloned = arr;
const deepCloned = utils.deepClone(arr);

arr === cloned; // true
arr === deepCloned; // false

deepEqual

This method returns a Boolean value(Returns true if the two values are equal, else false)

utils.deepEqual({a: {b: "foo"}}, {a: {b: "foo"}}) // true
utils.deepEqual({a: {b: "foo"}}, {a: {b: "foo"}}) // false

utils.deepEqual([1, 2], [1, 2]) // true
utils.deepEqual([1, 2], [1, "2"]) // false

uniq

Creates a duplicate-free version of an array

utils.uniq([1, 2, 3, 2]) // [1, 2, 3]
utils.uniq([1, 2, 3, "2", "5", 3, 5, "2"]) // [1, 2, 3, "2", "5", 5]

get

Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place

const obj = {
    name: "foo",
    info: {
        address: "bar",
        age: 20
    }
}

utils.get(obj, "name") // "foo"
utils.get(obj, "info", {}) // {address: "bar", age: 20}
utils.get(obj, "info.address", {}) // "bar"

utils.get(obj, "phone") // undefined
utils.get(obj, "phone", {}) // {}
utils.get(obj, "phone", "") // ""
0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago