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

@vycana/iteract

v1.2.0

Published

Iteract is a data manipulation library that allows for filtering data in a more readable and straightforward way. It provides an easy-to-use API for manipulating arrays of objects.

Downloads

7

Readme

Test GitHub GitHub Code Size in bytes GitHub Last Commit GitHub Release Date - Published_At

Iteract

Iteract is a data manipulation library that allows for filtering data in a more readable and straightforward way. It provides an easy-to-use API for manipulating arrays of objects.

Installation

Install the package using npm:

npm install @vycana/iteract

Usage

Getting Started

Node JS ENV

To use Iteract, simply import it and create a new instance with your data:

const { Iteract } = require("iteract");

const data = [
  { id: 1, name: "John", age: 30 },
  { id: 2, name: "Mary", age: 25 },
  { id: 3, name: "Peter", age: 35 }
];

const iteract = new Iteract(data);

Browser ENV

To use iteract in browser env, just use Iteract and you are ready to go.

<script>
        window.addEventListener("DOMContentLoaded", () => {
            console.log(Iteract);
        })
</script>

Creating a new Iteract object

Create a new Iteract object by passing an array or an object to the constructor:

const data = [1, 2, 3];
const iteract = new Iteract(data);

Method

all()

Use the all() method to get all the data stored in the object:

const data = [1, 2, 3];
const iteract = new Iteract(data);
console.log(iteract.all()); // [1, 2, 3]

where(...)

Use the where(...) method to filter the data based on certain conditions:

const data = [
  { name: 'John', age: 25 },
  { name: 'Mary', age: 30 },
  { name: 'Peter', age: 35 },
];
const iteract = new Iteract(data);
console.log(iteract.where('age', '>=', 30).all()); // [{ name: 'Mary', age: 30 }, { name: 'Peter', age: 35 }]

sort(...)

To use the sort method of the Iteract class, you can create a new instance of Iteract and pass an array or an object to it. Then, you can call the sort method on the Iteract instance, passing in the sortAscending parameter (which determines whether to sort the data in ascending or descending order) and the key parameter (which specifies the key to use for sorting if the data is an array of objects).

const { Iteract } = require('iteract');

// Create a new instance of Iteract with an array of numbers
const arr = [4, 2, 1, 3];
const iteractArr = new Iteract(arr);

// Sort the array in ascending order
const sortedArr = iteractArr.sort(true);
console.log(sortedArr.all()); // [1, 2, 3, 4]

// Sort the array in descending order
const reverseSortedArr = iteractArr.sort(false);
console.log(reverseSortedArr.all()); // [4, 3, 2, 1]

// Create a new instance of Iteract with an array of objects
const objArr = [
	{ name: 'John', age: 25 },
	{ name: 'Mary', age: 30 },
	{ name: 'Peter', age: 20 },
];

const iteractObjArr = new Iteract(objArr);

// Sort the array of objects in ascending order based on the 'age' key
const sortedObjArr = iteractObjArr.sort(true, 'age');
console.log(sortedObjArr.all()); // [{ name: 'Peter', age: 20 }, { name: 'John', age: 25 }, { name: 'Mary', age: 30 }]

// Sort the array of objects in descending order based on the 'name' key
const reverseSortedObjArr = iteractObjArr.sort(false, 'name');
console.log(reverseSortedObjArr.all()); // [{ name: 'Peter', age: 20 }, { name: 'Mary', age: 30 }, { name: 'John', age: 25 }]

has(value)

Use the has(value) method to check if a given value exists as a key in the object:

const data = { name: 'John', age: 25 };
const iteract = new Iteract(data);
console.log(iteract.has('name')); // true
console.log(iteract.has('email')); // false

hasKeys()

Use the hasKeys() method to check if the object has any keys:

const data = { name: 'John', age: 25 };
const iteract = new Iteract(data);
console.log(iteract.hasKeys()); // true

unique(key)

Use the unique(key) method to return an object with unique elements based on a specified key:

const data = [
  { name: 'John', age: 25 },
  { name: 'Mary', age: 30 },
  { name: 'John', age: 35 },
];
const iteract = new Iteract(data);
console.log(iteract.unique('name').all()); // [{ name: 'John', age: 25 }, { name: 'Mary', age: 30 }]

push(value)

Use the push(value) method to add a value to the data array and return a new Iteract object:

const data = [1, 2, 3];
const iteract = new Iteract(data);
console.log(iteract.push(4).all()); // [1, 2, 3, 4]

Contributors

License

Iteract is released under the Vycana's MIT License.