1.0.5 • Published 10 months ago

rankutil v1.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

rankutils

install package

import { ranksArray, ranksObject } from "rankutil";

or

const { ranksArray, ranksObject } = require("rankutil");

Array methods

Method 1: unique

The unique method returns an array containing only unique elements from the original array.

Usage

const originalArray = [1, 2, 2, 3, 4, 4, 5];
const uniqueArray = ranksArray(originalArray).unique();
console.log(uniqueArray); // Output: [1, 2, 3, 4, 5]

Method 2: removeEmpty

The removeEmpty method removes any empty or falsy values except false and 0 from the array.

Usage

const originalArray = [0, 1, "", false, null, undefined, "hello"];
const filteredArray = ranksArray(originalArray).removeEmpty();
console.log(filteredArray); // Output: [0,1,false,'hello']

Object methods

Method 1: replaceKey

The replaceKey method is designed to replace a key in the object with a new key.

Usage

const originalObject = { name: "John", age: 30 };
const updatedObject = ranksObject(originalObject).replaceKey(
  "name",
  "fullName"
);
console.log(updatedObject); // Output: { fullName: "John", age: 30 }

Method 2: removeEmpty

The removeEmpty method removes any empty or falsy values from the object.

Usage

const originalObject = { name: "John", age: null, address: "" };
const filteredObject = ranksObject(originalObject).removeEmpty();
console.log(filteredObject); // Output: { name: "John" }

Method 2: findProperty

The findProperty method is used to search for a key within the nested structure of the object.

Usage

const nestedObject = {
  person: {
    name: "John",
    age: 30,
    address: {
      city: "New York",
      country: "USA",
    },
  },
};

const foundKey = ranksObject(originalObject).findProperty("city");
console.log(foundKey); // Output: "New York"
1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago