rankutil

1.0.5 • Public • Published

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"

Readme

Keywords

none

Package Sidebar

Install

npm i rankutil

Weekly Downloads

1

Version

1.0.5

License

ISC

Unpacked Size

6.36 kB

Total Files

4

Last publish

Collaborators

  • desairamesh